-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Strange behaviour for subscriber notifications #1221
Comments
Good point. Can you raise this as an issue in dnd-core? The behavior is intentional; subscribers aren't guaranteed to get every state update, just the most recent one. If you have ideas how to optimize this please send a PR! |
I have create a PR for documentation clarification. listeners.forEach(listener => {
- if ( typeof listener !== 'undefined' ) {
+ if ( isDispatchingToListeners && typeof listener !== 'undefined' ) {
listener()
} Would fix it. But I agree with slorber that the non verified performance optimization is not worth the cost in code readability. |
According to the documentation, subscribe(listener) should:
Then one would assume notifications are actually delivered when getState() returns the state which was the result of the action dispatched.
But the current implementation of dispatch, actually lets a new action be dispatched, before all listeners are notified (if the action was dispatched by one of the listeners).
Therefore some listeners will get the notification of the second action, before the notification for the first action, but both with the latest state.
The current behavior makes the state.dirtyHandlerIds optimization in dnd-core end up missing updates to state.dragOperation.
When listeners do optimizations like dnd-core, will that not break the time travel in redux-devtool?
If the behavior is intentional, I think it should be documented, and the code should probably be optimized so that the new state is only notified once.
The text was updated successfully, but these errors were encountered: