-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
$subscribe
miss mutations with type of direct
immediately afterpatch
mutations
#992
Comments
This might be a caveat that cannot be worked around except by using a nextTick().then(() => {
isListening = true
})
isSyncListening = true
// because we paused the watcher, we need to manually call the subscriptions
triggerSubscriptions(
subscriptions,
subscriptionMutation,
pinia.state.value[$id] as UnwrapRef<S>
) Moving |
Thank you for your reply. Using $subscribe(callback, options = {}) {
const removeSubscription = addSubscription(subscriptions, callback, options.detached, () => stopWatcher());
const stopWatcher = scope.run(() => watch(() => pinia.state.value[$id], (state) => {
// when the `$patch` is called, and then the `watch` is also triggered due to the directly change of `store.count`,
// the "isListening" currently has the value of `false` and `callback` wound never be called here
if (options.flush === 'sync' ? isSyncListening : isListening) {
callback({
storeId: $id,
type: MutationType.direct,
events: debuggerEvents,
}, state);
}
}, assign({}, $subscribeOptions, options)));
return removeSubscription;
} |
Because otherwise Using Maybe splitting up the listeners by flush and making patch only trigger sync for sync listeners is a better idea but this could require a new mutation type "mixed" that would be very heavy code-wise |
subscribe mutation.events are empty in safari mobile, (I dont test safari desktop) but same code work in desktop and android mobile |
If I understand correctly what's going on here, the events are being debounced (similar in nature to lodash debounce). Or perhaps instead of being time sliced it is sliced based on an 'update frame'? Whatever code runs synchronously before passing back to the event loop? In order to communicate state change correctly, the mutation data would need to be included for all mutations that are being grouped. If Pinia mutation data is subject to race conditions and truncation, I certainly don't feel comfortable basing any of my logic on it. For my present use case, I can code to current state and respond to that. But it puts the burden on the consumer (me) to know whether the state I'm looking at has changed or not, and whether I have previously witnessed it. Here's the data I'm receiving from
Snapshot of state:
Problems here are:
Guarantees like "you will receive notice of all mutations that occur" and "you will know exactly where those mutations occurred" are some of the compelling reasons for me to reach for a state management library like Pinia. Am I understanding correctly, and is this in alignment with the goals of the project? I'm happy to submit a pull request if that would be welcome. Present mutation output could be kept for backwards compatibility and a new key introduced containing all batched mutations. |
Any way to have access to the mutation path? |
As a new pinia user this issue took me about two full days to find and finally have a working subscription. |
in $subscribe ,I use
console
to print the mutations and states when the states change :it works correct when I change the state directly or use
$pacth
singlelybut when I use them together as follow,the mutation with type of 'direct' will miss ,there is only {type: 'patch object',...} on console , and the
count
value printed was still the old value, actually had increased . seem to not be detected ?The text was updated successfully, but these errors were encountered: