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

Version 2.0 Proposal #3

Closed
wants to merge 3 commits into from
Closed

Conversation

brianegan
Copy link
Collaborator

@brianegan brianegan commented Aug 24, 2017

Hey hey :) It was cool meeting you in Munich last year, hope all is well!

I've been using Redux a bit more and would like to suggest a couple of changes to this library to make it more slightly flexible yet still "as simple as possible."

Since these would be breaking changes, I'd propose it as a 2.0 release.

Overall, if this isn't your thang, honestly no worries at all. I'd be happy to publish it as a separate package, but thought it'd be cool to try to keep all the number of Redux implementations in DartLand as small as possible, and see what your thoughts are.

Now, I know you didn't want to change to typedef's in my first PR, but hear me out :) This new version would allow us to have our cake and eat it too: If users want to use functions for reducers and middleware, they can. If they want to use classes, they can!

Also, I was trying to implement Redux DevTools, but I was unsuccessful due to the typing of Action, because Store Enhancers need to be able to dispatch their own actions. Therefore, I removed it. I had this exact constraint in a Java version of Redux I'd written and and actually removed this Generic constraint in that lib due to the constraint.

Proposed changes:

  • Added a bunch of docs and did just a bit of code cleanup.
  • Remove the typing of Action - If Action is a typed parameter, it prevents any type of Store Enhancer (such as Redux Dev Tools) from dispatching their own actions. In code, this means class Store<State, Action> becomes class Store<State>.
  • Change Reducer to Typedef with Class fallback -- this introduces typedef State Reducer<State>(State state, dynamic action); and changes class Reducer<State, Action> to abstract class ReducerClass<State>. This would require only a small change to code, including extending the new class and renaming reduce to call.
  • Change Middleware to Typedef with Class fallback -- this introduces typedef void Middleware<State>(Store<State> store, dynamic action, NextDispatcher next); and changes class Middleware<State, Action> to abstract class MiddlewareClass<State>. For middleware, this should be an almost transparent change, as all they'd have to do is extend MiddlewareClass instead of Middleware.
  • Add teardown method, which closes the StreamController and nulls out the state. Needed in case someone wanted to stop using the store during the app lifecycle.

Lemme know whatcha think and if you have suggestions!

This allows for Store Enhancers, such as Dev Tools, to dispatch their own actions.
This allows one to use more functional composition on their Reducers,
while maintaining a Class interface for the Object Oriented inclined.
@brianegan
Copy link
Collaborator Author

Hey, I've ended up making a bunch more changes to play around with some different concepts, especially around Store Enhancers for Dev Tools, so I think it might close this out for now.

@brianegan brianegan closed this Aug 25, 2017
@johnpryan
Copy link
Collaborator

Ok. I like this a lot better now that generic function type syntax was added in 1.24

Feel free to re-open whenever and i'll merge + publish the changes

@brianegan brianegan deleted the typedefs branch December 6, 2017 13:50
@lasseschmitt lasseschmitt mentioned this pull request Mar 23, 2018
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.

None yet

2 participants