-
Notifications
You must be signed in to change notification settings - Fork 13
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
Clear memoized for state while deferring notifications #261
Conversation
src/throttledStore.tsx
Outdated
@@ -279,17 +280,19 @@ export const createThrottledStore = ( | |||
observableNotify: onObservableNotify, | |||
resetPendingNotifications: resetAllPendingNotifications, | |||
hasPendingSubscribers: () => pendingBroadcastNotification, | |||
deferSubscriberNotifications: async action => { | |||
deferSubscriberNotifications: async (action, shouldClearMemoizedForState) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest changing to parameter to be {shouldClearMemoizedForState}
as options object to allow forward compatibility.
Also, it might be misleading, since it would clear cache only on dispatch, maybe we should name it shouldDispatchClearCache
or something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We wanted this to be a temporary solution, so that after we make sure it does not hurt performance, we'll remove this option and do it by default. In that case, do you still want an options object?
regarding the name - changed :)
In this PR, I added an option to clear
memoizeForState
cache on every state change, if deferring notifications.This is done because we normally clear the memoizeForState` cache only when notifying subscribers, which does not happen while deferring notifications. This may cause incorrect results.
Currently this is done only when given an optional argument to
deferSubscriberNotifications
(which makes the code temporarily ugly), so we can verify that it does not cause performance issues. In the future we would like to do it by default.