]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
refactor(types): move extractor types
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 28 Jul 2021 16:20:46 +0000 (18:20 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 28 Jul 2021 16:20:46 +0000 (18:20 +0200)
src/store.ts
src/types.ts

index 5eaf7eddec1bb8c0a45ef7ef88ab519d8dfa6f15..766022cf503031799aa6381fb5414dd7a82b243a 100644 (file)
@@ -37,6 +37,9 @@ import {
   DefineStoreOptionsInPlugin,
   StoreGeneric,
   StoreWithGetters,
+  _ExtractActionsFromSetupStore,
+  _ExtractGettersFromSetupStore,
+  _ExtractStateFromSetupStore,
 } from './types'
 import {
   getActivePinia,
@@ -132,8 +135,6 @@ function createOptionsStore<
 
   store = createSetupStore(id, setup, options, pinia, hot)
 
-  // TODO: HMR should also replace getters here
-
   store.$reset = $reset
 
   return store as any
@@ -574,63 +575,6 @@ function createSetupStore<
 
 // }
 
-/**
- * @internal
- */
-type _SpreadStateFromStore<SS, K extends readonly any[]> = K extends readonly [
-  infer A,
-  ...infer Rest
-]
-  ? A extends string | number | symbol
-    ? SS extends Record<A, _Method | ComputedRef<any>>
-      ? _SpreadStateFromStore<SS, Rest>
-      : SS extends Record<A, any>
-      ? Record<A, UnwrapRef<SS[A]>> & _SpreadStateFromStore<SS, Rest>
-      : never
-    : {}
-  : {}
-
-/**
- * @internal
- */
-type _SpreadPropertiesFromObject<
-  SS,
-  K extends readonly any[],
-  T
-> = K extends readonly [infer A, ...infer Rest]
-  ? A extends string | number | symbol
-    ? SS extends Record<A, T>
-      ? Record<A, UnwrapRef<SS[A]>> & _SpreadPropertiesFromObject<SS, Rest, T>
-      : _SpreadPropertiesFromObject<SS, Rest, T>
-    : {}
-  : {}
-
-/**
- * @internal
- */
-type _ExtractStateFromSetupStore<SS> = _SpreadStateFromStore<
-  SS,
-  _UnionToTuple<keyof SS>
->
-
-/**
- * @internal
- */
-type _ExtractActionsFromSetupStore<SS> = _SpreadPropertiesFromObject<
-  SS,
-  _UnionToTuple<keyof SS>,
-  _Method
->
-
-/**
- * @internal
- */
-type _ExtractGettersFromSetupStore<SS> = _SpreadPropertiesFromObject<
-  SS,
-  _UnionToTuple<keyof SS>,
-  ComputedRef<any>
->
-
 /**
  * Extract the actions of a store type. Works with both a Setup Store or an
  * Options Store.
index e00bb23f4ccca013c8e19cab1ae50c2a619d88f0..e6d4ccdd81a86629934c312f34cb7e94c21b817e 100644 (file)
@@ -1,4 +1,4 @@
-import { DebuggerEvent, Ref, UnwrapRef } from 'vue'
+import { ComputedRef, DebuggerEvent, Ref, UnwrapRef } from 'vue'
 import { Pinia } from './rootStore'
 
 /**
@@ -549,6 +549,63 @@ export interface DefineStoreOptionsBase<S extends StateTree, Store> {
   hydrate?(store: Store, initialState: UnwrapRef<S>): void
 }
 
+/**
+ * @internal
+ */
+type _SpreadStateFromStore<SS, K extends readonly any[]> = K extends readonly [
+  infer A,
+  ...infer Rest
+]
+  ? A extends string | number | symbol
+    ? SS extends Record<A, _Method | ComputedRef<any>>
+      ? _SpreadStateFromStore<SS, Rest>
+      : SS extends Record<A, any>
+      ? Record<A, UnwrapRef<SS[A]>> & _SpreadStateFromStore<SS, Rest>
+      : never
+    : {}
+  : {}
+
+/**
+ * @internal
+ */
+type _SpreadPropertiesFromObject<
+  SS,
+  K extends readonly any[],
+  T
+> = K extends readonly [infer A, ...infer Rest]
+  ? A extends string | number | symbol
+    ? SS extends Record<A, T>
+      ? Record<A, UnwrapRef<SS[A]>> & _SpreadPropertiesFromObject<SS, Rest, T>
+      : _SpreadPropertiesFromObject<SS, Rest, T>
+    : {}
+  : {}
+
+/**
+ * @internal
+ */
+export type _ExtractStateFromSetupStore<SS> = _SpreadStateFromStore<
+  SS,
+  _UnionToTuple<keyof SS>
+>
+
+/**
+ * @internal
+ */
+export type _ExtractActionsFromSetupStore<SS> = _SpreadPropertiesFromObject<
+  SS,
+  _UnionToTuple<keyof SS>,
+  _Method
+>
+
+/**
+ * @internal
+ */
+export type _ExtractGettersFromSetupStore<SS> = _SpreadPropertiesFromObject<
+  SS,
+  _UnionToTuple<keyof SS>,
+  ComputedRef<any>
+>
+
 /**
  * Options parameter of `defineStore()` for option stores. Can be extended to
  * augment stores with the plugin API. @see {@link DefineStoreOptionsBase}.
@@ -595,7 +652,7 @@ export interface DefineStoreOptions<
  */
 export interface DefineSetupStoreOptions<
   Id extends string,
-  // TODO: pass SS instead
+  // NOTE: Passing SS seems to make TS crash
   S extends StateTree,
   G,
   A /* extends ActionsTree */