]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
chore: repro for vite test/globalhmr
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 4 Aug 2021 09:47:54 +0000 (11:47 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 4 Aug 2021 09:47:54 +0000 (11:47 +0200)
playground/src/main.ts
playground/src/stores/counter.ts
src/index.ts

index 3de1a062a7b09c8fa2ac99d1089cffa31a755558..22cc088ed63341ebd42944cb2c7a2afdfd317907 100644 (file)
@@ -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'
   //   }
index bc1d0c9cd5e5ca40b35c2c88f9eedf03baa6a160..87b408d4ff5ac7dba9a376c37e323e4914a3d69f 100644 (file)
@@ -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))
+// }
index b15060c96d634ee5e86e4d39b1c19d82e7521668..b24ebba2c96341c601f3ada8ca8685423f06edcc 100644 (file)
@@ -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'