-
Notifications
You must be signed in to change notification settings - Fork 88
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
New ActionDispatched event would duplicate StateChanged #63
Comments
It seems reasonable for I'm not necessarily advocating for the latter, but that it could afford such flexibility recommends including it at a foundational level IMO. |
I agree that It is also true that using There are a few "simple" alternatives:
Of these, I'm leaning towards 2 or 3. If you or anyone else has other concrete suggestions, shoot!
You'd still have to define |
I'd vote for #3. It adds real power to the system, but its use is rather specialized – e.g. for extending the store. Your point about orthogonality is well taken, but I think there are significant conceptual differences. ActionDispatch is for tapping into the event stream, StateChanged is for reacting to changes in the state. Sure, there's a causal relationship between them, but they're two different phases which should be kept distinct – keeping them that way ensures use of the store is consistent with the underlying paradigm. |
I agree that having both |
I don't understand what this does that a middleware couldn't do. Middleware receive all actions and have the ability to do something with them before they reach the store. Middleware and stew creators are used to extend the store so I'm not sure I'm understanding the value of more events on the store itself |
Store creators* damn mobile |
|
It's important to note though that this does not replace middleware. This is for doing stuff with actions that have already reached the store and been dispatched. This is not possible with middleware. While middleware can stop actions, which is orthogonal to what this event is for. |
I'm a new commenter, but i think you should just have StateChanged, but go back to the standard way of using EventHandler for the event. You will get the best of both worlds and T could be an object that would include the action. There's no reason to raise two events and you should follow the standard .NET event pattern. |
It's true that we could pass some kind of
I disagree. The dispatched action shouldn't be needed for most purposes on a state-changed event in a redux architecture (it's mainly for more easily extending the store), so including the action could cause confusion among users and at worst lead to poor practices where it's used in unwise manners just because it's there. Even the updated state has been removed from the In general, if we send objects in the event args that the handler shouldn't use, then at best, it just increases noise as it requires devs to accept parameters they'll never use, and at worst, it drives devs towards unfortunate design decisions. In short, an Of course, if you then prefer to program against an API that raises a |
Created a PR for this at #64 so we have some code to look at. |
I'm working on a quick PR to add an
ActionDispatched
event toIStore
andStore
. I figured this was orthogonal to everything else on the store, and the intention was for this event to work as a backing for an extension method providing an IObservable of actions, as has been mentioned a few times (e.g. #47 (comment)).While making this, it occurred to me that this event would be raised at exactly the same time as
StateChanged
. The only and critical difference is thatActionDispatched
would pass on the action that was received (which is what allows us to build an IObservable out of it).@GuillaumeSalles, @dcolthorp, @lilasquared, how do you think we should solve this? In order to be able to make an observable of actions that reach the reducer (not actions that are stopped by middleware), we either need to make this an event on the base
Store
class, or make a subclass ofStore
which overridesInnerDispatch
(which needs to be made virtual as per PR #60).I'd like the former, because then we could use an extension method to observe the actions, and wouldn't need a subclass (which could be troublesome if we want to implement other stuff that needs subclasses but are orthogonal to this). For example, the
ObservableActionStore
in PR #62 could be dropped entirely.The text was updated successfully, but these errors were encountered: