setupDevtoolsPlugin,
} from '@vue/devtools-api'
import { App } from 'vue'
+import { PiniaPluginContext } from './rootStore'
import { GenericStore, GettersTree, StateTree } from './types'
function formatDisplay(display: string) {
return fields
}
+
+/**
+ * pinia.use(devtoolsPlugin)
+ */
+export function devtoolsPlugin({ app, store }: PiniaPluginContext) {
+ addDevtools(app, store)
+}
import { App, InjectionKey, Plugin, Ref, ref, warn } from 'vue'
+import { devtoolsPlugin } from './devtools'
import { IS_CLIENT } from './env'
import {
StateTree,
>
>()
-/**
- * Expose the client-side application instance used for devtools
- */
-let clientAppPromise: Promise<App> | undefined
-let resolveApp: ((app: App) => void) | undefined
-export const setClientApp = (app: App) => {
- if (resolveApp) {
- resolveApp(app)
- } else {
- // setClientApp might be called before getClientApp
- clientAppPromise = Promise.resolve(app)
- }
-}
-export const getClientApp = () =>
- clientAppPromise ||
- (clientAppPromise = new Promise((resolve) => (resolveApp = resolve)))
-
/**
* Context argument passed to Pinia plugins.
*/
// TODO: write test
// only set the app on client for devtools
if (__BROWSER__ && IS_CLIENT) {
- setClientApp(app)
// this allows calling useStore() outside of a component setup after
// installing pinia's plugin
setActivePinia(pinia)
state,
}
+ if (IS_CLIENT && __BROWSER__ && __DEV__) {
+ pinia.use(devtoolsPlugin)
+ }
+
return pinia
}
getActivePinia,
setActivePinia,
storesMap,
- getClientApp,
piniaSymbol,
Pinia,
} from './rootStore'
-import { addDevtools } from './devtools'
import { IS_CLIENT } from './env'
function innerPatch<T extends StateTree>(
provide(storeAndDescriptor[2], store)
}
- if (
- IS_CLIENT &&
- __BROWSER__ &&
- __DEV__ /*|| __FEATURE_PROD_DEVTOOLS__*/
- ) {
- getClientApp().then((app) => addDevtools(app, store))
- }
-
return store
}