Pinia Plugins: Finding the Right Approach for Extending Stores #2279
Replies: 1 comment
-
This concern was already answered in Discord, and the answer was to use composables for this way of extending the Store. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The fundamental problem I see with Pinia plugins is that the type definitions created for the plugins affect all the stores in your application 😱. This means that you might have a store called
useXXXX
, and when a random developer in the company has to work on the code related to that store, they might see that theuseXXXX
store has functions that don't exist in that store. Furthermore, it doesn't make sense for a store of that type to have those functions, but the developer sees them due to TypeScript's autocomplete.This becomes a significant problem when there are multiple teams working on the same source code within a company 😩.
Therefore, I wonder what the appropriate approach would be to create a plugin without encountering these frustrating disadvantages. So far, considering these limitations and others, such as the inability to observe actions added by plugins through store.$onAction, I'm leaning towards the conclusion that plugins are only suitable for the following use cases:
Apart from these use cases, using plugins to extend stores would require organizational actions within the company's teams to avoid the issues with type definitions.
I wonder if there has been any consideration given to rethinking the entire approach to Pinia plugins, allowing them to be defined directly in the store creation definition 🤔
Beta Was this translation helpful? Give feedback.
All reactions