From: Eduardo San Martin Morote Date: Fri, 25 Sep 2020 09:40:04 +0000 (+0200) Subject: docs: show how to install pinia X-Git-Tag: v2.0.0-alpha.3~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae715b0037bd16a763f417e4a2449c9f1c38b317;p=thirdparty%2Fvuejs%2Fpinia.git docs: show how to install pinia --- diff --git a/README.md b/README.md index 621fa563..969b0ffd 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,19 @@ npm install pinia@next ## Usage +### Install the plugin + +Create a pinia (the root store) and pass it to app: + +```js +import { createPinia } from 'pinia' + +app.use(createPinia()) +``` + +This will also add devtools support. +**NOTE**: this API is still experimental and is currently only used for devtools support but that might change in the future + ### Creating a Store You can create as many stores as you want, and they should each exist in different files: diff --git a/src/store.ts b/src/store.ts index 0776c796..868c0849 100644 --- a/src/store.ts +++ b/src/store.ts @@ -172,6 +172,9 @@ export function buildStore< return store } +// only warn the dev once +let isDevWarned: boolean | undefined + /** * Creates a `useStore` function that retrieves the store instance * @param options - options to define the store @@ -208,12 +211,14 @@ export function createStore< const app = getClientApp() if (app) { addDevtools(app, store, req) - } else { + } else if (!isDevWarned && !__TEST__) { + isDevWarned = true console.warn( `[🍍]: store was instantiated before calling\n` + `app.use(pinia)\n` + `Make sure to install pinia's plugin by using createPinia:\n` + - `linkto docs TODO` + `https://github.com/posva/pinia/tree/v2#install-the-plugin\n` + + `It will enable devtools and overall a better developer experience.` ) } }