]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
chore: remove old code
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 16 Jul 2021 12:55:44 +0000 (14:55 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 19 Jul 2021 09:52:25 +0000 (11:52 +0200)
src/hmr.ts
src/store.ts

index ae2cd6a36720ef408b482a1d0372612ad98a1002..ecd1cf1ad2041e6ba920f0f725bab79e0dd9b3e0 100644 (file)
@@ -1,68 +1,6 @@
 import { Pinia } from './rootStore'
 import { Store, StoreDefinition, _Method } from './types'
 
-/**
- * Setups the hot module replacement for a `useStore` in a Vite environment.
- *
- * @param useStore - function created by defineStore
- */
-export function setupViteHMR(
-  useStore: StoreDefinition<string, any, any, any>,
-  acceptUpdate: _Method,
-  invalidateUpdate: _Method,
-  data: any
-) {
-  const initialUseStore = useStore
-  // @ts-ignore: this would require importing vite types
-  // import.meta.hot.accept((newModule) => {
-
-  acceptUpdate((newModule) => {
-    // @ts-ignore
-    // if (!import.meta.hot) {
-    //   throw new Error('import.meta.hot disappeared')
-    // }
-
-    const pinia: Pinia | undefined =
-      (import.meta as any).hot.data.pinia || initialUseStore._pinia
-
-    if (!pinia) {
-      // this store is still not used
-      return
-    }
-
-    // preserve the pinia instance across loads
-    // @ts-ignore
-    // import.meta.hot.data.pinia = pinia
-    data.pinia = pinia
-
-    // console.log('got data', newStore)
-    for (const exportName in newModule) {
-      const useStore = newModule[exportName]
-      // console.log('checking for', exportName)
-      if (isUseStore(useStore) && pinia._s.has(useStore.$id)) {
-        // console.log('Accepting update for', useStore.$id)
-        const id = useStore.$id
-
-        if (id !== initialUseStore.$id) {
-          console.warn(
-            `The id of the store changed from "${initialUseStore.$id}" to "${id}". Reloading.`
-          )
-          // @ts-ignore
-          // return import.meta.hot.invalidate()
-          return invalidateUpdate()
-        }
-
-        const existingStore: Store = pinia._s.get(id)!
-        if (!existingStore) {
-          console.log(`skipping hmr because store doesn't exist yet`)
-          return
-        }
-        useStore(pinia, existingStore)
-      }
-    }
-  })
-}
-
 export const isUseStore = (fn: any): fn is StoreDefinition => {
   return typeof fn === 'function' && typeof fn.$id === 'string'
 }
index 83defd637d059da4f273c44a325b66b69bbd2501..3e15d7c9efd9700454178164d527e558b23af1fb 100644 (file)
@@ -389,8 +389,9 @@ function createSetupStore<
       }
       // action
     } else if (typeof prop === 'function') {
-      // @ts-expect-error: we are overriding the function
-      // we avoid wrapping if this a hot module replacement store
+      // @ts-expect-error: we are overriding the function we avoid wrapping if
+      // this a hot module replacement store because the hotUpdate method needs
+      // to do it with the right context
       setupStore[key] = __DEV__ && hot ? prop : wrapAction(key, prop)
 
       if (__DEV__) {