1
1
---
2
- title : Flux Actions
2
+ title : Actions communicate UI events to store updates
3
3
sidebar_label : Actions
4
4
---
5
5
6
+ import Grid from '@site/src /components/Grid';
7
+
6
8
# Actions
7
9
8
- Actions are minimal descriptions of something that happened in the application .
10
+ Actions are minimal descriptions of store updates .
9
11
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.
11
16
12
17
Many actions use the same meta information:
13
18
@@ -21,6 +26,8 @@ interface ActionMeta {
21
26
22
27
## FETCH
23
28
29
+ <Grid wrap >
30
+
24
31
``` ts
25
32
interface FetchMeta {
26
33
fetchedAt: number ;
@@ -38,11 +45,36 @@ interface FetchAction {
38
45
}
39
46
```
40
47
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 ) ,
42
70
[ useSuspense()] ( ./useSuspense.md ) , [ useDLE()] ( ./useDLE.md ) , [ useLive()] ( ./useLive.md ) , [ useFetch()] ( ./useFetch.md )
43
71
72
+ Read by [ NetworkManager] ( ./NetworkManager.md )
73
+
44
74
## SET
45
75
76
+ <Grid wrap >
77
+
46
78
``` ts
47
79
interface SetAction {
48
80
type: typeof actionTypes .SET ;
@@ -53,10 +85,37 @@ interface SetAction {
53
85
}
54
86
```
55
87
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 )
57
114
58
115
## SET_RESPONSE
59
116
117
+ <Grid wrap >
118
+
60
119
``` ts
61
120
interface SetResponseAction {
62
121
type: typeof actionTypes .SET_RESPONSE ;
@@ -69,21 +128,68 @@ interface SetResponseAction {
69
128
}
70
129
```
71
130
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 )
73
164
74
165
## RESET
75
166
167
+ <Grid wrap >
168
+
76
169
``` ts
77
170
interface ResetAction {
78
171
type: typeof actionTypes .RESET ;
79
172
date: number ;
80
173
}
81
174
```
82
175
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 )
84
188
85
189
## SUBSCRIBE
86
190
191
+ <Grid wrap >
192
+
87
193
``` ts
88
194
interface SubscribeAction {
89
195
type: typeof actionTypes .SUBSCRIBE ;
@@ -93,10 +199,29 @@ interface SubscribeAction {
93
199
}
94
200
```
95
201
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 )
97
220
98
221
## UNSUBSCRIBE
99
222
223
+ <Grid wrap >
224
+
100
225
``` ts
101
226
interface UnsubscribeAction {
102
227
type: typeof actionTypes .UNSUBSCRIBE ;
@@ -106,38 +231,88 @@ interface UnsubscribeAction {
106
231
}
107
232
```
108
233
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 )
110
252
111
253
## INVALIDATE
112
254
255
+ <Grid wrap >
256
+
113
257
``` ts
114
258
interface InvalidateAction {
115
259
type: typeof actionTypes .INVALIDATE ;
116
260
key: string ;
117
261
}
118
262
```
119
263
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 )
121
274
122
275
## INVALIDATEALL
123
276
277
+ <Grid wrap >
278
+
124
279
``` ts
125
280
interface InvalidateAllAction {
126
281
type: typeof actionTypes .INVALIDATEALL ;
127
282
testKey: (key : string ) => boolean ;
128
283
}
129
284
```
130
285
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 )
132
296
133
297
## EXPIREALL
134
298
299
+ <Grid wrap >
300
+
135
301
``` ts
136
302
interface ExpireAllAction {
137
303
type: typeof actionTypes .EXPIREALL ;
138
304
testKey: (key : string ) => boolean ;
139
305
}
140
306
```
141
307
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 )
143
318
0 commit comments