StoreWithGetters,
StoreGetter,
NonNullObject,
+ StoreAction,
+ StoreWithActions,
} from './types'
import { useStoreDevtools } from './devtools'
export const getActiveReq = () => activeReq
-export interface StoreAction {
- (...args: any[]): any
-}
-
-// in this type we forget about this because otherwise the type is recursive
-type StoreWithActions<A extends Record<string, StoreAction>> = {
- [k in keyof A]: A[k] extends (this: infer This, ...args: infer P) => infer R
- ? (this: This, ...args: P) => R
- : never
-}
-
// has the actions without the context (this) for typings
export type Store<
Id extends string,
A extends Record<string, StoreAction>
> = StoreWithState<Id, S> & StoreWithGetters<S, G> & StoreWithActions<A>
-export type PiniaStore<
- P extends Record<string, Store<any, any, any, any>>
-> = P extends Record<infer name, any>
- ? {
- [Id in P[name]['id']]: P[name] extends Store<
- Id,
- infer S,
- infer G,
- infer A
- >
- ? StoreWithGetters<S, G>
- : never
- }
- : never
-
/**
* Creates a store instance
* @param id unique identifier of the store, like a name. eg: main, cart, user
state: S
/**
- * Private property defining the _req for this store
+ * Private property defining the request key for this store
*/
_r: NonNullObject
subscribe(callback: SubscriptionCallback<S>): () => void
}
+export interface StoreAction {
+ (...args: any[]): any
+}
+
+// in this type we forget about this because otherwise the type is recursive
+export type StoreWithActions<A extends Record<string, StoreAction>> = {
+ [k in keyof A]: A[k] extends (this: infer This, ...args: infer P) => infer R
+ ? (this: This, ...args: P) => R
+ : never
+}
+
export interface DevtoolHook {
on(
event: string,