createPinia,
Pinia,
PiniaStorePlugin,
+ PiniaPluginContext,
} from './rootStore'
export { defineStore } from './store'
export { PiniaPlugin } from './plugin'
export {
StateTree,
Store,
+ StoreDefinition,
GenericStore,
GenericStoreDefinition,
StoreWithGetters,
StateDescriptor,
PiniaCustomProperties,
GenericStore,
+ GettersTree,
+ Method,
+ Store,
+ DefineStoreOptions,
} from './types'
import { VueConstructor } from 'vue'
import type Vue from 'vue'
: /* istanbul ignore next */
Symbol()) as InjectionKey<Pinia>
+/**
+ * Context argument passed to Pinia plugins.
+ */
+export interface PiniaPluginContext<
+ Id extends string = string,
+ S extends StateTree = StateTree,
+ G extends GettersTree<S> = GettersTree<S>,
+ A = Record<string, Method>
+> {
+ /**
+ * pinia instance.
+ */
+ pinia: Pinia
+
+ /**
+ * Current app created with `Vue.createApp()`.
+ */
+ // app: App
+
+ /**
+ * Current store being extended.
+ */
+ store: Store<Id, S, G, A>
+
+ /**
+ * Current store being extended.
+ */
+ options: DefineStoreOptions<Id, S, G, A>
+}
+
/**
* Plugin to extend every store
*/
export interface PiniaStorePlugin {
- (context: {
- pinia: Pinia
- store: GenericStore
- }): Partial<PiniaCustomProperties> | void
+ (context: PiniaPluginContext): Partial<PiniaCustomProperties> | void
}
/**
PiniaCustomProperties,
StoreDefinition,
GettersTree,
+ DefineStoreOptions,
} from './types'
import { useStoreDevtools } from './devtools'
import {
descriptor: StateDescriptor<S>,
$id: Id,
getters: G = {} as G,
- actions: A = {} as A
+ actions: A = {} as A,
+ options: DefineStoreOptions<Id, S, G, A>
) {
const pinia = getActivePinia()
// apply all plugins
pinia._p.forEach((extender) => {
- assign(store, extender({ store, pinia }))
+ assign(store, extender({ store, pinia, options }))
})
return store
storeAndDescriptor[1],
id,
getters as GettersTree<S> | undefined,
- actions as Record<string, Method> | undefined
+ actions as Record<string, Method> | undefined,
+ // @ts-expect-error: because of the extend on Actions
+ options
)
return store
storeAndDescriptor[1],
id,
getters as GettersTree<S> | undefined,
- actions as Record<string, Method> | undefined
+ actions as Record<string, Method> | undefined,
+ // @ts-expect-error: because of the extend on Actions
+ options
)
}