]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(types): expose PiniaPluginContext
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 1 Apr 2021 15:28:52 +0000 (17:28 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Wed, 28 Apr 2021 17:45:38 +0000 (19:45 +0200)
docs/core-concepts/plugins.md
src/index.ts
src/rootStore.ts
src/store.ts

index df7edc611a407d89756f51555b3d05fc6f4eae07..a9d832d88c616dd8661c583829128f91bb6a3ff6 100644 (file)
@@ -27,6 +27,7 @@ A Pinia plugin is a function that optionally returns properties to be added to a
 ```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()`
   // ...
index 39289f6e129abcef62733b813dc224da6a1c69fe..6a09a0ce481222a5d9eafb544f86fb2b9c2c9e20 100644 (file)
@@ -3,6 +3,7 @@ export {
   createPinia,
   Pinia,
   PiniaStorePlugin,
+  PiniaPluginContext,
 } from './rootStore'
 export { defineStore } from './store'
 export {
index faf4e5b5ed8fac260b4e484330970eff0085f4a2..2f8b9375bb2418cf3c30c865670dd6ff8f50a5d6 100644 (file)
@@ -56,14 +56,31 @@ export let clientApp: App | undefined /*#__PURE__*/
 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
 }
 
 /**
index 18c296bef7ed49a8dfccdd98e7414908f27d5e97..c82512cef87545903b13288c6078d1b88b868efe 100644 (file)
@@ -247,7 +247,7 @@ function buildStoreToUse<
 
   // 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