]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs(hmr): document hmr code
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 20 Jul 2021 08:00:53 +0000 (10:00 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 20 Jul 2021 08:00:53 +0000 (10:00 +0200)
src/hmr.ts
src/index.ts

index 68b37b97ab90f1420366fbafacefb9cd2029bd68..ab2e76d10d9de1cdc95c262bfc675449c3b34f3b 100644 (file)
@@ -2,10 +2,25 @@ import { isRef, isReactive } from 'vue'
 import { Pinia } from './rootStore'
 import { isPlainObject, Store, StoreDefinition, _Method } from './types'
 
+/**
+ * Checks if a function is a `StoreDefinition`
+ *
+ * @param fn - object to test
+ * @returns true if `fn` is a StoreDefinition
+ */
 export const isUseStore = (fn: any): fn is StoreDefinition => {
   return typeof fn === 'function' && typeof fn.$id === 'string'
 }
 
+/**
+ * Mutates in place `newState` with `oldState` to _hot update_ it. It will
+ * remove any key not existing in `newState` and recursively merge plain
+ * objects.
+ *
+ * @param newState - new state object to be patched
+ * @param oldState - old state that should be used to patch newState
+ * @returns - newState
+ */
 export function patchObject(
   newState: Record<string, any>,
   oldState: Record<string, any>
@@ -37,6 +52,20 @@ export function patchObject(
   return newState
 }
 
+/**
+ * Creates an _accept_ function to pass to `import.meta.hot` in Vite applications.
+ *
+ * @example
+ * ```js
+ * const useUser = defineStore(...)
+ * if (import.meta.hot) {
+ *   import.meta.hot.accept(acceptHMRUpdate(useUser, import.meta.hot))
+ * }
+ * ```
+ *
+ * @param initialUseStore - return of the defineStore to hot update
+ * @param hot - `import.meta.hot`
+ */
 export function acceptHMRUpdate(
   initialUseStore: StoreDefinition<string, any, any, any>,
   hot: any
index a94b847e208f098f16ed2d4c4f8bcfeee98e23ec..06ef34ae1647b1b92c293cb4bf107c9ab61d4e5f 100644 (file)
@@ -55,4 +55,4 @@ export type {
 export { createTestingPinia } from './testing'
 export type { TestingOptions } from './testing'
 
-export * from './hmr'
+export { acceptHMRUpdate } from './hmr'