]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
refactor: use original definestoreoptions type
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 9 Jul 2021 18:53:01 +0000 (20:53 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 19 Jul 2021 09:51:12 +0000 (11:51 +0200)
src/rootStore.ts
src/store.ts
src/types.ts

index a1402c9bc2aed697aaf650472e1dca492ec834ef..1b8278001fd37572d156564e425ab167ea80ec93 100644 (file)
@@ -5,7 +5,6 @@ import {
   StateDescriptor,
   PiniaCustomProperties,
   _Method,
-  DefineStoreOptions,
   Store,
   GettersTree,
   ActionsTree,
index 931543b3261ded5d58b604604a7b93214f4e6a48..4ff234c404fee6aacc2fff70512f8a56832aeed0 100644 (file)
@@ -32,7 +32,6 @@ import {
   ActionsTree,
   SubscriptionCallbackMutation,
   _UnionToTuple,
-  DefineOptionStoreOptions,
   DefineSetupStoreOptions,
   DefineStoreOptionsInPlugin,
 } from './types'
@@ -80,10 +79,7 @@ function createOptionsStore<
   S extends StateTree,
   G extends GettersTree<S>,
   A extends ActionsTree
->(
-  options: DefineOptionStoreOptions<Id, S, G, A>,
-  pinia: Pinia
-): Store<Id, S, G, A> {
+>(options: DefineStoreOptions<Id, S, G, A>, pinia: Pinia): Store<Id, S, G, A> {
   const { id, state, actions, getters } = options
   function $reset() {
     pinia.state.value[id] = state ? state() : {}
@@ -125,11 +121,13 @@ function createSetupStore<
 >(
   $id: Id,
   setup: () => SS,
-  options: DefineStoreOptions<Id, S, G, A> = {}
+  options:
+    | DefineSetupStoreOptions<Id, S, G, A>
+    | DefineStoreOptions<Id, S, G, A> = {}
 ): Store<Id, S, G, A> {
   const pinia = getActivePinia()
   let scope!: EffectScope
-  const buildState = (options as DefineOptionStoreOptions<Id, S, G, A>).state
+  const buildState = (options as DefineStoreOptions<Id, S, G, A>).state
 
   const optionsForPlugin: DefineStoreOptionsInPlugin<Id, S, G, A> = {
     actions: {} as A,
@@ -560,9 +558,7 @@ export function defineStore<
   G extends GettersTree<S>,
   // cannot extends ActionsTree because we loose the typings
   A /* extends ActionsTree */
->(
-  options: DefineOptionStoreOptions<Id, S, G, A>
-): StoreDefinition<Id, S, G, A> {
+>(options: DefineStoreOptions<Id, S, G, A>): StoreDefinition<Id, S, G, A> {
   const { id } = options
 
   function useStore(pinia?: Pinia | null) {
index a69ffba51d37988eab539f4f9796590e9e053ff4..90163db2dec5b5fa292d7c14f88840413054ac43 100644 (file)
@@ -455,7 +455,7 @@ export type ActionsTree = Record<string, _Method>
  * Options parameter of `defineStore()`. Can be extended to augment stores with
  * the plugin API.
  */
-export interface DefineOptionStoreOptions<
+export interface DefineStoreOptions<
   Id extends string,
   S extends StateTree,
   G extends GettersTree<S>,
@@ -508,7 +508,10 @@ export interface DefineSetupStoreOptions<
   S extends StateTree,
   G extends ActionsTree, // TODO: naming
   A /* extends ActionsTree */
-> extends Pick<DefineOptionStoreOptions<Id, S, G, A>, 'hydrate'> {
+> extends Omit<
+    DefineStoreOptions<Id, S, G, A>,
+    'actions' | 'id' | 'state' | 'getters'
+  > {
   /**
    * Extracted actions. Added by useStore(). SHOULD NOT be added by the user when
    * creating the store. Can be used in plugins to get the list of actions in a
@@ -525,7 +528,7 @@ export interface DefineStoreOptionsInPlugin<
   S extends StateTree,
   G extends ActionsTree, // TODO: naming
   A /* extends ActionsTree */
-> extends Omit<DefineOptionStoreOptions<Id, S, G, A>, 'id'> {
+> extends Omit<DefineStoreOptions<Id, S, G, A>, 'id'> {
   /**
    * Extracted object of actions. Added by useStore() when the store is built
    * using the setup API, otherwise uses the one passed to `defineStore()`.
@@ -541,13 +544,6 @@ export interface DefineStoreOptionsInPlugin<
   id?: Id
 }
 
-export type DefineStoreOptions<
-  Id extends string,
-  S extends StateTree,
-  G extends GettersTree<S>,
-  A /* extends ActionsTree */
-> = DefineOptionStoreOptions<Id, S, G, A> | DefineSetupStoreOptions<Id, S, G, A>
-
 export type _UnionToTuple<U> = _UnionToTupleRecursively<[], U>
 
 type _Overwrite<T, S extends any> = {