11---
2- title : Flux Actions
2+ title : Actions communicate UI events to store updates
33sidebar_label : Actions
44---
55
6+ import Grid from '@site/src /components/Grid';
7+
68# Actions
79
8- Actions are minimal descriptions of something that happened in the application .
10+ Actions are minimal descriptions of store updates .
911
10- They can be [ read and consumed by Manager middleware] ( ./Manager.md#reading-and-consuming-actions ) .
12+ They are [ dispatched by Controller methods] ( ./Controller.md#action-dispatchers ) ->
13+ [ read and consumed by Manager middleware] ( ./Manager.md#reading-and-consuming-actions ) ->
14+ processed by [ reducers] ( https://react.dev/reference/react/useReducer ) registered with [ DataProvider] ( ./DataProvider.md )
15+ to update the store's state.
1116
1217Many actions use the same meta information:
1318
@@ -21,6 +26,8 @@ interface ActionMeta {
2126
2227## FETCH
2328
29+ <Grid wrap >
30+
2431``` ts
2532interface FetchMeta {
2633 fetchedAt: number ;
@@ -38,11 +45,36 @@ interface FetchAction {
3845}
3946```
4047
41- Comes from [ Controller.fetch()] ( ./Controller.md#fetch ) , [ Controller.fetchIfStale()] ( ./Controller.md#fetchIfStale ) ,
48+ ``` js
49+ {
50+ type: ' rdc/fetch' ,
51+ key: ' GET https://jsonplaceholder.typicode.com/todos?userId=1' ,
52+ args: [
53+ {
54+ userId: 1
55+ }
56+ ],
57+ endpoint: Endpoint (' User.getList' ),
58+ meta: {
59+ fetchedAt: ' 5:09:41.975 PM' ,
60+ resolve : function (){},
61+ reject : function (){},
62+ promise: {}
63+ }
64+ }
65+ ```
66+
67+ </Grid >
68+
69+ Sent by [ Controller.fetch()] ( ./Controller.md#fetch ) , [ Controller.fetchIfStale()] ( ./Controller.md#fetchIfStale ) ,
4270[ useSuspense()] ( ./useSuspense.md ) , [ useDLE()] ( ./useDLE.md ) , [ useLive()] ( ./useLive.md ) , [ useFetch()] ( ./useFetch.md )
4371
72+ Read by [ NetworkManager] ( ./NetworkManager.md )
73+
4474## SET
4575
76+ <Grid wrap >
77+
4678``` ts
4779interface SetAction {
4880 type: typeof actionTypes .SET ;
@@ -53,10 +85,37 @@ interface SetAction {
5385}
5486```
5587
56- Comes from [ Controller.set()] ( ./Controller.md#set )
88+ ``` js
89+ {
90+ type: ' rdc/set' ,
91+ value: {
92+ userId: 1 ,
93+ id: 1 ,
94+ title: ' delectus aut autem' ,
95+ completed: true
96+ },
97+ args: [
98+ {
99+ id: 1
100+ }
101+ ],
102+ schema: Todo,
103+ meta: {
104+ fetchedAt: ' 5:18:26.394 PM' ,
105+ date: ' 5:18:26.636 PM' ,
106+ expiresAt: ' 6:18:26.636 PM'
107+ }
108+ }
109+ ```
110+
111+ </Grid >
112+
113+ Sent by [ Controller.set()] ( ./Controller.md#set )
57114
58115## SET_RESPONSE
59116
117+ <Grid wrap >
118+
60119``` ts
61120interface SetResponseAction {
62121 type: typeof actionTypes .SET_RESPONSE ;
@@ -69,21 +128,68 @@ interface SetResponseAction {
69128}
70129```
71130
72- Comes from [ Controller.setResponse()] ( ./Controller.md#setResponse ) , [ NetworkManager] ( ./NetworkManager.md )
131+ ``` js
132+ {
133+ type: ' rdc/setresponse' ,
134+ key: ' PATCH https://jsonplaceholder.typicode.com/todos/1' ,
135+ response: {
136+ userId: 1 ,
137+ id: 1 ,
138+ title: ' delectus aut autem' ,
139+ completed: true
140+ },
141+ args: [
142+ {
143+ id: 1
144+ },
145+ {
146+ completed: true
147+ }
148+ ],
149+ endpoint: Endpont (' Todo.partialUpdate' ),
150+ meta: {
151+ fetchedAt: ' 5:18:26.394 PM' ,
152+ date: ' 5:18:26.636 PM' ,
153+ expiresAt: ' 6:18:26.636 PM'
154+ },
155+ error: false
156+ }
157+ ```
158+
159+ </Grid >
160+
161+ Sent by [ Controller.setResponse()] ( ./Controller.md#setResponse ) , [ NetworkManager] ( ./NetworkManager.md )
162+
163+ Read by [ NetworkManager] ( ./NetworkManager.md ) , [ LogoutManager] ( ./LogoutManager.md )
73164
74165## RESET
75166
167+ <Grid wrap >
168+
76169``` ts
77170interface ResetAction {
78171 type: typeof actionTypes .RESET ;
79172 date: number ;
80173}
81174```
82175
83- Comes from [ Controller.resetEntireStore()] ( ./Controller.md#resetEntireStore )
176+ ``` js
177+ {
178+ type: ' rdc/reset' ,
179+ date: ' 5:09:41.975 PM' ,
180+ }
181+ ```
182+
183+ </Grid >
184+
185+ Sent by [ Controller.resetEntireStore()] ( ./Controller.md#resetEntireStore )
186+
187+ Read by [ NetworkManager] ( ./NetworkManager.md )
84188
85189## SUBSCRIBE
86190
191+ <Grid wrap >
192+
87193``` ts
88194interface SubscribeAction {
89195 type: typeof actionTypes .SUBSCRIBE ;
@@ -93,10 +199,29 @@ interface SubscribeAction {
93199}
94200```
95201
96- Comes from [ Controller.subscribe()] ( ./Controller.md#subscribe ) , [ useSubscription()] ( ./useSubscription.md ) , [ useLive()] ( ./useLive.md )
202+ ``` js
203+ {
204+ type: ' rdc/subscribe' ,
205+ key: ' GET https://api.exchange.coinbase.com/products/BTC-USD/ticker' ,
206+ args: [
207+ {
208+ product_id: ' BTC-USD'
209+ }
210+ ],
211+ endpoint: Endpoint (' https://api.exchange.coinbase.com/products/:product_id/ticker' ),
212+ }
213+ ```
214+
215+ </Grid >
216+
217+ Sent by [ Controller.subscribe()] ( ./Controller.md#subscribe ) , [ useSubscription()] ( ./useSubscription.md ) , [ useLive()] ( ./useLive.md )
218+
219+ Read by [ SubscriptionManager] ( ./SubscriptionManager.md )
97220
98221## UNSUBSCRIBE
99222
223+ <Grid wrap >
224+
100225``` ts
101226interface UnsubscribeAction {
102227 type: typeof actionTypes .UNSUBSCRIBE ;
@@ -106,38 +231,88 @@ interface UnsubscribeAction {
106231}
107232```
108233
109- Comes from [ Controller.unsubscribe()] ( ./Controller.md#unsubscribe ) , [ useSubscription()] ( ./useSubscription.md ) , [ useLive()] ( ./useLive.md )
234+ ``` js
235+ {
236+ type: ' rdc/unsubscribe' ,
237+ key: ' GET https://api.exchange.coinbase.com/products/BTC-USD/ticker' ,
238+ args: [
239+ {
240+ product_id: ' BTC-USD'
241+ }
242+ ],
243+ endpoint: Endpoint (' https://api.exchange.coinbase.com/products/:product_id/ticker' ),
244+ }
245+ ```
246+
247+ </Grid >
248+
249+ Sent by [ Controller.unsubscribe()] ( ./Controller.md#unsubscribe ) , [ useSubscription()] ( ./useSubscription.md ) , [ useLive()] ( ./useLive.md )
250+
251+ Read by [ SubscriptionManager] ( ./SubscriptionManager.md )
110252
111253## INVALIDATE
112254
255+ <Grid wrap >
256+
113257``` ts
114258interface InvalidateAction {
115259 type: typeof actionTypes .INVALIDATE ;
116260 key: string ;
117261}
118262```
119263
120- Comes from [ Controller.invalidate()] ( ./Controller.md#invalidate )
264+ ``` js
265+ {
266+ type: ' rdc/invalidate' ,
267+ key: ' GET https://jsonplaceholder.typicode.com/todos?userId=1' ,
268+ }
269+ ```
270+
271+ </Grid >
272+
273+ Sent by [ Controller.invalidate()] ( ./Controller.md#invalidate )
121274
122275## INVALIDATEALL
123276
277+ <Grid wrap >
278+
124279``` ts
125280interface InvalidateAllAction {
126281 type: typeof actionTypes .INVALIDATEALL ;
127282 testKey: (key : string ) => boolean ;
128283}
129284```
130285
131- Comes from [ Controller.invalidateAll()] ( ./Controller.md#invalidateAll )
286+ ``` js
287+ {
288+ type: ' rdc/invalidateall' ,
289+ testKey: Endpoint (' User.getList' ),
290+ }
291+ ```
292+
293+ </Grid >
294+
295+ Sent by [ Controller.invalidateAll()] ( ./Controller.md#invalidateAll )
132296
133297## EXPIREALL
134298
299+ <Grid wrap >
300+
135301``` ts
136302interface ExpireAllAction {
137303 type: typeof actionTypes .EXPIREALL ;
138304 testKey: (key : string ) => boolean ;
139305}
140306```
141307
142- Comes from [ Controller.expireAll()] ( ./Controller.md#expireAll )
308+ ``` js
309+ {
310+ type: ' rdc/expireall' ,
311+ testKey: Endpoint (' User.getList' ),
312+ }
313+ ```
314+
315+ </Grid >
316+
317+ Sent by [ Controller.expireAll()] ( ./Controller.md#expireAll )
143318
0 commit comments