import { defineStore } from './store'
+/**
+ * {@inheritDoc defineStore}
+ * @deprecated Use {@link defineStore}
+ */
export const createStore = ((options: any) => {
console.warn(
'[🍍]: "createStore" has been deprecated and will be removed on the sable release, use "defineStore" instead.'
* `fetch`, `setup`, `serverPrefetch` and others
*/
export let activePinia: Pinia | undefined
+
+/**
+ * Sets or unsets the active pinia. Used in SSR and internally when calling
+ * actions and getters
+ *
+ * @param pinia - Pinia instance
+ */
export const setActivePinia = (pinia: Pinia | undefined) =>
(activePinia = pinia)
+/**
+ * Get the currently active pinia
+ */
export const getActivePinia = () => {
if (__DEV__ && !activePinia) {
warn(
export const setClientApp = (app: App) => (clientApp = app)
export const getClientApp = () => clientApp
+/**
+ * Every application must own its own pinia to be able to create stores
+ */
export interface Pinia {
install: Exclude<Plugin['install'], undefined>
? Symbol('pinia')
: Symbol()) as InjectionKey<Pinia>
+/**
+ * Creates a Pinia instance to be used by the application
+ */
export function createPinia(): Pinia {
const state = ref({})
import { Ref } from 'vue'
import { Pinia } from './rootStore'
+/**
+ * Generic state of a Store
+ */
export type StateTree = Record<string | number | symbol, any>
/**
)
}
+/**
+ * Store Getter
+ * @internal
+ */
export interface StoreGetter<S extends StateTree, T = any> {
(state: S, getters: Record<string, Ref<any>>): T
}
state: S
) => void
+/**
+ * Base store with state and functions
+ * @internal
+ */
export interface StoreWithState<Id extends string, S extends StateTree> {
/**
* Unique identifier of the store
// }
// in this type we forget about this because otherwise the type is recursive
+/**
+ * Store augmented for actions
+ * @internal
+ */
export type StoreWithActions<A> = {
[k in keyof A]: A[k] extends (...args: infer P) => infer R
? (...args: P) => R
// (state: S, getters: Record<string, Ref<any>>): T
// }
+/**
+ * Store augmented with getters
+ * @internal
+ */
export type StoreWithGetters<G> = {
[k in keyof G]: G[k] extends (this: infer This, store?: any) => infer R
? R
// }
// has the actions without the context (this) for typings
+/**
+ * Store type to build a store
+ */
export type Store<
Id extends string,
S extends StateTree,
A
> = StoreWithState<Id, S> & S & StoreWithGetters<G> & StoreWithActions<A>
+/**
+ * Generic store type
+ */
export type GenericStore = Store<
string,
StateTree,