]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
refactor(types): use Store with defaults, deprecate GenericStore
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 12 May 2021 14:33:31 +0000 (16:33 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 13 May 2021 11:22:19 +0000 (13:22 +0200)
__tests__/onAction.spec.ts
src/mapHelpers.ts
src/rootStore.ts
src/store.ts
src/types.ts

index 315388eeda6381f18d0ee37ef485f7a2401391d1..b42e147c3a93160b4da5bb8ac05ef3f8c02fc4d3 100644 (file)
@@ -70,7 +70,15 @@ describe('Subscriptions', () => {
 
   it('calls after with the returned value', async () => {
     const spy = jest.fn()
-    store.$onAction(({ after }) => {
+    store.$onAction(({ after, name, store }) => {
+      name
+      if (name === 'upperName') {
+        after((ret) => {
+          // @ts-expect-error
+          ret * 2
+          ret.toUpperCase()
+        })
+      }
       after(spy)
     })
     expect(store.upperName()).toBe('EDUARDO')
index 347d2de6e74ede520f99463598bf9bb76f0c8f4d..bddb18a47e5c095beb5a0527e3c521cfc946f83d 100644 (file)
@@ -1,6 +1,5 @@
 import type Vue from 'vue'
 import {
-  GenericStore,
   GettersTree,
   _Method,
   StateTree,
@@ -151,7 +150,7 @@ export type _MapStateObjectReturn<
     keyof S | keyof G | ((store: Store<Id, S, G, A>) => any)
   >
 > = {
-  [key in keyof T]: () => T[key] extends (store: GenericStore) => infer R
+  [key in keyof T]: () => T[key] extends (store: Store) => infer R
     ? R
     : T[key] extends keyof S | keyof G
     ? Store<Id, S, G, A>[T[key]]
index 4e27d00c6ab2dab92eb8139ce30734aac543aa56..9f8dfbd7833ad2ad9939ad8b1ff1b63358762817 100644 (file)
@@ -26,7 +26,7 @@ export const storesMap = new WeakMap<
     [
       StoreWithState<string, StateTree>,
       StateDescriptor<StateTree>,
-      InjectionKey<GenericStore>
+      InjectionKey<Store>
     ]
   >
 >()
@@ -122,7 +122,7 @@ declare module 'vue/types/vue' {
      *
      * @internal
      */
-    _pStores?: Record<string, GenericStore>
+    _pStores?: Record<string, Store>
   }
 }
 
index 24f938e9f5745b1e524fb30f81ea0371cedc6868..4c4794a69d71e7e2094a845282a58ca610cb4a8e 100644 (file)
@@ -100,7 +100,7 @@ function initStore<Id extends string, S extends StateTree>(
 ): [
   StoreWithState<Id, S>,
   { get: () => S; set: (newValue: S) => void },
-  InjectionKey<GenericStore>
+  InjectionKey<Store>
 ] {
   const pinia = getActivePinia()
   pinia.Vue.set(pinia.state.value, $id, initialState || buildState())
index 1f04cf9bb2138fde4bff185bc2332ede98adc768..dd097368168f2d686097c5546c7a7e59247d69d1 100644 (file)
@@ -300,23 +300,9 @@ export interface StoreDefinition<
 
 /**
  * Generic version of Store.
+ * @deprecated Use Store instead
  */
-export type GenericStore = Store<
-  string,
-  StateTree,
-  GettersTree<StateTree>,
-  Record<string, _Method>
->
-
-/**
- * Generic version of `StoreDefinition`.
- */
-export type GenericStoreDefinition = StoreDefinition<
-  string,
-  StateTree,
-  GettersTree<StateTree>,
-  Record<string, _Method>
->
+export type GenericStore = Store
 
 /**
  * Properties that are added to every store by `pinia.use()`