From ae715b0037bd16a763f417e4a2449c9f1c38b317 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 25 Sep 2020 11:40:04 +0200 Subject: [PATCH] docs: show how to install pinia --- README.md | 13 +++++++++++++ src/store.ts | 9 +++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) 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.` ) } } -- 2.47.2