]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(types): export used types
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 31 Dec 2020 14:45:16 +0000 (15:45 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 31 Dec 2020 14:45:16 +0000 (15:45 +0100)
Close #315

src/deprecated.ts
src/index.ts
src/rootStore.ts
src/types.ts

index 06791aafd4cd55152db354fe32e054427d7bd43b..1d08727c6389c38dcf26a8cd9af3c3a27473dc4d 100644 (file)
@@ -1,5 +1,9 @@
 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.'
index 2a82b6010a124fdc8613b8d16289f7374411e37f..7b86b398114ff762bc89e5f85dc4d54d3dd57345 100644 (file)
@@ -6,4 +6,11 @@ export {
   Pinia,
 } from './rootStore'
 export { defineStore } from './store'
+export {
+  StateTree,
+  Store,
+  StoreWithGetters,
+  StoreWithActions,
+  StoreWithState,
+} from './types'
 export { createStore } from './deprecated'
index fc20db7fcdcb6dd4d46a7cc261770cc5e9cd9e60..6b85bd54561cf51e942ada71b627360d65b1a095 100644 (file)
@@ -12,9 +12,19 @@ import {
  * `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(
@@ -76,6 +86,9 @@ export let clientApp: App | undefined
 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>
 
@@ -98,6 +111,9 @@ export const piniaSymbol = (__DEV__
   ? Symbol('pinia')
   : Symbol()) as InjectionKey<Pinia>
 
+/**
+ * Creates a Pinia instance to be used by the application
+ */
 export function createPinia(): Pinia {
   const state = ref({})
 
index a8a418edac467931f21b55a13f8ad4f4b94720a2..eee9dd3a3deedd3c44b85c56a899b4bac11badb4 100644 (file)
@@ -1,6 +1,9 @@
 import { Ref } from 'vue'
 import { Pinia } from './rootStore'
 
+/**
+ * Generic state of a Store
+ */
 export type StateTree = Record<string | number | symbol, any>
 
 /**
@@ -23,6 +26,10 @@ export function isPlainObject(
   )
 }
 
+/**
+ * Store Getter
+ * @internal
+ */
 export interface StoreGetter<S extends StateTree, T = any> {
   (state: S, getters: Record<string, Ref<any>>): T
 }
@@ -35,6 +42,10 @@ export type SubscriptionCallback<S> = (
   state: S
 ) => void
 
+/**
+ * Base store with state and functions
+ * @internal
+ */
 export interface StoreWithState<Id extends string, S extends StateTree> {
   /**
    * Unique identifier of the store
@@ -83,6 +94,10 @@ export type Method = (...args: any[]) => any
 // }
 
 // 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
@@ -94,6 +109,10 @@ export type StoreWithActions<A> = {
 //   (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
@@ -109,6 +128,9 @@ export type StoreWithGetters<G> = {
 // }
 
 // has the actions without the context (this) for typings
+/**
+ * Store type to build a store
+ */
 export type Store<
   Id extends string,
   S extends StateTree,
@@ -116,6 +138,9 @@ export type Store<
   A
 > = StoreWithState<Id, S> & S & StoreWithGetters<G> & StoreWithActions<A>
 
+/**
+ * Generic store type
+ */
 export type GenericStore = Store<
   string,
   StateTree,