]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: show more api docs
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 22 Oct 2021 10:18:21 +0000 (12:18 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 22 Oct 2021 10:18:21 +0000 (12:18 +0200)
packages/pinia/src/devtools/plugin.ts
packages/pinia/src/index.ts
packages/pinia/src/mapHelpers.ts
packages/pinia/src/rootStore.ts
packages/pinia/src/store.ts
packages/pinia/src/types.ts

index 04fd9d001b62c2b1750e3247e2f62f8b20bf42ca..8f4c2af99be227c4fe767b64510957a4957a93d0 100644 (file)
@@ -9,10 +9,10 @@ import {
 } from 'vue-demi'
 import { Pinia, PiniaPluginContext } from '../rootStore'
 import {
-  GettersTree,
+  _GettersTree,
   MutationType,
   StateTree,
-  ActionsTree,
+  _ActionsTree,
   StoreGeneric,
 } from '../types'
 import {
@@ -139,7 +139,7 @@ export function registerPiniaDevtools(app: App, pinia: Pinia) {
                 value: store._getters.reduce((getters, key) => {
                   getters[key] = store[key]
                   return getters
-                }, {} as GettersTree<StateTree>),
+                }, {} as _GettersTree<StateTree>),
               })
             }
           })
@@ -447,7 +447,7 @@ function patchActionForGrouping(store: StoreGeneric, actionNames: string[]) {
     // 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 () {
@@ -478,8 +478,8 @@ function patchActionForGrouping(store: StoreGeneric, actionNames: string[]) {
 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:')) {
index 9387295212f9e9dfe90d81487539c19b2cf7daed..f46c3d0ccd3320f6526b645e51f80d0352d95554 100644 (file)
@@ -15,12 +15,12 @@ export type {
   // TODO: remove in release
   GenericStore,
   StoreDefinition,
-  StoreWithGetters,
-  GettersTree,
-  ActionsTree,
+  _StoreWithGetters,
+  _GettersTree,
+  _ActionsTree,
   _Method,
-  StoreWithActions,
-  StoreWithState,
+  _StoreWithActions,
+  _StoreWithState,
   StoreProperties,
   StoreOnActionListener,
   StoreOnActionListenerContext,
index de55bfe75baf7fd0117d49b15e79e526039e8f1f..2b97ebdd380fc4acd65ccbddd89b89670a01b629 100644 (file)
@@ -1,6 +1,6 @@
 import type { ComponentPublicInstance } from 'vue-demi'
 import type {
-  GettersTree,
+  _GettersTree,
   _Method,
   StateTree,
   Store,
@@ -124,7 +124,7 @@ export function mapStores<Stores extends any[]>(
  */
 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
@@ -141,7 +141,7 @@ export type _MapStateReturn<
 export type _MapStateObjectReturn<
   Id extends string,
   S extends StateTree,
-  G extends GettersTree<S>,
+  G extends _GettersTree<S>,
   A,
   T extends Record<
     string,
@@ -194,7 +194,7 @@ export type _MapStateObjectReturn<
 export function mapState<
   Id extends string,
   S extends StateTree,
-  G extends GettersTree<S>,
+  G extends _GettersTree<S>,
   A,
   KeyMapper extends Record<
     string,
@@ -231,7 +231,7 @@ export function mapState<
 export function mapState<
   Id extends string,
   S extends StateTree,
-  G extends GettersTree<S>,
+  G extends _GettersTree<S>,
   A,
   Keys extends keyof S | keyof G
 >(
@@ -250,7 +250,7 @@ export function mapState<
 export function mapState<
   Id extends string,
   S extends StateTree,
-  G extends GettersTree<S>,
+  G extends _GettersTree<S>,
   A
 >(
   useStore: StoreDefinition<Id, S, G, A>,
@@ -326,7 +326,7 @@ export type _MapActionsObjectReturn<A, T extends Record<string, keyof 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>
 >(
@@ -359,7 +359,7 @@ export function mapActions<
 export function mapActions<
   Id extends string,
   S extends StateTree,
-  G extends GettersTree<S>,
+  G extends _GettersTree<S>,
   A
 >(
   useStore: StoreDefinition<Id, S, G, A>,
@@ -376,7 +376,7 @@ export function mapActions<
 export function mapActions<
   Id extends string,
   S extends StateTree,
-  G extends GettersTree<S>,
+  G extends _GettersTree<S>,
   A,
   KeyMapper extends Record<string, keyof A>
 >(
@@ -440,7 +440,7 @@ export type _MapWritableStateObjectReturn<
 export function mapWritableState<
   Id extends string,
   S extends StateTree,
-  G extends GettersTree<S>,
+  G extends _GettersTree<S>,
   A,
   KeyMapper extends Record<string, keyof S>
 >(
@@ -458,7 +458,7 @@ export function mapWritableState<
 export function mapWritableState<
   Id extends string,
   S extends StateTree,
-  G extends GettersTree<S>,
+  G extends _GettersTree<S>,
   A
 >(
   useStore: StoreDefinition<Id, S, G, A>,
@@ -475,7 +475,7 @@ export function mapWritableState<
 export function mapWritableState<
   Id extends string,
   S extends StateTree,
-  G extends GettersTree<S>,
+  G extends _GettersTree<S>,
   A,
   KeyMapper extends Record<string, keyof S>
 >(
index 8181e234cb9c3dfdde4e3d9534d19e3a4643f065..2713f4cc7de69b29bb2c794fe1b97995f3677437 100644 (file)
@@ -12,8 +12,8 @@ import {
   PiniaCustomProperties,
   _Method,
   Store,
-  GettersTree,
-  ActionsTree,
+  _GettersTree,
+  _ActionsTree,
   PiniaCustomStateProperties,
   DefineStoreOptionsInPlugin,
   StoreGeneric,
@@ -104,8 +104,8 @@ export const piniaSymbol = (
 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.
index 0a31d46c39f7363bd6012f9af642b0e10345b2e4..61e0a9c5a2f3356086b943599a1e53440a419f33 100644 (file)
@@ -30,19 +30,19 @@ import {
   _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'
@@ -83,8 +83,8 @@ function isComputed(o: any): o is ComputedRef {
 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>,
@@ -157,7 +157,7 @@ function createSetupStore<
   SS,
   S extends StateTree,
   G extends Record<string, _Method>,
-  A extends ActionsTree
+  A extends _ActionsTree
 >(
   $id: Id,
   setup: () => SS,
@@ -401,7 +401,7 @@ function createSetupStore<
       return removeSubscription
     },
     $dispose,
-  } as StoreWithState<Id, S, G, A>
+  } as _StoreWithState<Id, S, G, A>
 
   if (isVue2) {
     // start as non ready
@@ -701,7 +701,7 @@ function createSetupStore<
 export type StoreActions<SS> = SS extends Store<
   string,
   StateTree,
-  GettersTree<StateTree>,
+  _GettersTree<StateTree>,
   infer A
 >
   ? A
@@ -715,9 +715,9 @@ export type StoreGetters<SS> = SS extends Store<
   string,
   StateTree,
   infer G,
-  ActionsTree
+  _ActionsTree
 >
-  ? StoreWithGetters<G>
+  ? _StoreWithGetters<G>
   : _ExtractGettersFromSetupStore<SS>
 
 /**
@@ -727,8 +727,8 @@ export type StoreGetters<SS> = SS extends Store<
 export type StoreState<SS> = SS extends Store<
   string,
   infer S,
-  GettersTree<StateTree>,
-  ActionsTree
+  _GettersTree<StateTree>,
+  _ActionsTree
 >
   ? UnwrapRef<S>
   : _ExtractStateFromSetupStore<SS>
@@ -750,7 +750,7 @@ export type StoreState<SS> = SS extends Store<
 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 */ = {}
 >(
@@ -766,7 +766,7 @@ export function defineStore<
 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>
@@ -801,12 +801,17 @@ export function defineStore(
 ): 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'
index 893eb9239f19b9915236876177adc763783d5a08..c0b03a07e944e006c0565a559b5231be3387e2e2 100644 (file)
@@ -67,9 +67,7 @@ export enum MutationType {
 }
 
 /**
- * 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 {
   /**
@@ -163,7 +161,11 @@ export type SubscriptionCallback<S> = (
   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
    */
@@ -214,8 +216,8 @@ export type StoreOnActionListenerContext<
   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>
@@ -236,7 +238,7 @@ export type StoreOnActionListener<
     S,
     G,
     // {} creates a type of never due to how StoreOnActionListenerContext is defined
-    {} extends A ? ActionsTree : A
+    {} extends A ? _ActionsTree : A
   >
 ) => void
 
@@ -295,16 +297,15 @@ export interface StoreProperties<Id extends string> {
   _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> */,
@@ -445,29 +446,27 @@ export type _Method = (...args: any[]) => any
 
 // 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,
@@ -475,11 +474,11 @@ export type Store<
   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>
 
@@ -491,8 +490,8 @@ export type Store<
 export type StoreGeneric = Store<
   string,
   StateTree,
-  GettersTree<StateTree>,
-  ActionsTree
+  _GettersTree<StateTree>,
+  _ActionsTree
 >
 
 /**
@@ -504,12 +503,12 @@ export type StoreGeneric = Store<
 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>
@@ -520,8 +519,8 @@ export type GenericStore<
 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.
@@ -545,13 +544,13 @@ export interface StoreDefinition<
 }
 
 /**
- * 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
 > {}
 
 /**
@@ -560,22 +559,20 @@ export interface PiniaCustomProperties<
 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
@@ -647,8 +644,8 @@ export interface DefineStoreOptions<
    * 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.
@@ -657,8 +654,8 @@ export interface DefineStoreOptions<
     ThisType<
       A &
         UnwrapRef<S> &
-        StoreWithState<Id, S, G, A> &
-        StoreWithGetters<G> &
+        _StoreWithState<Id, S, G, A> &
+        _StoreWithGetters<G> &
         PiniaCustomProperties
     >
 }