vuejs / pinia

🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support
https://pinia.vuejs.org
MIT License
12.91k stars 1.02k forks source link

Ability to manually trigger plugin action subscriptions within a setup store #2609

Closed travislaynewilson closed 5 months ago

travislaynewilson commented 5 months ago

What problem is this solving

When calling C(), the store is not triggering subscriptions for A and B, causing the plugin to not receive updates when those actions are fired.

Proposed solution

I propose that we be given an ability to manually trigger action subscriptions from within a store to counter this behavior.

An alternative is to simply have actions in a setup store trigger their $onAction subscriptions, whether called internally or externally.

Describe alternatives you've considered

To circumvent this, I would need to double-up my code, or create an additional subscription in the plugin that doubles up the logic in the plugin. This feels like an anti-pattern that could better be solved if the dedicated subscriptions would simply trigger when called, internally or externally.

posva commented 5 months ago

This is a technical limitation. To fix it, it would require wrapping functions within setup stores with some internal action(() => {...}), which adds a boilerplate but also doesn't work with composables returning functions. Even if it could be automatically added with a vite plugin, it wouldn't work in many scenarios.

I propose that we be given an ability to manually trigger action subscriptions from within a store to counter this behavior.

This would just be a hacky workaround...

I'm looking for other ideas and feedback regarding the action() wrapper. It might be a useful addition for future major versions. So far, it seems a bit too much to just have it for plugins