From: Eduardo San Martin Morote Date: Mon, 5 Feb 2024 10:09:24 +0000 (+0100) Subject: docs: updates X-Git-Tag: @pinia/nuxt@0.5.2-beta.0~55 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=623b59c1a2be7380600cbf00560f2e8e5e6b92fd;p=thirdparty%2Fvuejs%2Fpinia.git docs: updates --- diff --git a/packages/docs/api/interfaces/pinia.DefineStoreOptions.md b/packages/docs/api/interfaces/pinia.DefineStoreOptions.md index 5a491331..8c769ec1 100644 --- a/packages/docs/api/interfaces/pinia.DefineStoreOptions.md +++ b/packages/docs/api/interfaces/pinia.DefineStoreOptions.md @@ -60,6 +60,9 @@ ___ • `Optional` **state**: () => `S` +Function to create a fresh state. **Must be an arrow function** to ensure +correct typings! + #### Type declaration ▸ (): `S` diff --git a/packages/docs/api/interfaces/pinia.DefineStoreOptionsInPlugin.md b/packages/docs/api/interfaces/pinia.DefineStoreOptionsInPlugin.md index bbc20a8b..c5634ecd 100644 --- a/packages/docs/api/interfaces/pinia.DefineStoreOptionsInPlugin.md +++ b/packages/docs/api/interfaces/pinia.DefineStoreOptionsInPlugin.md @@ -53,6 +53,9 @@ ___ • `Optional` **state**: () => `S` +Function to create a fresh state. **Must be an arrow function** to ensure +correct typings! + #### Type declaration ▸ (): `S` diff --git a/packages/docs/api/interfaces/pinia._StoreOnActionListenerContext.md b/packages/docs/api/interfaces/pinia._StoreOnActionListenerContext.md index 4bdbf9f0..abd1608e 100644 --- a/packages/docs/api/interfaces/pinia._StoreOnActionListenerContext.md +++ b/packages/docs/api/interfaces/pinia._StoreOnActionListenerContext.md @@ -26,6 +26,9 @@ For internal use **only** • **after**: (`callback`: `A` extends `Record`\<`ActionName`, [`_Method`](../modules/pinia.md#_Method)\> ? (`resolvedReturn`: [`_Awaited`](../modules/pinia.md#_Awaited)\<`ReturnType`\<`A`[`ActionName`]\>\>) => `void` : () => `void`) => `void` +Sets up a hook once the action is finished. It receives the return value +of the action, if it's a Promise, it will be unwrapped. + #### Type declaration ▸ (`callback`): `void` @@ -65,6 +68,9 @@ ___ • **onError**: (`callback`: (`error`: `unknown`) => `void`) => `void` +Sets up a hook if the action fails. Return `false` to catch the error and +stop it from propagating. + #### Type declaration ▸ (`callback`): `void` diff --git a/packages/docs/api/interfaces/pinia._StoreWithState.md b/packages/docs/api/interfaces/pinia._StoreWithState.md index c975e301..b2854780 100644 --- a/packages/docs/api/interfaces/pinia._StoreWithState.md +++ b/packages/docs/api/interfaces/pinia._StoreWithState.md @@ -111,43 +111,10 @@ function that removes the watcher ▸ (): `void` -Setups a callback to be called every time an action is about to get -invoked. The callback receives an object with all the relevant information -of the invoked action: -- `store`: the store it is invoked on -- `name`: The name of the action -- `args`: The parameters passed to the action - -On top of these, it receives two functions that allow setting up a callback -once the action finishes or when it fails. - -It also returns a function to remove the callback. Note than when calling -`store.$onAction()` inside of a component, it will be automatically cleaned -up when the component gets unmounted unless `detached` is set to true. - ##### Returns `void` -function that removes the watcher - -**`Example`** - -```js -store.$onAction(({ after, onError }) => { - // Here you could share variables between all of the hooks as well as - // setting up watchers and clean them up - after((resolvedValue) => { - // can be used to cleanup side effects -. // `resolvedValue` is the value returned by the action, if it's a -. // Promise, it will be the resolved value instead of the Promise - }) - onError((error) => { - // can be used to pass up errors - }) -}) -``` - **`Example`** ```js @@ -242,12 +209,6 @@ function that removes the watcher ▸ (): `void` -Setups a callback to be called whenever the state changes. It also returns a function to remove the callback. Note -that when calling `store.$subscribe()` inside of a component, it will be automatically cleaned up when the -component gets unmounted unless `detached` is set to true. - ##### Returns `void` - -function that removes the watcher diff --git a/packages/docs/api/interfaces/pinia_testing.TestingOptions.md b/packages/docs/api/interfaces/pinia_testing.TestingOptions.md index 7ae2abcb..6b18f139 100644 --- a/packages/docs/api/interfaces/pinia_testing.TestingOptions.md +++ b/packages/docs/api/interfaces/pinia_testing.TestingOptions.md @@ -14,6 +14,10 @@ editLink: false • `Optional` **createSpy**: (`fn?`: (...`args`: `any`[]) => `any`) => (...`args`: `any`[]) => `any` +Function used to create a spy for actions and `$patch()`. Pre-configured +with `jest.fn` in Jest projects or `vi.fn` in Vitest projects if +`globals: true` is set. + #### Type declaration ▸ (`fn?`): (...`args`: `any`[]) => `any` diff --git a/packages/docs/api/modules/pinia.md b/packages/docs/api/modules/pinia.md index 959db867..0cb48eda 100644 --- a/packages/docs/api/modules/pinia.md +++ b/packages/docs/api/modules/pinia.md @@ -115,6 +115,8 @@ ___ Ƭ **StoreOnActionListener**\<`Id`, `S`, `G`, `A`\>: (`context`: [`StoreOnActionListenerContext`](pinia.md#StoreOnActionListenerContext)\<`Id`, `S`, `G`, {} extends `A` ? [`_ActionsTree`](pinia.md#_ActionsTree) : `A`\>) => `void` +Argument of `store.$onAction()` + #### Type parameters | Name | Type | @@ -128,8 +130,6 @@ ___ ▸ (`context`): `void` -Argument of `store.$onAction()` - ##### Parameters | Name | Type | @@ -179,6 +179,8 @@ ___ Ƭ **SubscriptionCallback**\<`S`\>: (`mutation`: [`SubscriptionCallbackMutation`](pinia.md#SubscriptionCallbackMutation)\<`S`\>, `state`: `UnwrapRef`\<`S`\>) => `void` +Callback of a subscription + #### Type parameters | Name | @@ -189,8 +191,6 @@ ___ ▸ (`mutation`, `state`): `void` -Callback of a subscription - ##### Parameters | Name | Type | @@ -453,14 +453,14 @@ ___ Ƭ **\_Method**: (...`args`: `any`[]) => `any` -#### Type declaration - -▸ (`...args`): `any` - Generic type for a function that can infer arguments and return type For internal use **only** +#### Type declaration + +▸ (`...args`): `any` + ##### Parameters | Name | Type |