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')
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) {
}
}
-export function formatStoreForInspectorTree(
- store: GenericStore
-): CustomInspectorNode {
+export function formatStoreForInspectorTree(store: Store): CustomInspectorNode {
return {
id: store.$id,
label: store.$id,
}
export function formatStoreForInspectorState(
- store: GenericStore
+ store: Store
): CustomInspectorState[string] {
const fields: CustomInspectorState[string] = [
{ editable: false, key: 'id', value: formatDisplay(store.$id) },
import { App } from 'vue'
import { PiniaPluginContext, setActivePinia } from '../rootStore'
import {
- GenericStore,
+ Store,
GettersTree,
MutationType,
StateTree,
/**
* 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
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(
import { ComponentPublicInstance } from 'vue'
import {
- GenericStore,
GettersTree,
_Method,
StateTree,
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]]
StateTree,
StoreWithState,
StateDescriptor,
- GenericStore,
PiniaCustomProperties,
_Method,
DefineStoreOptions,
[
StoreWithState<string, StateTree>,
StateDescriptor<StateTree>,
- InjectionKey<GenericStore>
+ InjectionKey<Store>
]
>
>()
*
* @internal
*/
- _pStores?: Record<string, GenericStore>
+ _pStores?: Record<string, Store>
}
}
StateDescriptor,
DefineStoreOptions,
StoreDefinition,
- GenericStore,
GettersTree,
MutationType,
StoreOnActionListener,
): [
StoreWithState<Id, S>,
{ get: () => S; set: (newValue: S) => void },
- InjectionKey<GenericStore>
+ InjectionKey<Store>
] {
const pinia = getActivePinia()
pinia.state.value[$id] = initialState || buildState()
/**
* 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()`