Open martinszeltins opened 1 month ago
Hi mutations in Pinia are synchronous, and this plugin uses the $subscribe
API to react to mutations and save the state. You can still make async calls in a sync function, but you may experience unexpected behaviours, that's why it's not recommended.
See https://pinia.vuejs.org/core-concepts/state.html#Subscribing-to-the-state
The other way to implement async behavious with Pinia is actions.
Hi mutations in Pinia are synchronous, and this plugin uses the
$subscribe
API to react to mutations and save the state. You can still make async calls in a sync function, but you may experience unexpected behaviours, that's why it's not recommended.See pinia.vuejs.org/core-concepts/state.html#Subscribing-to-the-state
The other way to implement async behavious with Pinia is actions.
What are potential problems that can occur when making async calls on $subscribe?
Async calls are not awaited, if two mutations happen successively, the second call may resolve before the first one, resulting in outdated data replacing latest data.
Async calls are not awaited, if two mutations happen successively, the second call may resolve before the first one, resulting in outdated data replacing latest data.
Perhaps this can be solved using timestamps?
Last Synced Mutation Time: 2024-05-27T19:34:49
Mutation: user=john; timestamp=2024-05-27T19:34:49
// Rejected because timestamp is < last synced time
Mutation: user=joh; timestamp=2024-05-27T19:30:49
That could be a workaround for you, but this would be out of scope of the plugin, as we dont support async behaviours and side effects :)
Describe the bug
It would be really nice to be able to store the pinia state in Redis. I don't understand the limitation of Storage must be synchronous. Why can't we simply trigger a Redis save and load on $subscribe?
Reproduction
n/a
System Info
Used Package Manager
n/a
Validations