From: Eduardo San Martin Morote Date: Wed, 30 Jun 2021 10:50:42 +0000 (+0200) Subject: docs: better explanations for plugins X-Git-Tag: v2.0.0-beta.5~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b990fb677af1140878aae5b68ec629aefb968301;p=thirdparty%2Fvuejs%2Fpinia.git docs: better explanations for plugins Close #559 --- diff --git a/docs/core-concepts/plugins.md b/docs/core-concepts/plugins.md index e41b2cef..76ac628c 100644 --- a/docs/core-concepts/plugins.md +++ b/docs/core-concepts/plugins.md @@ -10,11 +10,20 @@ Pinia stores can be fully extended thanks to a low level API. Here is a list of - Implement side effects like local storage - Apply **only** to specific stores -Plugins are added to pinia with `pinia.use()`. The simplest example is adding a property to all stores by returning an object: +Plugins are added to the pinia instance with `pinia.use()`. The simplest example is adding a static property to all stores by returning an object: ```js +import { createPinia } from 'pinia' + // add a property named `secret` to every store that is created after this plugin is installed -pinia.use(() => ({ secret: 'the cake is a lie' })) +// this could be in a different file +function SecretPiniaPlugin() { + return { secret: 'the cake is a lie' } +} + +const pinia = createPinia() +// give the plugin to pinia +pinia.use(SecretPiniaPlugin) // in another file const store = useStore() @@ -180,7 +189,7 @@ The same is true for `store.$onAction()`. ## Adding new options -It is possible to create new options when defining stores to later on consume the options on plugins. For example, you could create a `debounce` option that allows you to debounce any action: +It is possible to create new options when defining stores to later on consume them from plugins. For example, you could create a `debounce` option that allows you to debounce any action: ```js defineStore({