]> 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>
Wed, 12 May 2021 14:33:31 +0000 (16:33 +0200)
__tests__/onAction.spec.ts
src/devtools/formatting.ts
src/devtools/plugin.ts
src/mapHelpers.ts
src/rootStore.ts
src/store.ts
src/types.ts

index f4faa6b80a31a2c0f39122404c2363f3fa754de8..dd3d3cc6792747e19fbd9ed0da964bb71f984e61 100644 (file)
@@ -68,7 +68,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 0b3aaaf9139302ca8d07cb088ebb2567e482fa6a..54bba4766b0a018b25165363e72ec5adf56f50d4 100644 (file)
@@ -1,5 +1,5 @@
 import { CustomInspectorNode, CustomInspectorState } from '@vue/devtools-api'
-import { GenericStore, GettersTree, MutationType, StateTree } from '../types'
+import { Store, GettersTree, MutationType, StateTree } from '../types'
 import { DebuggerEvent } from 'vue'
 
 export function formatDisplay(display: string) {
@@ -10,9 +10,7 @@ export function formatDisplay(display: string) {
   }
 }
 
-export function formatStoreForInspectorTree(
-  store: GenericStore
-): CustomInspectorNode {
+export function formatStoreForInspectorTree(store: Store): CustomInspectorNode {
   return {
     id: store.$id,
     label: store.$id,
@@ -21,7 +19,7 @@ export function formatStoreForInspectorTree(
 }
 
 export function formatStoreForInspectorState(
-  store: GenericStore
+  store: Store
 ): CustomInspectorState[string] {
   const fields: CustomInspectorState[string] = [
     { editable: false, key: 'id', value: formatDisplay(store.$id) },
index fcba6f69322cf3b85d2965284e90ab0e9813dbbd..90cfcd955d7210046028a6373b52d2f972055f88 100644 (file)
@@ -2,7 +2,7 @@ import { setupDevtoolsPlugin, TimelineEvent } from '@vue/devtools-api'
 import { App } from 'vue'
 import { PiniaPluginContext, setActivePinia } from '../rootStore'
 import {
-  GenericStore,
+  Store,
   GettersTree,
   MutationType,
   StateTree,
@@ -18,7 +18,7 @@ import {
 /**
  * Registered stores used for devtools.
  */
-const registeredStores = /*#__PURE__*/ new Set<GenericStore>()
+const registeredStores = /*#__PURE__*/ new Set<Store>()
 
 let isAlreadyInstalled: boolean | undefined
 // timeline can be paused when directly changing the state
@@ -28,7 +28,7 @@ const componentStateTypes: string[] = []
 const MUTATIONS_LAYER_ID = 'pinia:mutations'
 const INSPECTOR_ID = 'pinia'
 
-export function addDevtools(app: App, store: GenericStore) {
+export function addDevtools(app: App, store: Store) {
   registeredStores.add(store)
   componentStateTypes.push('🍍 ' + store.$id)
   setupDevtoolsPlugin(
index eac63bd04ae7ea71184690a68ef5574eb4401cd5..47c5c9b0885c1218b1fb06b7b3e64464c9866375 100644 (file)
@@ -1,6 +1,5 @@
 import { ComponentPublicInstance } from 'vue'
 import {
-  GenericStore,
   GettersTree,
   _Method,
   StateTree,
@@ -149,7 +148,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 ec293a34cd8b6262f6c230313b3fa4d468d51358..b1d85d9dc84a01e110f8a7aa537beb27d9056fce 100644 (file)
@@ -3,7 +3,6 @@ import {
   StateTree,
   StoreWithState,
   StateDescriptor,
-  GenericStore,
   PiniaCustomProperties,
   _Method,
   DefineStoreOptions,
@@ -54,7 +53,7 @@ export const storesMap = new WeakMap<
     [
       StoreWithState<string, StateTree>,
       StateDescriptor<StateTree>,
-      InjectionKey<GenericStore>
+      InjectionKey<Store>
     ]
   >
 >()
@@ -105,7 +104,7 @@ declare module '@vue/runtime-core' {
      *
      * @internal
      */
-    _pStores?: Record<string, GenericStore>
+    _pStores?: Record<string, Store>
   }
 }
 
index ffd31de11e8e6ec6b8aa3d8192bd2196bcbd2812..6ed81b7378e6163b4a2b95bd4bcaaa8382c5d47e 100644 (file)
@@ -25,7 +25,6 @@ import {
   StateDescriptor,
   DefineStoreOptions,
   StoreDefinition,
-  GenericStore,
   GettersTree,
   MutationType,
   StoreOnActionListener,
@@ -100,7 +99,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.state.value[$id] = initialState || buildState()
index cd48cf30c8353e03d6f96dc7e978a5353c31426e..1f75c0d8be4aac89b92f4baadcf143ad9e40b292 100644 (file)
@@ -313,23 +313,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()`