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

Exposing a subset of the Store API to middleware #40

Open
ekweible opened this issue Sep 9, 2018 · 2 comments
Open

Exposing a subset of the Store API to middleware #40

ekweible opened this issue Sep 9, 2018 · 2 comments

Comments

@ekweible
Copy link

ekweible commented Sep 9, 2018

This is primarily a question about a difference between the middleware API here versus the JS version.

redux.js exposes only a subset of the Store's API (getState() and dispatch()) to middleware, whereas redux.dart provides the entire Store instance. Are there any valid use cases where having access to reducer, onChange, or teardown justifies their presence?

It seems to me that using those additional Store APIs in middleware would usually be considered anti-patterns and limiting middleware to just the Store's state and dispatcher would be a useful constraint and would make test setups a bit simpler (although this might be a marginal improvement, at best).

Obviously this would be a breaking API change, and the benefit of preventing misuse in middleware and aligning with redux.js is relatively small, so I definitely understand if you decide the juice isn't worth the squeeze. Maybe something to consider in the future if you have other reasons for a new major version.

@johnpryan
Copy link
Collaborator

johnpryan commented Sep 10, 2018

This is a good suggestion, thanks Evan :) Yeah, it's a breaking change, but it looks to me like people aren't using reducer onChange or teardown in middleware right now anyway:

https://github.com/brianegan/redux_logging/blob/master/lib/redux_logging.dart#L121
https://github.com/Cretezy/redux_persist/blob/master/packages/redux_persist/lib/redux_persist.dart#L208
https://github.com/brianegan/dart_redux_epics/blob/master/lib/src/epic_middleware.dart#L40

This was just my quick collection of some middleware I see on Pub.

@jnorkus
Copy link

jnorkus commented Dec 11, 2018

I have just come across this. I am missing the onChange in the epic middleware, so I forked the repo to add that. How would you go about accessing the state stream without that? In my epics I usually want to watch the state to wait for some condition before continuing.

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

No branches or pull requests

3 participants