From: Eduardo San Martin Morote Date: Wed, 4 Aug 2021 09:47:54 +0000 (+0200) Subject: chore: repro for vite X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Ftest%2Fglobalhmr;p=thirdparty%2Fvuejs%2Fpinia.git chore: repro for vite --- diff --git a/playground/src/main.ts b/playground/src/main.ts index 3de1a062..22cc088e 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -1,6 +1,6 @@ import { computed, createApp, markRaw } from 'vue' import App from './App.vue' -import { createPinia } from '../../src' +import { acceptHMRUpdate, createPinia, isUseStore } from '../../src' import { router } from './router' const pinia = createPinia() @@ -10,6 +10,24 @@ pinia.use(() => ({ })) if (import.meta.hot) { + const stores = import.meta.glob('./stores/*.ts') + for (const filePath in stores) { + console.log('configuring HMR for', filePath) + + stores[filePath]().then((mod) => { + for (const exportName in mod) { + const storeDef = mod[exportName] + if (isUseStore(storeDef)) { + console.log(`Detected store "${storeDef.$id}"`) + import.meta.hot!.accept( + filePath, + acceptHMRUpdate(storeDef, import.meta.hot) + ) + } + } + }) + } + // const isUseStore = (fn: any): fn is StoreDefinition => { // return typeof fn === 'function' && typeof fn.$id === 'string' // } diff --git a/playground/src/stores/counter.ts b/playground/src/stores/counter.ts index bc1d0c9c..87b408d4 100644 --- a/playground/src/stores/counter.ts +++ b/playground/src/stores/counter.ts @@ -63,6 +63,6 @@ export const useCounter = defineStore({ }, }) -if (import.meta.hot) { - import.meta.hot.accept(acceptHMRUpdate(useCounter, import.meta.hot)) -} +// if (import.meta.hot) { +// import.meta.hot.accept(acceptHMRUpdate(useCounter, import.meta.hot)) +// } diff --git a/src/index.ts b/src/index.ts index b15060c9..b24ebba2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,6 +60,6 @@ export type { export { createTestingPinia } from './testing' export type { TestingOptions, TestingPinia } from './testing' -export { acceptHMRUpdate } from './hmr' +export { acceptHMRUpdate, isUseStore } from './hmr' export { PiniaPlugin } from './vue2-plugin'