} from 'vue-demi'
import { Pinia, PiniaPluginContext } from '../rootStore'
import {
- GettersTree,
+ _GettersTree,
MutationType,
StateTree,
- ActionsTree,
+ _ActionsTree,
StoreGeneric,
} from '../types'
import {
value: store._getters.reduce((getters, key) => {
getters[key] = store[key]
return getters
- }, {} as GettersTree<StateTree>),
+ }, {} as _GettersTree<StateTree>),
})
}
})
// use toRaw to avoid tracking #541
storeActions[actionName] = toRaw(store)[actionName]
return storeActions
- }, {} as ActionsTree)
+ }, {} as _ActionsTree)
for (const actionName in actions) {
store[actionName] = function () {
export function devtoolsPlugin<
Id extends string = string,
S extends StateTree = StateTree,
- G /* extends GettersTree<S> */ = GettersTree<S>,
- A /* extends ActionsTree */ = ActionsTree
+ G /* extends GettersTree<S> */ = _GettersTree<S>,
+ A /* extends ActionsTree */ = _ActionsTree
>({ app, store, options }: PiniaPluginContext<Id, S, G, A>) {
// HMR module
if (store.$id.startsWith('__hot:')) {
// TODO: remove in release
GenericStore,
StoreDefinition,
- StoreWithGetters,
- GettersTree,
- ActionsTree,
+ _StoreWithGetters,
+ _GettersTree,
+ _ActionsTree,
_Method,
- StoreWithActions,
- StoreWithState,
+ _StoreWithActions,
+ _StoreWithState,
StoreProperties,
StoreOnActionListener,
StoreOnActionListenerContext,
import type { ComponentPublicInstance } from 'vue-demi'
import type {
- GettersTree,
+ _GettersTree,
_Method,
StateTree,
Store,
*/
export type _MapStateReturn<
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
Keys extends keyof S | keyof G = keyof S | keyof G
> = {
// [key in keyof S | keyof G]: () => key extends keyof S
export type _MapStateObjectReturn<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A,
T extends Record<
string,
export function mapState<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A,
KeyMapper extends Record<
string,
export function mapState<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A,
Keys extends keyof S | keyof G
>(
export function mapState<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A
>(
useStore: StoreDefinition<Id, S, G, A>,
export function mapActions<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A,
KeyMapper extends Record<string, keyof A>
>(
export function mapActions<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A
>(
useStore: StoreDefinition<Id, S, G, A>,
export function mapActions<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A,
KeyMapper extends Record<string, keyof A>
>(
export function mapWritableState<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A,
KeyMapper extends Record<string, keyof S>
>(
export function mapWritableState<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A
>(
useStore: StoreDefinition<Id, S, G, A>,
export function mapWritableState<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
+ G extends _GettersTree<S>,
A,
KeyMapper extends Record<string, keyof S>
>(
PiniaCustomProperties,
_Method,
Store,
- GettersTree,
- ActionsTree,
+ _GettersTree,
+ _ActionsTree,
PiniaCustomStateProperties,
DefineStoreOptionsInPlugin,
StoreGeneric,
export interface PiniaPluginContext<
Id extends string = string,
S extends StateTree = StateTree,
- G /* extends GettersTree<S> */ = GettersTree<S>,
- A /* extends ActionsTree */ = ActionsTree
+ G /* extends _GettersTree<S> */ = _GettersTree<S>,
+ A /* extends _ActionsTree */ = _ActionsTree
> {
/**
* pinia instance.
_Method,
DefineStoreOptions,
StoreDefinition,
- GettersTree,
+ _GettersTree,
MutationType,
StoreOnActionListener,
- ActionsTree,
+ _ActionsTree,
SubscriptionCallbackMutation,
DefineSetupStoreOptions,
DefineStoreOptionsInPlugin,
StoreGeneric,
- StoreWithGetters,
+ _StoreWithGetters,
_ExtractActionsFromSetupStore,
_ExtractGettersFromSetupStore,
_ExtractStateFromSetupStore,
- StoreWithState,
+ _StoreWithState,
} from './types'
import { setActivePinia, piniaSymbol, Pinia, activePinia } from './rootStore'
import { IS_CLIENT } from './env'
function createOptionsStore<
Id extends string,
S extends StateTree,
- G extends GettersTree<S>,
- A extends ActionsTree
+ G extends _GettersTree<S>,
+ A extends _ActionsTree
>(
id: Id,
options: DefineStoreOptions<Id, S, G, A>,
SS,
S extends StateTree,
G extends Record<string, _Method>,
- A extends ActionsTree
+ A extends _ActionsTree
>(
$id: Id,
setup: () => SS,
return removeSubscription
},
$dispose,
- } as StoreWithState<Id, S, G, A>
+ } as _StoreWithState<Id, S, G, A>
if (isVue2) {
// start as non ready
export type StoreActions<SS> = SS extends Store<
string,
StateTree,
- GettersTree<StateTree>,
+ _GettersTree<StateTree>,
infer A
>
? A
string,
StateTree,
infer G,
- ActionsTree
+ _ActionsTree
>
- ? StoreWithGetters<G>
+ ? _StoreWithGetters<G>
: _ExtractGettersFromSetupStore<SS>
/**
export type StoreState<SS> = SS extends Store<
string,
infer S,
- GettersTree<StateTree>,
- ActionsTree
+ _GettersTree<StateTree>,
+ _ActionsTree
>
? UnwrapRef<S>
: _ExtractStateFromSetupStore<SS>
export function defineStore<
Id extends string,
S extends StateTree = {},
- G extends GettersTree<S> = {},
+ G extends _GettersTree<S> = {},
// cannot extends ActionsTree because we loose the typings
A /* extends ActionsTree */ = {}
>(
export function defineStore<
Id extends string,
S extends StateTree = {},
- G extends GettersTree<S> = {},
+ G extends _GettersTree<S> = {},
// cannot extends ActionsTree because we loose the typings
A /* extends ActionsTree */ = {}
>(options: DefineStoreOptions<Id, S, G, A>): StoreDefinition<Id, S, G, A>
): StoreDefinition {
let id: string
let options:
- | DefineStoreOptions<string, StateTree, GettersTree<StateTree>, ActionsTree>
+ | DefineStoreOptions<
+ string,
+ StateTree,
+ _GettersTree<StateTree>,
+ _ActionsTree
+ >
| DefineSetupStoreOptions<
string,
StateTree,
- GettersTree<StateTree>,
- ActionsTree
+ _GettersTree<StateTree>,
+ _ActionsTree
>
const isSetupStore = typeof setup === 'function'
}
/**
- * Base type for the context passed to a subscription callback.
- *
- * @internal
+ * Base type for the context passed to a subscription callback. Internal type.
*/
export interface _SubscriptionCallbackMutationBase {
/**
state: UnwrapRef<S>
) => void
-type _StoreOnActionListenerContext<Store, ActionName extends string, A> = {
+/**
+ * Actual type for {@link StoreOnActionListenerContext}. Exists for refactoring
+ * purposes. For internal use only.
+ */
+interface _StoreOnActionListenerContext<Store, ActionName extends string, A> {
/**
* Name of the action
*/
S extends StateTree,
G /* extends GettersTree<S> */,
A /* extends ActionsTree */
-> = ActionsTree extends A
- ? _StoreOnActionListenerContext<StoreGeneric, string, ActionsTree>
+> = _ActionsTree extends A
+ ? _StoreOnActionListenerContext<StoreGeneric, string, _ActionsTree>
: {
[Name in keyof A]: Name extends string
? _StoreOnActionListenerContext<Store<Id, S, G, A>, Name, A>
S,
G,
// {} creates a type of never due to how StoreOnActionListenerContext is defined
- {} extends A ? ActionsTree : A
+ {} extends A ? _ActionsTree : A
>
) => void
_hmrPayload: {
state: string[]
hotState: Ref<StateTree>
- actions: ActionsTree
- getters: ActionsTree
+ actions: _ActionsTree
+ getters: _ActionsTree
}
}
/**
- * Base store with state and functions
- * @internal
+ * Base store with state and functions. Should not be used directly.
*/
-export interface StoreWithState<
+export interface _StoreWithState<
Id extends string,
S extends StateTree,
G /* extends GettersTree<StateTree> */,
// in this type we forget about this because otherwise the type is recursive
/**
- * Store augmented for actions
- *
+ * Store augmented for actions. For internal usage only.
* @internal
*/
-export type StoreWithActions<A> = {
+export type _StoreWithActions<A> = {
[k in keyof A]: A[k] extends (...args: infer P) => infer R
? (...args: P) => R
: never
}
/**
- * Store augmented with getters
- *
+ * Store augmented with getters. For internal usage only.
* @internal
*/
-export type StoreWithGetters<G> = {
+export type _StoreWithGetters<G> = {
readonly [k in keyof G]: G[k] extends (...args: any[]) => infer R
? R
: UnwrapRef<G[k]>
}
/**
- * Store type to build a store
+ * Store type to build a store.
*/
export type Store<
Id extends string = string,
G /* extends GettersTree<S>*/ = {},
// has the actions without the context (this) for typings
A /* extends ActionsTree */ = {}
-> = StoreWithState<Id, S, G, A> &
+> = _StoreWithState<Id, S, G, A> &
UnwrapRef<S> &
- StoreWithGetters<G> &
+ _StoreWithGetters<G> &
// StoreWithActions<A> &
- (ActionsTree extends A ? {} : A) &
+ (_ActionsTree extends A ? {} : A) &
PiniaCustomProperties<Id, S, G, A> &
PiniaCustomStateProperties<S>
export type StoreGeneric = Store<
string,
StateTree,
- GettersTree<StateTree>,
- ActionsTree
+ _GettersTree<StateTree>,
+ _ActionsTree
>
/**
export type GenericStore<
Id extends string = string,
S extends StateTree = StateTree,
- G /* extends GettersTree<S> */ = GettersTree<S>,
+ G /* extends GettersTree<S> */ = _GettersTree<S>,
// has the actions without the context (this) for typings
- A /* extends ActionsTree */ = ActionsTree
-> = StoreWithState<Id, S, G, A> &
+ A /* extends ActionsTree */ = _ActionsTree
+> = _StoreWithState<Id, S, G, A> &
UnwrapRef<S> &
- StoreWithGetters<G> &
+ _StoreWithGetters<G> &
A &
PiniaCustomProperties<Id, S, G, A> &
PiniaCustomStateProperties<S>
export interface StoreDefinition<
Id extends string = string,
S extends StateTree = StateTree,
- G /* extends GettersTree<S>*/ = GettersTree<S>,
- A /* extends ActionsTree */ = ActionsTree
+ G /* extends GettersTree<S>*/ = _GettersTree<S>,
+ A /* extends ActionsTree */ = _ActionsTree
> {
/**
* Returns a store, creates it if necessary.
}
/**
- * Properties that are added to every store by `pinia.use()`.
+ * Interface to be extended by the user when they add properties through plugins.
*/
export interface PiniaCustomProperties<
Id extends string = string,
S extends StateTree = StateTree,
- G /* extends GettersTree<S> */ = GettersTree<S>,
- A /* extends ActionsTree */ = ActionsTree
+ G /* extends GettersTree<S> */ = _GettersTree<S>,
+ A /* extends ActionsTree */ = _ActionsTree
> {}
/**
export interface PiniaCustomStateProperties<S extends StateTree = StateTree> {}
/**
- * Type of an object of Getters that infers the argument.
- *
+ * Type of an object of Getters that infers the argument. For internal usage only.
* @internal
*/
-export type GettersTree<S extends StateTree> = Record<
+export type _GettersTree<S extends StateTree> = Record<
string,
| ((state: UnwrapRef<S> & UnwrapRef<PiniaCustomStateProperties<S>>) => any)
| (() => any)
>
/**
- * Type of an object of Actions.
- *
+ * Type of an object of Actions. For internal usage only.
* @internal
*/
-export type ActionsTree = Record<string, _Method>
+export type _ActionsTree = Record<string, _Method>
/**
* @internal
* Optional object of getters.
*/
getters?: G &
- ThisType<UnwrapRef<S> & StoreWithGetters<G> & PiniaCustomProperties> &
- GettersTree<S>
+ ThisType<UnwrapRef<S> & _StoreWithGetters<G> & PiniaCustomProperties> &
+ _GettersTree<S>
/**
* Optional object of actions.
ThisType<
A &
UnwrapRef<S> &
- StoreWithState<Id, S, G, A> &
- StoreWithGetters<G> &
+ _StoreWithState<Id, S, G, A> &
+ _StoreWithGetters<G> &
PiniaCustomProperties
>
}