Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconcile reducer/reducers #783

Merged
merged 2 commits into from
Jan 17, 2018
Merged

Reconcile reducer/reducers #783

merged 2 commits into from
Jan 17, 2018

Conversation

ryanlanciaux
Copy link
Member

@ryanlanciaux ryanlanciaux commented Dec 23, 2017

Griddle major version

1.11.0

Changes proposed in this pull request

Fix an apparent typo from #757

Why these changes are made

A couple of the stories were not working (controlled griddle)

Are there tests?

No but there are some fixed stories

@dahlbyk
Copy link
Contributor

dahlbyk commented Dec 23, 2017

Damn. In my defense, we're not consistent between "reducer" (from core/plugins) and "reducers" (everywhere else).

Are there tests?

There actually are! Unfortunately...
Two unit tests, no integration tests

@dahlbyk
Copy link
Contributor

dahlbyk commented Dec 23, 2017

In my defense, we're not consistent between "reducer" (from core/plugins) and "reducers" (everywhere else).

I've added a commit to this branch to try and make this more consistent:

  • initializer now returns reducer instead of reducers, which makes sense because it's actually a combined reducer function
  • Within initializer, dataReducers (retained from previous code) has been renamed defaultReducer to align with defaultStyleConfig

I do believe it would be better if the core/plugin key were reducers instead of reducer, since it expects a reducer-per-key object rather than an actual reducer function. On the other hand, it would seem reasonable to keep it as reducer if we could handle receiving functions or objects (which we'd coalesce to functions). Thoughts?

@ryanlanciaux
Copy link
Member Author

Awesome - I'll close this one and look at that. Thanks a ton

@dahlbyk dahlbyk reopened this Dec 24, 2017
@dahlbyk
Copy link
Contributor

dahlbyk commented Dec 24, 2017

In retrospect, I should have included both of these commits in #784. Or did you specifically not like the reducers 👉 reducer change?

@ryanlanciaux
Copy link
Member Author

Sorry -- for some reason I thought it was included in #784 :D

I do believe it would be better if the core/plugin key were reducers instead of reducer, since it expects a reducer-per-key object rather than an actual reducer function.

I agree with this -- sorry about the inconsistency that was around from the beginning here.

I think the future intent (that isn't documented) is, like you said. It would be nice to be able to take a reducer function or an object as well as the one-off reducer methods. If you have any stronger opinions on this -- I'm totally happy with either direction 😄

@dahlbyk
Copy link
Contributor

dahlbyk commented Dec 27, 2017

I think the future intent (that isn't documented) is, like you said. It would be nice to be able to take a reducer function or an object as well as the one-off reducer methods. If you have any stronger opinions on this -- I'm totally happy with either direction 😄

I poked around at this for a bit, and it's not obvious how a plain reducer function should fit in the existing reducer object composition model:

  1. All BEFORE_REDUCE
  2. All *_BEFORE for the current type
  3. The "winning" (last-applied) reducer for the current type
  4. All *_AFTER for the current type
  5. All AFTER_REDUCE

If a plugin provides a plain function for reducer, it's not obvious to me at which point that reducer should be called:

  1. In place of (3) for all types, unless another reducer object with type is applied later, e.g.
    plugins=[{ reducer: { A: a }, { reducer: r }, { reducer: { B: b } }]
    
    would call r for all actions, except calling b when type is "B".
  2. In place of (3) for all types for which a reducer has not been defined at any point, e.g.
    plugins=[{ reducer: { A: a }, { reducer: r }, { reducer: { B: b } }]
    
    would call r for all actions, except calling a or b when type is "A" or "B", respectively.
  3. Before or after (3) for all types, e.g.
    plugins=[{ reducer: { A: a }, { reducer: r }, { reducer: { B: b } }]
    
    would call r for all actions, before or after calling a or b when type is "A" or "B", respectively.

Or maybe there's another option? Thoughts?

@dahlbyk dahlbyk changed the title Update typo Reconcile reducer/reducers Dec 27, 2017
@dahlbyk dahlbyk merged commit 250ea2a into master Jan 17, 2018
@dahlbyk dahlbyk deleted the fixInitializer branch January 17, 2018 22:08
@dahlbyk
Copy link
Contributor

dahlbyk commented Jan 17, 2018

We can revisit #783 (comment) later, but for now I've merged this for better naming consistency.

@ryanlanciaux
Copy link
Member Author

Thank you - sorry I dropped off the face of the earth on this one. I totally agree with your assessment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants