```js
export function myPiniaPlugin(context) {
context.pinia // the pinia created with `createPinia()`
+ context.app // the current app created with `createApp()`
context.store // the store the plugin is augmenting
context.options // the options object defining the store passed to `defineStore()`
// ...
createPinia,
Pinia,
PiniaStorePlugin,
+ PiniaPluginContext,
} from './rootStore'
export { defineStore } from './store'
export {
export const setClientApp = (app: App) => (clientApp = app)
export const getClientApp = () => clientApp
+/**
+ * Context argument passed to Pinia plugins.
+ */
+export interface PiniaPluginContext {
+ /**
+ * pinia instance.
+ */
+
+ pinia: Pinia
+ /**
+ * Current app created with `Vue.createApp()`.
+ */
+ app: App
+
+ /**
+ * Current store being extended.
+ */
+ store: GenericStore
+}
+
/**
* Plugin to extend every store
*/
export interface PiniaStorePlugin {
- (context: {
- app: App
- store: GenericStore
- }): Partial<PiniaCustomProperties> | void
+ (context: PiniaPluginContext): Partial<PiniaCustomProperties> | void
}
/**
// apply all plugins
pinia._p.forEach((extender) => {
- Object.assign(store, extender({ store, app: pinia._a }))
+ Object.assign(store, extender({ store, app: pinia._a, pinia }))
})
return store