From 0c39da0cf2d9ec7678c7b0b4567fb950e45a91cd Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Sun, 22 Dec 2024 11:08:53 +0000 Subject: [PATCH] docs: Add Action examples --- docs/core/api/Actions.md | 199 +++++++++++++++++++++++++++++++++--- docs/core/api/Controller.md | 2 +- docs/core/api/Snapshot.md | 2 +- 3 files changed, 189 insertions(+), 14 deletions(-) diff --git a/docs/core/api/Actions.md b/docs/core/api/Actions.md index cbd936ed0f5e..5b10cdca1332 100644 --- a/docs/core/api/Actions.md +++ b/docs/core/api/Actions.md @@ -1,13 +1,18 @@ --- -title: Flux Actions +title: Actions communicate UI events to store updates sidebar_label: Actions --- +import Grid from '@site/src/components/Grid'; + # Actions -Actions are minimal descriptions of something that happened in the application. +Actions are minimal descriptions of store updates. -They can be [read and consumed by Manager middleware](./Manager.md#reading-and-consuming-actions). +They are [dispatched by Controller methods](./Controller.md#action-dispatchers) -> +[read and consumed by Manager middleware](./Manager.md#reading-and-consuming-actions) -> +processed by [reducers](https://react.dev/reference/react/useReducer) registered with [DataProvider](./DataProvider.md) +to update the store's state. Many actions use the same meta information: @@ -21,6 +26,8 @@ interface ActionMeta { ## FETCH + + ```ts interface FetchMeta { fetchedAt: number; @@ -38,11 +45,36 @@ interface FetchAction { } ``` -Comes from [Controller.fetch()](./Controller.md#fetch), [Controller.fetchIfStale()](./Controller.md#fetchIfStale), +```js +{ + type: 'rdc/fetch', + key: 'GET https://jsonplaceholder.typicode.com/todos?userId=1', + args: [ + { + userId: 1 + } + ], + endpoint: Endpoint('User.getList'), + meta: { + fetchedAt: '5:09:41.975 PM', + resolve: function (){}, + reject: function (){}, + promise: {} + } +} +``` + + + +Sent by [Controller.fetch()](./Controller.md#fetch), [Controller.fetchIfStale()](./Controller.md#fetchIfStale), [useSuspense()](./useSuspense.md), [useDLE()](./useDLE.md), [useLive()](./useLive.md), [useFetch()](./useFetch.md) +Read by [NetworkManager](./NetworkManager.md) + ## SET + + ```ts interface SetAction { type: typeof actionTypes.SET; @@ -53,10 +85,37 @@ interface SetAction { } ``` -Comes from [Controller.set()](./Controller.md#set) +```js +{ + type: 'rdc/set', + value: { + userId: 1, + id: 1, + title: 'delectus aut autem', + completed: true + }, + args: [ + { + id: 1 + } + ], + schema: Todo, + meta: { + fetchedAt: '5:18:26.394 PM', + date: '5:18:26.636 PM', + expiresAt: '6:18:26.636 PM' + } +} +``` + + + +Sent by [Controller.set()](./Controller.md#set) ## SET_RESPONSE + + ```ts interface SetResponseAction { type: typeof actionTypes.SET_RESPONSE; @@ -69,10 +128,44 @@ interface SetResponseAction { } ``` -Comes from [Controller.setResponse()](./Controller.md#setResponse), [NetworkManager](./NetworkManager.md) +```js +{ + type: 'rdc/setresponse', + key: 'PATCH https://jsonplaceholder.typicode.com/todos/1', + response: { + userId: 1, + id: 1, + title: 'delectus aut autem', + completed: true + }, + args: [ + { + id: 1 + }, + { + completed: true + } + ], + endpoint: Endpont('Todo.partialUpdate'), + meta: { + fetchedAt: '5:18:26.394 PM', + date: '5:18:26.636 PM', + expiresAt: '6:18:26.636 PM' + }, + error: false +} +``` + + + +Sent by [Controller.setResponse()](./Controller.md#setResponse), [NetworkManager](./NetworkManager.md) + +Read by [NetworkManager](./NetworkManager.md), [LogoutManager](./LogoutManager.md) ## RESET + + ```ts interface ResetAction { type: typeof actionTypes.RESET; @@ -80,10 +173,23 @@ interface ResetAction { } ``` -Comes from [Controller.resetEntireStore()](./Controller.md#resetEntireStore) +```js +{ + type: 'rdc/reset', + date: '5:09:41.975 PM', +} +``` + + + +Sent by [Controller.resetEntireStore()](./Controller.md#resetEntireStore) + +Read by [NetworkManager](./NetworkManager.md) ## SUBSCRIBE + + ```ts interface SubscribeAction { type: typeof actionTypes.SUBSCRIBE; @@ -93,10 +199,29 @@ interface SubscribeAction { } ``` -Comes from [Controller.subscribe()](./Controller.md#subscribe), [useSubscription()](./useSubscription.md), [useLive()](./useLive.md) +```js +{ + type: 'rdc/subscribe', + key: 'GET https://api.exchange.coinbase.com/products/BTC-USD/ticker', + args: [ + { + product_id: 'BTC-USD' + } + ], + endpoint: Endpoint('https://api.exchange.coinbase.com/products/:product_id/ticker'), +} +``` + + + +Sent by [Controller.subscribe()](./Controller.md#subscribe), [useSubscription()](./useSubscription.md), [useLive()](./useLive.md) + +Read by [SubscriptionManager](./SubscriptionManager.md) ## UNSUBSCRIBE + + ```ts interface UnsubscribeAction { type: typeof actionTypes.UNSUBSCRIBE; @@ -106,10 +231,29 @@ interface UnsubscribeAction { } ``` -Comes from [Controller.unsubscribe()](./Controller.md#unsubscribe), [useSubscription()](./useSubscription.md), [useLive()](./useLive.md) +```js +{ + type: 'rdc/unsubscribe', + key: 'GET https://api.exchange.coinbase.com/products/BTC-USD/ticker', + args: [ + { + product_id: 'BTC-USD' + } + ], + endpoint: Endpoint('https://api.exchange.coinbase.com/products/:product_id/ticker'), +} +``` + + + +Sent by [Controller.unsubscribe()](./Controller.md#unsubscribe), [useSubscription()](./useSubscription.md), [useLive()](./useLive.md) + +Read by [SubscriptionManager](./SubscriptionManager.md) ## INVALIDATE + + ```ts interface InvalidateAction { type: typeof actionTypes.INVALIDATE; @@ -117,10 +261,21 @@ interface InvalidateAction { } ``` -Comes from [Controller.invalidate()](./Controller.md#invalidate) +```js +{ + type: 'rdc/invalidate', + key: 'GET https://jsonplaceholder.typicode.com/todos?userId=1', +} +``` + + + +Sent by [Controller.invalidate()](./Controller.md#invalidate) ## INVALIDATEALL + + ```ts interface InvalidateAllAction { type: typeof actionTypes.INVALIDATEALL; @@ -128,10 +283,21 @@ interface InvalidateAllAction { } ``` -Comes from [Controller.invalidateAll()](./Controller.md#invalidateAll) +```js +{ + type: 'rdc/invalidateall', + testKey: Endpoint('User.getList'), +} +``` + + + +Sent by [Controller.invalidateAll()](./Controller.md#invalidateAll) ## EXPIREALL + + ```ts interface ExpireAllAction { type: typeof actionTypes.EXPIREALL; @@ -139,5 +305,14 @@ interface ExpireAllAction { } ``` -Comes from [Controller.expireAll()](./Controller.md#expireAll) +```js +{ + type: 'rdc/expireall', + testKey: Endpoint('User.getList'), +} +``` + + + +Sent by [Controller.expireAll()](./Controller.md#expireAll) diff --git a/docs/core/api/Controller.md b/docs/core/api/Controller.md index 3076f5636f74..0a4f333d247b 100644 --- a/docs/core/api/Controller.md +++ b/docs/core/api/Controller.md @@ -497,7 +497,7 @@ Gets the (globally referentially stable) response for a given endpoint/args pair The denormalize response data. Guarantees global referential stability for all members. -#### expiryStatus +#### [expiryStatus](../concepts/expiry-policy.md#expiry-status) ```ts export enum ExpiryStatus { diff --git a/docs/core/api/Snapshot.md b/docs/core/api/Snapshot.md index ff294d5e2a5a..07138eef574e 100644 --- a/docs/core/api/Snapshot.md +++ b/docs/core/api/Snapshot.md @@ -57,7 +57,7 @@ Gets the (globally referentially stable) response for a given endpoint/args pair The denormalize response data. Guarantees global referential stability for all members. -#### expiryStatus +#### [expiryStatus](../concepts/expiry-policy.md#expiry-status) ```ts export enum ExpiryStatus {