kiss-for-react 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +699 -156
- package/lib/cjs/ClassPersistor.js +177 -112
- package/lib/cjs/Esserializer/DeserializationOptions.js +4 -4
- package/lib/cjs/Esserializer/SerializeOptions.js +4 -4
- package/lib/cjs/Esserializer/builtins.js +258 -0
- package/lib/cjs/Esserializer/constant.js +39 -131
- package/lib/cjs/Esserializer/deserializer.js +293 -313
- package/lib/cjs/Esserializer/general.js +91 -39
- package/lib/cjs/Esserializer/index.js +47 -43
- package/lib/cjs/Esserializer/serializer.js +168 -133
- package/lib/cjs/Evt.js +132 -0
- package/lib/cjs/Hooks.js +1474 -969
- package/lib/cjs/KissAction.js +4762 -1333
- package/lib/cjs/LoadPages.js +336 -0
- package/lib/cjs/Persistor.js +189 -120
- package/lib/cjs/ProcessPersistence.js +579 -262
- package/lib/cjs/Store.js +4342 -1534
- package/lib/cjs/StoreException.js +162 -75
- package/lib/cjs/StoreProvider.js +166 -0
- package/lib/cjs/UserException.js +212 -218
- package/lib/cjs/Wait.js +309 -309
- package/lib/cjs/index.js +69 -42
- package/lib/cjs/server.js +54 -0
- package/lib/cjs/types/ClassPersistor.d.ts +143 -112
- package/lib/cjs/types/ClassPersistor.d.ts.map +1 -1
- package/lib/cjs/types/Esserializer/DeserializationOptions.d.ts +13 -6
- package/lib/cjs/types/Esserializer/DeserializationOptions.d.ts.map +1 -1
- package/lib/cjs/types/Esserializer/SerializeOptions.d.ts +11 -5
- package/lib/cjs/types/Esserializer/SerializeOptions.d.ts.map +1 -1
- package/lib/cjs/types/Esserializer/builtins.d.ts +36 -0
- package/lib/cjs/types/Esserializer/builtins.d.ts.map +1 -0
- package/lib/cjs/types/Esserializer/constant.d.ts +25 -49
- package/lib/cjs/types/Esserializer/constant.d.ts.map +1 -1
- package/lib/cjs/types/Esserializer/deserializer.d.ts +27 -17
- package/lib/cjs/types/Esserializer/deserializer.d.ts.map +1 -1
- package/lib/cjs/types/Esserializer/general.d.ts +28 -4
- package/lib/cjs/types/Esserializer/general.d.ts.map +1 -1
- package/lib/cjs/types/Esserializer/index.d.ts +33 -29
- package/lib/cjs/types/Esserializer/index.d.ts.map +1 -1
- package/lib/cjs/types/Esserializer/serializer.d.ts +14 -3
- package/lib/cjs/types/Esserializer/serializer.d.ts.map +1 -1
- package/lib/cjs/types/Evt.d.ts +124 -0
- package/lib/cjs/types/Evt.d.ts.map +1 -0
- package/lib/cjs/types/Hooks.d.ts +1174 -837
- package/lib/cjs/types/Hooks.d.ts.map +1 -1
- package/lib/cjs/types/KissAction.d.ts +5257 -1398
- package/lib/cjs/types/KissAction.d.ts.map +1 -1
- package/lib/cjs/types/LoadPages.d.ts +287 -0
- package/lib/cjs/types/LoadPages.d.ts.map +1 -0
- package/lib/cjs/types/Persistor.d.ts +187 -118
- package/lib/cjs/types/Persistor.d.ts.map +1 -1
- package/lib/cjs/types/ProcessPersistence.d.ts +197 -99
- package/lib/cjs/types/ProcessPersistence.d.ts.map +1 -1
- package/lib/cjs/types/Store.d.ts +2266 -1042
- package/lib/cjs/types/Store.d.ts.map +1 -1
- package/lib/cjs/types/StoreException.d.ts +97 -28
- package/lib/cjs/types/StoreException.d.ts.map +1 -1
- package/lib/cjs/types/StoreProvider.d.ts +95 -0
- package/lib/cjs/types/StoreProvider.d.ts.map +1 -0
- package/lib/cjs/types/UserException.d.ts +178 -169
- package/lib/cjs/types/UserException.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +12 -9
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/server.d.ts +12 -0
- package/lib/cjs/types/server.d.ts.map +1 -0
- package/lib/cjs/types/utils.d.ts +15 -1
- package/lib/cjs/types/utils.d.ts.map +1 -1
- package/lib/cjs/utils.js +45 -7
- package/lib/esm/ClassPersistor.mjs +177 -0
- package/lib/esm/Esserializer/{DeserializationOptions.js → DeserializationOptions.mjs} +3 -3
- package/lib/esm/Esserializer/{SerializeOptions.js → SerializeOptions.mjs} +3 -3
- package/lib/esm/Esserializer/builtins.mjs +254 -0
- package/lib/esm/Esserializer/constant.mjs +28 -0
- package/lib/esm/Esserializer/deserializer.mjs +288 -0
- package/lib/esm/Esserializer/general.mjs +81 -0
- package/lib/esm/Esserializer/index.mjs +43 -0
- package/lib/esm/Esserializer/serializer.mjs +164 -0
- package/lib/esm/Evt.mjs +151 -0
- package/lib/esm/Hooks.mjs +1448 -0
- package/lib/esm/KissAction.mjs +4816 -0
- package/lib/esm/LoadPages.mjs +340 -0
- package/lib/esm/Persistor.mjs +180 -0
- package/lib/esm/ProcessPersistence.mjs +581 -0
- package/lib/esm/Store.mjs +4464 -0
- package/lib/esm/StoreException.mjs +153 -0
- package/lib/esm/StoreProvider.mjs +162 -0
- package/lib/esm/{UserException.js → UserException.mjs} +240 -246
- package/lib/esm/{Wait.js → Wait.mjs} +309 -309
- package/lib/esm/index.mjs +12 -9
- package/lib/esm/server.mjs +23 -0
- package/lib/esm/types/ClassPersistor.d.ts +143 -112
- package/lib/esm/types/ClassPersistor.d.ts.map +1 -1
- package/lib/esm/types/Esserializer/DeserializationOptions.d.ts +13 -6
- package/lib/esm/types/Esserializer/DeserializationOptions.d.ts.map +1 -1
- package/lib/esm/types/Esserializer/SerializeOptions.d.ts +11 -5
- package/lib/esm/types/Esserializer/SerializeOptions.d.ts.map +1 -1
- package/lib/esm/types/Esserializer/builtins.d.ts +36 -0
- package/lib/esm/types/Esserializer/builtins.d.ts.map +1 -0
- package/lib/esm/types/Esserializer/constant.d.ts +25 -49
- package/lib/esm/types/Esserializer/constant.d.ts.map +1 -1
- package/lib/esm/types/Esserializer/deserializer.d.ts +27 -17
- package/lib/esm/types/Esserializer/deserializer.d.ts.map +1 -1
- package/lib/esm/types/Esserializer/general.d.ts +28 -4
- package/lib/esm/types/Esserializer/general.d.ts.map +1 -1
- package/lib/esm/types/Esserializer/index.d.ts +33 -29
- package/lib/esm/types/Esserializer/index.d.ts.map +1 -1
- package/lib/esm/types/Esserializer/serializer.d.ts +14 -3
- package/lib/esm/types/Esserializer/serializer.d.ts.map +1 -1
- package/lib/esm/types/Evt.d.ts +124 -0
- package/lib/esm/types/Evt.d.ts.map +1 -0
- package/lib/esm/types/Hooks.d.ts +1174 -837
- package/lib/esm/types/Hooks.d.ts.map +1 -1
- package/lib/esm/types/KissAction.d.ts +5257 -1398
- package/lib/esm/types/KissAction.d.ts.map +1 -1
- package/lib/esm/types/LoadPages.d.ts +287 -0
- package/lib/esm/types/LoadPages.d.ts.map +1 -0
- package/lib/esm/types/Persistor.d.ts +187 -118
- package/lib/esm/types/Persistor.d.ts.map +1 -1
- package/lib/esm/types/ProcessPersistence.d.ts +197 -99
- package/lib/esm/types/ProcessPersistence.d.ts.map +1 -1
- package/lib/esm/types/Store.d.ts +2266 -1042
- package/lib/esm/types/Store.d.ts.map +1 -1
- package/lib/esm/types/StoreException.d.ts +97 -28
- package/lib/esm/types/StoreException.d.ts.map +1 -1
- package/lib/esm/types/StoreProvider.d.ts +95 -0
- package/lib/esm/types/StoreProvider.d.ts.map +1 -0
- package/lib/esm/types/UserException.d.ts +178 -169
- package/lib/esm/types/UserException.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +12 -9
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/server.d.ts +12 -0
- package/lib/esm/types/server.d.ts.map +1 -0
- package/lib/esm/types/utils.d.ts +15 -1
- package/lib/esm/types/utils.d.ts.map +1 -1
- package/lib/esm/utils.mjs +38 -0
- package/package.json +54 -30
- package/lib/cjs/UnmodifiableSetView.js +0 -53
- package/lib/cjs/types/UnmodifiableSetView.d.ts +0 -24
- package/lib/cjs/types/UnmodifiableSetView.d.ts.map +0 -1
- package/lib/esm/ClassPersistor.js +0 -112
- package/lib/esm/Esserializer/constant.js +0 -81
- package/lib/esm/Esserializer/deserializer.js +0 -307
- package/lib/esm/Esserializer/general.js +0 -34
- package/lib/esm/Esserializer/index.js +0 -39
- package/lib/esm/Esserializer/serializer.js +0 -130
- package/lib/esm/Hooks.js +0 -955
- package/lib/esm/KissAction.js +0 -1459
- package/lib/esm/Persistor.js +0 -113
- package/lib/esm/ProcessPersistence.js +0 -262
- package/lib/esm/Store.js +0 -1606
- package/lib/esm/StoreException.js +0 -69
- package/lib/esm/UnmodifiableSetView.js +0 -50
- package/lib/esm/types/UnmodifiableSetView.d.ts +0 -24
- package/lib/esm/types/UnmodifiableSetView.d.ts.map +0 -1
- package/lib/esm/utils.js +0 -3
package/lib/esm/KissAction.js
DELETED
|
@@ -1,1459 +0,0 @@
|
|
|
1
|
-
import { StoreException } from "./StoreException";
|
|
2
|
-
import { UserException } from "./UserException";
|
|
3
|
-
/** Base action. All other actions should extend this one. */
|
|
4
|
-
export class KissAction {
|
|
5
|
-
get attempts() {
|
|
6
|
-
return this._retry.attempts;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* The `before()` method MAY be implemented by the action. If implemented, it runs before the
|
|
10
|
-
* reducer. It may be sync or async. If it's async, the reducer will run after the before
|
|
11
|
-
* resolves.
|
|
12
|
-
*
|
|
13
|
-
* This method is useful for actions that need to perform some checks before executing the
|
|
14
|
-
* reducer. If necessary, it can prevent the reducer from running by throwing an exception.
|
|
15
|
-
*
|
|
16
|
-
* For example, the default `before()` method checks if the `checkInternet` property was set.
|
|
17
|
-
* If it was set, it checks if the device has an internet connection. If the connection is not
|
|
18
|
-
* present, it throws a `UserException`, preventing the reducer from running.
|
|
19
|
-
*
|
|
20
|
-
* Note the `after()` method always runs, even if the `before()` method throws an exception.
|
|
21
|
-
*/
|
|
22
|
-
before() {
|
|
23
|
-
if (this.checkInternet) {
|
|
24
|
-
const dialog = this.checkInternet.dialog;
|
|
25
|
-
return this.hasInternet().then((isConnected) => {
|
|
26
|
-
if (!isConnected) {
|
|
27
|
-
if (dialog) {
|
|
28
|
-
throw new UserException("Please, verify your connection.").withTitle("There is no Internet");
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
throw new UserException("No Internet").withDialog(false);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
// Return void (not a Promise) when we don't need to check internet.
|
|
37
|
-
else
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Checks if the device has an internet connection.
|
|
42
|
-
* Can be overridden by subclasses to provide custom internet connectivity checks.
|
|
43
|
-
*
|
|
44
|
-
* By default, in web environment it uses `navigator.onLine`, and for other environments it returns `true`.
|
|
45
|
-
* Note `navigator.onLine` is not very useful, as it only tells you if there's a local connection,
|
|
46
|
-
* and not whether the internet is accessible.
|
|
47
|
-
*
|
|
48
|
-
* It's recommended to override this method in your base action, to check for internet connectivity
|
|
49
|
-
* in some other way that suits your needs.
|
|
50
|
-
*
|
|
51
|
-
* For example, in React Native environments, we could use the `NetInfo` package
|
|
52
|
-
* (https://www.npmjs.com/package/@rescript-react-native/netinfo) to check for internet connectivity.
|
|
53
|
-
*
|
|
54
|
-
* First, add NetInfo to your `package.json`:
|
|
55
|
-
*
|
|
56
|
-
* ```json
|
|
57
|
-
* "dependencies": {
|
|
58
|
-
* "@react-native-community/netinfo": "^11.4.1"
|
|
59
|
-
* }
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* Then, import it in your action:
|
|
63
|
-
*
|
|
64
|
-
* ```typescript
|
|
65
|
-
* import NetInfo from '@react-native-community/netinfo';
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* Finally, override the `hasInternet()` method:
|
|
69
|
-
*
|
|
70
|
-
* ```typescript
|
|
71
|
-
* protected hasInternet(): Promise<boolean> {
|
|
72
|
-
* return NetInfo.fetch().then(state => state.isConnected);
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* Another option, for Node.js and the browser is using https://www.npmjs.com/package/is-online
|
|
77
|
-
*
|
|
78
|
-
* Note: Instead of adding this to every action, you can create a base class
|
|
79
|
-
* that extends `KissAction` and implement the `hasInternet()` method there.
|
|
80
|
-
*/
|
|
81
|
-
hasInternet() {
|
|
82
|
-
// Web environment detection.
|
|
83
|
-
const isWebEnvironment = typeof window !== 'undefined' && 'navigator' in window;
|
|
84
|
-
// In web environment, use navigator.onLine. Otherwise, assume connected.
|
|
85
|
-
return Promise.resolve(isWebEnvironment ? navigator.onLine : true);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* The `after()` method MAY be implemented by the action. If implemented, it runs after the
|
|
89
|
-
* `before()`, after `reduce()`, and after `wrapError()`.
|
|
90
|
-
*
|
|
91
|
-
* The `after()` method is always synchronous, and it will always be called when the action is
|
|
92
|
-
* dispatched, even if errors were thrown by `before` or `reduce`.
|
|
93
|
-
*/
|
|
94
|
-
after() {
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* If any error is thrown by `reduce` or `before`, you have the chance to further process it
|
|
98
|
-
* by using `wrapError`. Usually this is used to wrap the error inside another that better
|
|
99
|
-
* describes the failed action.
|
|
100
|
-
*
|
|
101
|
-
* For example, if some input validation inside your action throws a `ValidationError`,
|
|
102
|
-
* then instead of throwing this error you could do:
|
|
103
|
-
*
|
|
104
|
-
* ```
|
|
105
|
-
* wrapError(error) { return new UserException("Please enter a valid input.", {hardCause: error}) }
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* If you want to disable the error you can return `null`. For example, if you want
|
|
109
|
-
* to disable all errors of type `MyException`:
|
|
110
|
-
*
|
|
111
|
-
* ```
|
|
112
|
-
* wrapError(error) { return (error instanceof MyException) ? null : error }
|
|
113
|
-
* ```
|
|
114
|
-
*
|
|
115
|
-
* IMPORTANT: If instead of RETURNING an error you throw an error inside the `wrapError` method,
|
|
116
|
-
* Kiss will catch this error and use it instead the original error. In other words,
|
|
117
|
-
* returning an error or throwing an error works the same way. But it's recommended that you
|
|
118
|
-
* return the error instead of throwing it anyway.
|
|
119
|
-
*
|
|
120
|
-
* IMPORTANT: Apart from defining `wrapError()` methods per action, you can also define a
|
|
121
|
-
* global `wrapError` as a store parameter when you create the Store.
|
|
122
|
-
*/
|
|
123
|
-
wrapError(error) {
|
|
124
|
-
return error;
|
|
125
|
-
}
|
|
126
|
-
;
|
|
127
|
-
/**
|
|
128
|
-
* If the action should check for internet connection or not.
|
|
129
|
-
* - If `checkInternet = { dialog: true }`, throw a UserException with a dialog.
|
|
130
|
-
* - If `checkInternet = { dialog: false }`, throw a UserException without a dialog.
|
|
131
|
-
* - If `checkInternet` is undefined/null, don't check for internet.
|
|
132
|
-
*
|
|
133
|
-
* The default is checking for internet connectivity with `navigator.onLine`. To customize how
|
|
134
|
-
* internet connectivity is checked, you may override the `hasInternet()` method:
|
|
135
|
-
*
|
|
136
|
-
* ```ts
|
|
137
|
-
* class MyAction extends KissAction<State> {
|
|
138
|
-
* checkInternet = { dialog: true };
|
|
139
|
-
*
|
|
140
|
-
* protected hasInternet(): Promise<boolean> {
|
|
141
|
-
* // Custom internet check implementation
|
|
142
|
-
* return Promise.resolve(navigator.onLine && await this.pingServer('https://api.example.com/health');
|
|
143
|
-
* }
|
|
144
|
-
*
|
|
145
|
-
* reduce() { ... }
|
|
146
|
-
* }
|
|
147
|
-
* ```
|
|
148
|
-
*
|
|
149
|
-
* By default, the `hasInternet()` method uses `navigator.onLine` in web environments
|
|
150
|
-
* and returns true for other environments.
|
|
151
|
-
*/
|
|
152
|
-
checkInternet;
|
|
153
|
-
_store = null;
|
|
154
|
-
_resolve = null;
|
|
155
|
-
_status = new ActionStatus();
|
|
156
|
-
_initialState = null;
|
|
157
|
-
_log = [];
|
|
158
|
-
/**
|
|
159
|
-
* Adds a key/value pair to the action log.
|
|
160
|
-
*
|
|
161
|
-
* ```ts
|
|
162
|
-
* class LoadUser extends Action {
|
|
163
|
-
*
|
|
164
|
-
* async reduce() {
|
|
165
|
-
* let user = await loadUser();
|
|
166
|
-
* this.log('User', user.id); // Here!
|
|
167
|
-
*
|
|
168
|
-
* return (state) => state.copy(user: user);
|
|
169
|
-
* }
|
|
170
|
-
* }
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
log(key, value) {
|
|
174
|
-
this._log.push({ key, value });
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Gets the action log.
|
|
178
|
-
*
|
|
179
|
-
* ```ts
|
|
180
|
-
* function stateObserver(action, prevState, newState, error, dispatchCount) {
|
|
181
|
-
* let log = action.getLog(); // Here!
|
|
182
|
-
* saveMetrics(action, log, newState, error);
|
|
183
|
-
* }
|
|
184
|
-
* ```
|
|
185
|
-
*/
|
|
186
|
-
get getLog() {
|
|
187
|
-
return this._log;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Returns the "status" of the action, used to keep track of the action's lifecycle. If you have
|
|
191
|
-
* a reference to the action you can check its status at any time with `action.status`:
|
|
192
|
-
*
|
|
193
|
-
* ```ts
|
|
194
|
-
* let action = new MyAction();
|
|
195
|
-
* await store.dispatchAndWait(new MyAction());
|
|
196
|
-
* if (action.isFinishedWithNoErrors) { ... }
|
|
197
|
-
* ```
|
|
198
|
-
* However, dispatchAndWait also returns the action status after it finishes:
|
|
199
|
-
*
|
|
200
|
-
* ```ts
|
|
201
|
-
* let status = await store.dispatchAndWait(new MyAction());
|
|
202
|
-
* if (status.isFinishedWithNoErrors) { ... }
|
|
203
|
-
* ```
|
|
204
|
-
*/
|
|
205
|
-
get status() {
|
|
206
|
-
return this._status;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Dispatches an action to the Redux store.
|
|
210
|
-
*/
|
|
211
|
-
dispatch(action) {
|
|
212
|
-
this.store.dispatch(action);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Dispatches an action and returns a promise that resolves when the action finishes.
|
|
216
|
-
* While the state change from the action's reducer will have been applied when the promise
|
|
217
|
-
* resolves, other independent processes that the action may have started may still be in
|
|
218
|
-
* progress.
|
|
219
|
-
*
|
|
220
|
-
* Usage: `await this.dispatchAndWait(new MyAction())`.
|
|
221
|
-
*/
|
|
222
|
-
dispatchAndWait(action) {
|
|
223
|
-
return this.store.dispatchAndWait(action);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Dispatches the given action to the Redux store, to potentially change the state.
|
|
227
|
-
*
|
|
228
|
-
* This is exactly the same as the regular `dispatch`, except for the fact it
|
|
229
|
-
* will throw a `StoreException` if the action is ASYNC. Note an action is ASYNC
|
|
230
|
-
* if any of its `reduce()` or `before()` methods return a Promise.
|
|
231
|
-
*
|
|
232
|
-
* The only use for `dispatchSync` is when you need to guarantee (in runtime) that your
|
|
233
|
-
* action is SYNC, which means the state gets changed right after the dispatch call.
|
|
234
|
-
*/
|
|
235
|
-
dispatchSync(action) {
|
|
236
|
-
return this.store.dispatchSync(action);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Returns the Redux store: `this.store`.
|
|
240
|
-
*
|
|
241
|
-
* To read the current state inside an action, use: `this.store.state` or simply `this.state`.
|
|
242
|
-
* Note this is the CURRENT state, meaning it may change each time you look at it.
|
|
243
|
-
*
|
|
244
|
-
* If you want the snapshot of the state as it was when the action was dispatched, you can
|
|
245
|
-
* use `this.initialState`. You can also make a copy of the current state at any point in time:
|
|
246
|
-
*
|
|
247
|
-
* ```ts
|
|
248
|
-
* let currentState = this.state;
|
|
249
|
-
* ```
|
|
250
|
-
*
|
|
251
|
-
* To dispatch an action inside the current action, you can simply write `this.dispatch()`
|
|
252
|
-
* or `this.dispatchAndWait()`, which is the same as `this.store.dispatch()` etc.
|
|
253
|
-
*/
|
|
254
|
-
get store() {
|
|
255
|
-
if (this._store === null)
|
|
256
|
-
throw new StoreException('Store not set in action');
|
|
257
|
-
return this._store;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Returns the CURRENT state: `this.state`.
|
|
261
|
-
* Note this is the CURRENT state, meaning it may change each time you look at it.
|
|
262
|
-
*
|
|
263
|
-
* If you want a snapshot of the state as it was when the action was dispatched, you can
|
|
264
|
-
* use `this.initialState`. You can also make a copy of the current state at any point in time:
|
|
265
|
-
*
|
|
266
|
-
* ```ts
|
|
267
|
-
* let currentState = this.state;
|
|
268
|
-
* ```
|
|
269
|
-
*
|
|
270
|
-
* To dispatch an action inside the current action, you can simply write `this.dispatch()`
|
|
271
|
-
* or `this.dispatchAndWait()`, which is the same as `this.store.dispatch()` etc.
|
|
272
|
-
*/
|
|
273
|
-
get state() {
|
|
274
|
-
return this.store.state;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Returns the state as it was when the action was dispatched.
|
|
278
|
-
*
|
|
279
|
-
* It can be the same or different from `this.state`, which is the current state in the store,
|
|
280
|
-
* because other actions may have changed the current state since this action was dispatched.
|
|
281
|
-
*
|
|
282
|
-
* In the case of SYNC actions that do not dispatch other SYNC actions,
|
|
283
|
-
* `this.state` and `this.initialState` will be the same.
|
|
284
|
-
*/
|
|
285
|
-
get initialState() {
|
|
286
|
-
return this._initialState;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* You can wrap the reducer to allow for some pre- or post-processing.
|
|
290
|
-
* For instance, if you want to prevent an async reducer from modifying the current state,
|
|
291
|
-
* if the current state has already changed since the reducer started:
|
|
292
|
-
*
|
|
293
|
-
* ```ts
|
|
294
|
-
* wrapReduce(reduce: () => St | null | Promise<((state: St) => (St | null)) | null>): () => St | null | Promise<((state: St) => (St | null)) | null> {
|
|
295
|
-
* let oldState = this.state;
|
|
296
|
-
* let newState = await reduce();
|
|
297
|
-
* return oldState === this.state ? newState : null;
|
|
298
|
-
* }
|
|
299
|
-
* ```
|
|
300
|
-
*
|
|
301
|
-
* Note: If you return a function that returns a Promise, the action will be ASYNC.
|
|
302
|
-
* If you return a function that returns St, the action will be SYNC only if the
|
|
303
|
-
* before and reduce methods are also SYNC.
|
|
304
|
-
*/
|
|
305
|
-
wrapReduce(reduce) {
|
|
306
|
-
return reduce;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* If method `abortDispatch()` returns true, the action will not be dispatched: `before`,
|
|
310
|
-
* `reduce` and `after` will not be called. This is an advanced feature only useful under rare
|
|
311
|
-
* circumstances, and you should only use it if you know what you are doing.
|
|
312
|
-
*/
|
|
313
|
-
abortDispatch() {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Method `abortReduce()` is called with the result of the `reduce()` method, right after
|
|
318
|
-
* the `reduce()` runs. However, it's only called if no error was thrown, and if the `reduce()`
|
|
319
|
-
* method result would change the current state (in other words, if `reduce()` returned a
|
|
320
|
-
* non-null state different from the current state).
|
|
321
|
-
*
|
|
322
|
-
* If `abortReduce()` returns true, the result of the `reduce()` method will be discarded,
|
|
323
|
-
* as if the `reduce()` method itself returned null.
|
|
324
|
-
*
|
|
325
|
-
* Note: `abortReduce()` is called BEFORE the `after()` method, and the `after()` method will
|
|
326
|
-
* run normally no mather the result of `abortReduce()`.
|
|
327
|
-
*
|
|
328
|
-
* For example, suppose you want to abort an async action if some part of the state changed
|
|
329
|
-
* since when the action was dispatched:
|
|
330
|
-
* ```
|
|
331
|
-
* abortReduce(state: St): boolean {
|
|
332
|
-
* return (state.somePart !== this.initialState.somePart);
|
|
333
|
-
* }
|
|
334
|
-
* ```
|
|
335
|
-
*
|
|
336
|
-
* Method `abortReduce()` is an advanced feature only useful under rare circumstances,
|
|
337
|
-
* and you should only use it if you know what you are doing.
|
|
338
|
-
*/
|
|
339
|
-
abortReduce(state) {
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* You can use `isWaiting` and pass it an action `type`:
|
|
344
|
-
* - It returns true if an ASYNC action of the specific type is currently being processed.
|
|
345
|
-
* - It returns false if an ASYNC action of the specific type is NOT currently being processed.
|
|
346
|
-
* - This is only useful for ASYNC actions, since it always returns `false` when the action is SYNC.
|
|
347
|
-
*
|
|
348
|
-
* Note an action is ASYNC if it returns a promise from its `before` OR its `reduce` methods.
|
|
349
|
-
*
|
|
350
|
-
* ```ts
|
|
351
|
-
* dispatch(MyAction());
|
|
352
|
-
* if (this.isWaiting(MyAction)) { // Show a spinner } *
|
|
353
|
-
* ```
|
|
354
|
-
*/
|
|
355
|
-
isWaiting(type) {
|
|
356
|
-
return this.store.isWaiting(type);
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Returns true if the given action `type` failed with an `UserException`.
|
|
360
|
-
* Note: This method uses the EXACT action type. Subtypes are not considered.
|
|
361
|
-
*/
|
|
362
|
-
isFailed(type) {
|
|
363
|
-
return this.store.isFailed(type);
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Returns the `UserException` of the `type` that failed.
|
|
367
|
-
* Note: This method uses the EXACT type in `type`. Subtypes are not considered.
|
|
368
|
-
*/
|
|
369
|
-
exceptionFor(type) {
|
|
370
|
-
return this.store.exceptionFor(type);
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Removes the exact given action `type` from the list of action types that failed.
|
|
374
|
-
* Note it clears the EXACT given type. Subtypes are not considered.
|
|
375
|
-
*
|
|
376
|
-
* Even if you never call this method explicitly, just dispatching an action already clears that action type
|
|
377
|
-
* from the list of failing action types. But you can call this method explicitly if you want to clear the
|
|
378
|
-
* action type before it's used again.
|
|
379
|
-
*
|
|
380
|
-
* Usage:
|
|
381
|
-
* ```ts
|
|
382
|
-
* this.clearExceptionFor(MyAction);
|
|
383
|
-
* ```
|
|
384
|
-
*/
|
|
385
|
-
clearExceptionFor(type) {
|
|
386
|
-
return this.store.clearExceptionFor(type);
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* If your action overrides this method returning `true`, it will abort the action in
|
|
390
|
-
* case the action is still running from a previous dispatch. For example:
|
|
391
|
-
*
|
|
392
|
-
* ```ts
|
|
393
|
-
* class MyAction extends KissActiontate> {
|
|
394
|
-
* nonReentrant = true;
|
|
395
|
-
* }
|
|
396
|
-
* ```
|
|
397
|
-
*/
|
|
398
|
-
nonReentrant = false;
|
|
399
|
-
/**
|
|
400
|
-
* To retry the `reduce` method when it throws an error:
|
|
401
|
-
*
|
|
402
|
-
* ```ts
|
|
403
|
-
* class MyAction extends KissActiontate> {
|
|
404
|
-
* retry = {on: true}
|
|
405
|
-
* }
|
|
406
|
-
* ```
|
|
407
|
-
*
|
|
408
|
-
* The retry parameters are:
|
|
409
|
-
*
|
|
410
|
-
* - Initial Delay: Millisecond delay before the first retry attempt.
|
|
411
|
-
* - Multiplier: The factor by which the delay increases for each subsequent retry.
|
|
412
|
-
* - Maximum Retries: The maximum number of retries before giving up.
|
|
413
|
-
* - Maximum Delay: The maximum millisecond delay between retries to avoid excessively long wait times.
|
|
414
|
-
*
|
|
415
|
-
* And their default values are:
|
|
416
|
-
*
|
|
417
|
-
* - `initialDelay` is `350` milliseconds.
|
|
418
|
-
* - `multiplier` is `2`, which means the default delays are: 350 millis, 700 millis, and 1.4 seg.
|
|
419
|
-
* - `maxRetries` is `3`, meaning it will try a total of 4 times.
|
|
420
|
-
* - `maxDelay` is `5000` milliseconds (which means 5 seconds).
|
|
421
|
-
*
|
|
422
|
-
* You can change one or more of the default values.
|
|
423
|
-
* Doing so also turns on the retry:
|
|
424
|
-
*
|
|
425
|
-
* ```ts
|
|
426
|
-
* class MyAction extends KissActiontate> {
|
|
427
|
-
* retry = {initialDelay: 100, multiplier: 5, maxRetries: 10, maxDelay: 10000};
|
|
428
|
-
* }
|
|
429
|
-
* ```
|
|
430
|
-
*
|
|
431
|
-
* If you want to retry unlimited times, make `maxRetries` equal to: `-1`:
|
|
432
|
-
*
|
|
433
|
-
* ```ts
|
|
434
|
-
* class MyAction extends KissActiontate> {
|
|
435
|
-
* retry = {maxRetries: -1};
|
|
436
|
-
* }
|
|
437
|
-
* ```
|
|
438
|
-
*
|
|
439
|
-
* Notes:
|
|
440
|
-
*
|
|
441
|
-
* - If you `await dispatchAndWait(action)` and the action uses unlimited retries,
|
|
442
|
-
* it may never finish if it keeps failing. So, be careful when using it.
|
|
443
|
-
*
|
|
444
|
-
* - If the `before` method throws an error, the retry will NOT happen.
|
|
445
|
-
*
|
|
446
|
-
* - The retry delay only starts after the reducer finishes executing. For example, if the
|
|
447
|
-
* reducer takes 1 second to fail, and the retry delay is 350 millis, the first retry will
|
|
448
|
-
* happen 1.35 seconds after the first reducer started.
|
|
449
|
-
*
|
|
450
|
-
* - When the action finally fails, the last error will be rethrown, and the previous ones
|
|
451
|
-
* will be ignored.
|
|
452
|
-
*
|
|
453
|
-
* - For most actions that use `retry`, consider also making them non-Reentrant to avoid
|
|
454
|
-
* multiple instances of the same action running at the same time:
|
|
455
|
-
* ```ts
|
|
456
|
-
* class MyAction extends KissActiontate> {
|
|
457
|
-
* retry = {on: true}
|
|
458
|
-
* nonReentrant = true;
|
|
459
|
-
* }
|
|
460
|
-
* ```
|
|
461
|
-
*
|
|
462
|
-
* - Keep in mind that all actions using the `retry` mixin will become asynchronous, even
|
|
463
|
-
* if the original action was synchronous.
|
|
464
|
-
*
|
|
465
|
-
* - If necessary, you can know the current "attempt number" by using `this.attempts`.
|
|
466
|
-
*/
|
|
467
|
-
retry;
|
|
468
|
-
_retry = {
|
|
469
|
-
on: false,
|
|
470
|
-
attempts: 0,
|
|
471
|
-
initialDelay: 350,
|
|
472
|
-
multiplier: 2,
|
|
473
|
-
maxRetries: 3,
|
|
474
|
-
maxDelay: 5000,
|
|
475
|
-
unlimitedRetries: false,
|
|
476
|
-
currentDelay: 0,
|
|
477
|
-
};
|
|
478
|
-
get ifRetryIsOn() {
|
|
479
|
-
return this.retry?.on === true;
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Returns a promise which will resolve when the given state `condition` is true.
|
|
483
|
-
* If the condition is already true when the method is called, the promise resolves immediately.
|
|
484
|
-
*
|
|
485
|
-
* You may also provide a `timeoutMillis`, which by default is 10 minutes. If you want, you
|
|
486
|
-
* can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
|
|
487
|
-
* To disable the timeout, make it 0 or -1.
|
|
488
|
-
*
|
|
489
|
-
* This method is useful in tests, and it returns the action which changed
|
|
490
|
-
* the store state into the condition, in case you need it:
|
|
491
|
-
*
|
|
492
|
-
* ```typescript
|
|
493
|
-
* let action = await store.waitCondition((state) => state.name == "Bill");
|
|
494
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
495
|
-
*
|
|
496
|
-
* This method is also eventually useful in production code, in which case you
|
|
497
|
-
* should avoid waiting for conditions that may take a very long time to complete,
|
|
498
|
-
* as checking the condition is an overhead to every state change.
|
|
499
|
-
*
|
|
500
|
-
* Examples:
|
|
501
|
-
*
|
|
502
|
-
* // Dispatches an actions that changes the state, then await for the state change:
|
|
503
|
-
* expect(store.state.name, 'John')
|
|
504
|
-
* dispatch(new ChangeNameAction("Bill"));
|
|
505
|
-
* let action = await store.waitCondition((state) => state.name == "Bill");
|
|
506
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
507
|
-
* expect(store.state.name, 'Bill');
|
|
508
|
-
*
|
|
509
|
-
* // Dispatches actions and wait until no actions are in progress.
|
|
510
|
-
* dispatch(new BuyAction('IBM'));
|
|
511
|
-
* dispatch(new BuyAction('TSLA'));
|
|
512
|
-
* await waitAllActions([]);
|
|
513
|
-
* expect(state.stocks, ['IBM', 'TSLA']);
|
|
514
|
-
*
|
|
515
|
-
* // Dispatches two actions in PARALLEL and wait for their TYPES:
|
|
516
|
-
* expect(store.state.portfolio, ['TSLA']);
|
|
517
|
-
* dispatch(new BuyAction('IBM'));
|
|
518
|
-
* dispatch(new SellAction('TSLA'));
|
|
519
|
-
* await store.waitAllActionTypes([BuyAction, SellAction]);
|
|
520
|
-
* expect(store.state.portfolio, ['IBM']);
|
|
521
|
-
*
|
|
522
|
-
* // Dispatches actions in PARALLEL and wait until no actions are in progress.
|
|
523
|
-
* dispatch(new BuyAction('IBM'));
|
|
524
|
-
* dispatch(new BuyAction('TSLA'));
|
|
525
|
-
* await store.waitAllActions([]);
|
|
526
|
-
* expect(store.state.portfolio.includes('IBM', 'TSLA')).toBe(false);
|
|
527
|
-
*
|
|
528
|
-
* // Dispatches two actions in PARALLEL and wait for them:
|
|
529
|
-
* let action1 = new BuyAction('IBM');
|
|
530
|
-
* let action2 = new SellAction('TSLA');
|
|
531
|
-
* dispatch(action1);
|
|
532
|
-
* dispatch(action2);
|
|
533
|
-
* await store.waitAllActions([action1, action2]);
|
|
534
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
535
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
536
|
-
*
|
|
537
|
-
* // Dispatches two actions in SERIES and wait for them:
|
|
538
|
-
* await dispatchAndWait(new BuyAction('IBM'));
|
|
539
|
-
* await dispatchAndWait(new SellAction('TSLA'));
|
|
540
|
-
* expect(store.state.portfolio.includes('IBM', 'TSLA')).toBe(false);
|
|
541
|
-
*
|
|
542
|
-
* // Wait until some action of a given type is dispatched.
|
|
543
|
-
* dispatch(new DoALotOfStuffAction());
|
|
544
|
-
* let action = store.waitActionType(ChangeNameAction);
|
|
545
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
546
|
-
* expect(action.status.isCompletedOk).toBe(true);
|
|
547
|
-
* expect(store.state.name, 'Bill');
|
|
548
|
-
*
|
|
549
|
-
* // Wait until some action of the given types is dispatched.
|
|
550
|
-
* dispatch(new ProcessStocksAction());
|
|
551
|
-
* let action = store.waitAnyActionTypeFinishes([BuyAction, SellAction]);
|
|
552
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
553
|
-
*
|
|
554
|
-
* See also:
|
|
555
|
-
* `waitCondition` - Waits until the state is in a given condition.
|
|
556
|
-
* `waitActionCondition` - Waits until the actions in progress meet a given condition.
|
|
557
|
-
* `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
|
|
558
|
-
* `waitActionType` - Waits until an action of a given type is NOT in progress.
|
|
559
|
-
* `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
|
|
560
|
-
* `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
|
|
561
|
-
*/
|
|
562
|
-
waitCondition(condition, timeoutMillis = null) {
|
|
563
|
-
return this.store.waitCondition(condition, timeoutMillis);
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Returns a Promise that resolves when some actions meet the given `condition`.
|
|
567
|
-
*
|
|
568
|
-
* If `completeImmediately` is false (the default), this method will throw an error if the
|
|
569
|
-
* condition was already true when the method was called. Otherwise, the promise will complete
|
|
570
|
-
* immediately and throw no error.
|
|
571
|
-
*
|
|
572
|
-
* The `condition` is a function that takes the set of actions "in progress", as well as an
|
|
573
|
-
* action that just entered the set (by being dispatched) or left the set (by finishing
|
|
574
|
-
* dispatching). The function should return `true` when the condition is met, and `false`
|
|
575
|
-
* otherwise. For example:
|
|
576
|
-
*
|
|
577
|
-
* ```ts
|
|
578
|
-
* let action = await store.waitActionCondition((actionsInProgress, triggerAction) => { ... });
|
|
579
|
-
* ```
|
|
580
|
-
*
|
|
581
|
-
* Important: Your condition function should NOT modify the set of actions.
|
|
582
|
-
*
|
|
583
|
-
* You get back the set of the actions being dispatched that met the condition, as well as
|
|
584
|
-
* the action that triggered the condition by being added or removed from the set.
|
|
585
|
-
*
|
|
586
|
-
* Note: The condition is only checked when some action is dispatched or finishes dispatching.
|
|
587
|
-
* It's not checked every time action statuses change.
|
|
588
|
-
*
|
|
589
|
-
* You may also provide a `timeoutMillis`, which by default is 10 minutes.
|
|
590
|
-
* To disable the timeout, make it 0 or -1.
|
|
591
|
-
* If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
|
|
592
|
-
*
|
|
593
|
-
* Examples:
|
|
594
|
-
*
|
|
595
|
-
* ```ts
|
|
596
|
-
* // Dispatches an actions that changes the state, then await for the state change:
|
|
597
|
-
* expect(store.state.name).toBe('John');
|
|
598
|
-
* dispatch(new ChangeNameAction("Bill"));
|
|
599
|
-
* let action = await store.waitCondition((state) => state.name == "Bill");
|
|
600
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
601
|
-
* expect(store.state.name).toBe('Bill');
|
|
602
|
-
*
|
|
603
|
-
* // Dispatches actions and wait until no actions are in progress.
|
|
604
|
-
* dispatch(new BuyAction('IBM'));
|
|
605
|
-
* dispatch(new BuyAction('TSLA'));
|
|
606
|
-
* await waitAllActions();
|
|
607
|
-
* expect(state.stocks).toEqual(['IBM', 'TSLA']);
|
|
608
|
-
*
|
|
609
|
-
* // Dispatches two actions in PARALLEL and wait for their TYPES:
|
|
610
|
-
* expect(store.state.portfolio).toEqual(['TSLA']);
|
|
611
|
-
* dispatch(new BuyAction('IBM'));
|
|
612
|
-
* dispatch(new SellAction('TSLA'));
|
|
613
|
-
* await store.waitAllActionTypes([BuyAction, SellAction]);
|
|
614
|
-
* expect(store.state.portfolio).toEqual(['IBM']);
|
|
615
|
-
*
|
|
616
|
-
* // Dispatches actions in PARALLEL and wait until no actions are in progress.
|
|
617
|
-
* dispatch(new BuyAction('IBM'));
|
|
618
|
-
* dispatch(new BuyAction('TSLA'));
|
|
619
|
-
* await store.waitAllActions();
|
|
620
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
621
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(true);
|
|
622
|
-
*
|
|
623
|
-
* // Dispatches two actions in PARALLEL and wait for them:
|
|
624
|
-
* let action1 = new BuyAction('IBM');
|
|
625
|
-
* let action2 = new SellAction('TSLA');
|
|
626
|
-
* dispatch(action1);
|
|
627
|
-
* dispatch(action2);
|
|
628
|
-
* await store.waitAllActions([action1, action2]);
|
|
629
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
630
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
631
|
-
*
|
|
632
|
-
* // Dispatches two actions in SERIES and wait for them:
|
|
633
|
-
* await dispatchAndWait(new BuyAction('IBM'));
|
|
634
|
-
* await dispatchAndWait(new SellAction('TSLA'));
|
|
635
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
636
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
637
|
-
*
|
|
638
|
-
* // Wait until some action of a given type is dispatched.
|
|
639
|
-
* dispatch(new DoALotOfStuffAction());
|
|
640
|
-
* let action = await store.waitActionType(ChangeNameAction);
|
|
641
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
642
|
-
* expect(action.status.isCompletedOk).toBe(true);
|
|
643
|
-
* expect(store.state.name).toBe('Bill');
|
|
644
|
-
*
|
|
645
|
-
* // Wait until some action of the given types is dispatched.
|
|
646
|
-
* dispatch(new ProcessStocksAction());
|
|
647
|
-
* let action = await store.waitAnyActionTypeFinishes([BuyAction, SellAction]);
|
|
648
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
649
|
-
* ```
|
|
650
|
-
*
|
|
651
|
-
* See also:
|
|
652
|
-
* `waitCondition` - Waits until the state is in a given condition.
|
|
653
|
-
* `waitActionCondition` - Waits until the actions in progress meet a given condition.
|
|
654
|
-
* `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
|
|
655
|
-
* `waitActionType` - Waits until an action of a given type is NOT in progress.
|
|
656
|
-
* `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
|
|
657
|
-
* `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
|
|
658
|
-
*
|
|
659
|
-
* You should only use this method in tests.
|
|
660
|
-
*/
|
|
661
|
-
async waitActionCondition(
|
|
662
|
-
//
|
|
663
|
-
/// The condition receives the current actions in progress, and the action that triggered the condition.
|
|
664
|
-
condition, {
|
|
665
|
-
// If `completeImmediately` is `false` (the default), this method will throw an error if the
|
|
666
|
-
// condition is already true when the method is called. Otherwise, the promise will complete
|
|
667
|
-
// immediately and throw no error.
|
|
668
|
-
completeImmediately = false,
|
|
669
|
-
//
|
|
670
|
-
// The maximum time to wait for the condition to be met. The default is 10 minutes.
|
|
671
|
-
// To disable the timeout, make it 0 or -1.
|
|
672
|
-
timeoutMillis = null, } = {}) {
|
|
673
|
-
return this.store.waitActionCondition(condition, {
|
|
674
|
-
completeImmediately: completeImmediately,
|
|
675
|
-
timeoutMillis: timeoutMillis
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* Returns a promise that resolves when ALL given actions finished dispatching.
|
|
680
|
-
*
|
|
681
|
-
* If `completeImmediately` is false (the default), this method will throw an error if none
|
|
682
|
-
* of the given actions are in progress when the method is called. Otherwise, the promise will
|
|
683
|
-
* complete immediately and throw no error.
|
|
684
|
-
*
|
|
685
|
-
* However, if you don't provide any actions (empty list or `null`), the promise will complete
|
|
686
|
-
* when ALL current actions in progress finish dispatching. In other words, when no actions are
|
|
687
|
-
* currently in progress. In this case, if [completeImmediately] is `false`, the method will
|
|
688
|
-
* throw an error if no actions are in progress when the method is called.
|
|
689
|
-
*
|
|
690
|
-
* Note: Waiting until no actions are in progress should only be done in test, never in
|
|
691
|
-
* production, as it's very easy to create a deadlock. However, waiting for specific actions to
|
|
692
|
-
* finish is safe in production, as long as you're waiting for actions you just dispatched.
|
|
693
|
-
*
|
|
694
|
-
* You may also provide a [timeoutMillis], which by default is 10 minutes.
|
|
695
|
-
* To disable the timeout, make it 0 or -1.
|
|
696
|
-
* If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
|
|
697
|
-
*
|
|
698
|
-
* Examples:
|
|
699
|
-
*
|
|
700
|
-
* ```ts
|
|
701
|
-
* // Dispatches an actions that changes the state, then await for the state change:
|
|
702
|
-
* expect(store.state.name).toBe('John');
|
|
703
|
-
* dispatch(new ChangeNameAction("Bill"));
|
|
704
|
-
* let action = await store.waitCondition((state) => state.name == "Bill");
|
|
705
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
706
|
-
* expect(store.state.name).toBe('Bill');
|
|
707
|
-
*
|
|
708
|
-
* // Dispatches actions and wait until no actions are in progress.
|
|
709
|
-
* dispatch(new BuyAction('IBM'));
|
|
710
|
-
* dispatch(new BuyAction('TSLA'));
|
|
711
|
-
* await waitAllActions();
|
|
712
|
-
* expect(state.stocks).toEqual(['IBM', 'TSLA']);
|
|
713
|
-
*
|
|
714
|
-
* // Dispatches two actions in PARALLEL and wait for their TYPES:
|
|
715
|
-
* expect(store.state.portfolio).toEqual(['TSLA']);
|
|
716
|
-
* dispatch(new BuyAction('IBM'));
|
|
717
|
-
* dispatch(new SellAction('TSLA'));
|
|
718
|
-
* await store.waitAllActionTypes([BuyAction, SellAction]);
|
|
719
|
-
* expect(store.state.portfolio).toEqual(['IBM']);
|
|
720
|
-
*
|
|
721
|
-
* // Dispatches actions in PARALLEL and wait until no actions are in progress.
|
|
722
|
-
* dispatch(new BuyAction('IBM'));
|
|
723
|
-
* dispatch(new BuyAction('TSLA'));
|
|
724
|
-
* await store.waitAllActions();
|
|
725
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
726
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(true);
|
|
727
|
-
*
|
|
728
|
-
* // Dispatches two actions in PARALLEL and wait for them:
|
|
729
|
-
* let action1 = new BuyAction('IBM');
|
|
730
|
-
* let action2 = new SellAction('TSLA');
|
|
731
|
-
* dispatch(action1);
|
|
732
|
-
* dispatch(action2);
|
|
733
|
-
* await store.waitAllActions([action1, action2]);
|
|
734
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
735
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
736
|
-
*
|
|
737
|
-
* // Dispatches two actions in SERIES and wait for them:
|
|
738
|
-
* await dispatchAndWait(new BuyAction('IBM'));
|
|
739
|
-
* await dispatchAndWait(new SellAction('TSLA'));
|
|
740
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
741
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
742
|
-
*
|
|
743
|
-
* // Wait until some action of a given type is dispatched.
|
|
744
|
-
* dispatch(new DoALotOfStuffAction());
|
|
745
|
-
* let action = await store.waitActionType(ChangeNameAction);
|
|
746
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
747
|
-
* expect(action.status.isCompletedOk).toBe(true);
|
|
748
|
-
* expect(store.state.name).toBe('Bill');
|
|
749
|
-
*
|
|
750
|
-
* // Wait until some action of the given types is dispatched.
|
|
751
|
-
* dispatch(new ProcessStocksAction());
|
|
752
|
-
* let action = await store.waitAnyActionTypeFinishes([BuyAction, SellAction]);
|
|
753
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
754
|
-
* ```
|
|
755
|
-
*
|
|
756
|
-
* See also:
|
|
757
|
-
* `waitCondition` - Waits until the state is in a given condition.
|
|
758
|
-
* `waitActionCondition` - Waits until the actions in progress meet a given condition.
|
|
759
|
-
* `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
|
|
760
|
-
* `waitActionType` - Waits until an action of a given type is NOT in progress.
|
|
761
|
-
* `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
|
|
762
|
-
* `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
|
|
763
|
-
*
|
|
764
|
-
* You should only use this method in tests.
|
|
765
|
-
*/
|
|
766
|
-
waitAllActions(actions, { completeImmediately = false, timeoutMillis = null } = {}) {
|
|
767
|
-
return this.store.waitAllActions(actions, {
|
|
768
|
-
completeImmediately: completeImmediately,
|
|
769
|
-
timeoutMillis: timeoutMillis
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
/**
|
|
773
|
-
* Returns a promise that completes when an action of the given type in NOT in progress
|
|
774
|
-
* (it's not being dispatched):
|
|
775
|
-
*
|
|
776
|
-
* - If NO action of the given type is currently in progress when the method is called,
|
|
777
|
-
* and `completeImmediately` is false (the default), this method will throw an error.
|
|
778
|
-
*
|
|
779
|
-
* - If NO action of the given type is currently in progress when the method is called,
|
|
780
|
-
* and `completeImmediately` is true, the promise completes immediately, returns `null`,
|
|
781
|
-
* and throws no error.
|
|
782
|
-
*
|
|
783
|
-
* - If an action of the given type is in progress, the promise completes when the action
|
|
784
|
-
* finishes, and returns the action. You can use the returned action to check its `status`:
|
|
785
|
-
*
|
|
786
|
-
* ```dart
|
|
787
|
-
* var action = await store.waitActionType(MyAction);
|
|
788
|
-
* expect(action.status.originalError, isA<UserException>());
|
|
789
|
-
* ```
|
|
790
|
-
*
|
|
791
|
-
* You may also provide a `timeoutMillis`, which by default is 10 minutes.
|
|
792
|
-
* To disable the timeout, make it 0 or -1.
|
|
793
|
-
* If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
|
|
794
|
-
*
|
|
795
|
-
* Examples:
|
|
796
|
-
*
|
|
797
|
-
* ```ts
|
|
798
|
-
* // Dispatches an actions that changes the state, then await for the state change:
|
|
799
|
-
* expect(store.state.name).toBe('John');
|
|
800
|
-
* dispatch(new ChangeNameAction("Bill"));
|
|
801
|
-
* let action = await store.waitCondition((state) => state.name == "Bill");
|
|
802
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
803
|
-
* expect(store.state.name).toBe('Bill');
|
|
804
|
-
*
|
|
805
|
-
* // Dispatches actions and wait until no actions are in progress.
|
|
806
|
-
* dispatch(new BuyAction('IBM'));
|
|
807
|
-
* dispatch(new BuyAction('TSLA'));
|
|
808
|
-
* await waitAllActions();
|
|
809
|
-
* expect(state.stocks).toEqual(['IBM', 'TSLA']);
|
|
810
|
-
*
|
|
811
|
-
* // Dispatches two actions in PARALLEL and wait for their TYPES:
|
|
812
|
-
* expect(store.state.portfolio).toEqual(['TSLA']);
|
|
813
|
-
* dispatch(new BuyAction('IBM'));
|
|
814
|
-
* dispatch(new SellAction('TSLA'));
|
|
815
|
-
* await store.waitAllActionTypes([BuyAction, SellAction]);
|
|
816
|
-
* expect(store.state.portfolio).toEqual(['IBM']);
|
|
817
|
-
*
|
|
818
|
-
* // Dispatches actions in PARALLEL and wait until no actions are in progress.
|
|
819
|
-
* dispatch(new BuyAction('IBM'));
|
|
820
|
-
* dispatch(new BuyAction('TSLA'));
|
|
821
|
-
* await store.waitAllActions();
|
|
822
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
823
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(true);
|
|
824
|
-
*
|
|
825
|
-
* // Dispatches two actions in PARALLEL and wait for them:
|
|
826
|
-
* let action1 = new BuyAction('IBM');
|
|
827
|
-
* let action2 = new SellAction('TSLA');
|
|
828
|
-
* dispatch(action1);
|
|
829
|
-
* dispatch(action2);
|
|
830
|
-
* await store.waitAllActions([action1, action2]);
|
|
831
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
832
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
833
|
-
*
|
|
834
|
-
* // Dispatches two actions in SERIES and wait for them:
|
|
835
|
-
* await dispatchAndWait(new BuyAction('IBM'));
|
|
836
|
-
* await dispatchAndWait(new SellAction('TSLA'));
|
|
837
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
838
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
839
|
-
*
|
|
840
|
-
* // Wait until some action of a given type is dispatched.
|
|
841
|
-
* dispatch(new DoALotOfStuffAction());
|
|
842
|
-
* let action = await store.waitActionType(ChangeNameAction);
|
|
843
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
844
|
-
* expect(action.status.isCompletedOk).toBe(true);
|
|
845
|
-
* expect(store.state.name).toBe('Bill');
|
|
846
|
-
*
|
|
847
|
-
* // Wait until some action of the given types is dispatched.
|
|
848
|
-
* dispatch(new ProcessStocksAction());
|
|
849
|
-
* let action = await store.waitAnyActionTypeFinishes([BuyAction, SellAction]);
|
|
850
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
851
|
-
* ```
|
|
852
|
-
*
|
|
853
|
-
* See also:
|
|
854
|
-
* `waitCondition` - Waits until the state is in a given condition.
|
|
855
|
-
* `waitActionCondition` - Waits until the actions in progress meet a given condition.
|
|
856
|
-
* `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
|
|
857
|
-
* `waitActionType` - Waits until an action of a given type is NOT in progress.
|
|
858
|
-
* `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
|
|
859
|
-
* `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
|
|
860
|
-
*
|
|
861
|
-
* You should only use this method in tests.
|
|
862
|
-
*/
|
|
863
|
-
async waitActionType(actionType, { completeImmediately = false, timeoutMillis = null } = {}) {
|
|
864
|
-
return this.store.waitActionType(actionType, {
|
|
865
|
-
completeImmediately: completeImmediately,
|
|
866
|
-
timeoutMillis: timeoutMillis
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* Returns a promise that completes when ALL actions of the given type are NOT in progress
|
|
871
|
-
* (none of them is being dispatched):
|
|
872
|
-
*
|
|
873
|
-
* - If NO action of the given types is currently in progress when the method is called,
|
|
874
|
-
* and `completeImmediately` is false (the default), this method will throw an error.
|
|
875
|
-
*
|
|
876
|
-
* - If NO action of the given type is currently in progress when the method is called,
|
|
877
|
-
* and `completeImmediately` is true, the promise completes immediately and throws no error.
|
|
878
|
-
*
|
|
879
|
-
* - If any action of the given types is in progress, the promise completes only when
|
|
880
|
-
* no action of the given types is in progress anymore.
|
|
881
|
-
*
|
|
882
|
-
* You may also provide a `timeoutMillis`, which by default is 10 minutes.
|
|
883
|
-
* To disable the timeout, make it 0 or -1.
|
|
884
|
-
* If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
|
|
885
|
-
*
|
|
886
|
-
* Examples:
|
|
887
|
-
*
|
|
888
|
-
* ```ts
|
|
889
|
-
* // Dispatches an actions that changes the state, then await for the state change:
|
|
890
|
-
* expect(store.state.name).toBe('John');
|
|
891
|
-
* dispatch(new ChangeNameAction("Bill"));
|
|
892
|
-
* let action = await store.waitCondition((state) => state.name == "Bill");
|
|
893
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
894
|
-
* expect(store.state.name).toBe('Bill');
|
|
895
|
-
*
|
|
896
|
-
* // Dispatches actions and wait until no actions are in progress.
|
|
897
|
-
* dispatch(new BuyAction('IBM'));
|
|
898
|
-
* dispatch(new BuyAction('TSLA'));
|
|
899
|
-
* await waitAllActions();
|
|
900
|
-
* expect(state.stocks).toEqual(['IBM', 'TSLA']);
|
|
901
|
-
*
|
|
902
|
-
* // Dispatches two actions in PARALLEL and wait for their TYPES:
|
|
903
|
-
* expect(store.state.portfolio).toEqual(['TSLA']);
|
|
904
|
-
* dispatch(new BuyAction('IBM'));
|
|
905
|
-
* dispatch(new SellAction('TSLA'));
|
|
906
|
-
* await store.waitAllActionTypes([BuyAction, SellAction]);
|
|
907
|
-
* expect(store.state.portfolio).toEqual(['IBM']);
|
|
908
|
-
*
|
|
909
|
-
* // Dispatches actions in PARALLEL and wait until no actions are in progress.
|
|
910
|
-
* dispatch(new BuyAction('IBM'));
|
|
911
|
-
* dispatch(new BuyAction('TSLA'));
|
|
912
|
-
* await store.waitAllActions();
|
|
913
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
914
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(true);
|
|
915
|
-
*
|
|
916
|
-
* // Dispatches two actions in PARALLEL and wait for them:
|
|
917
|
-
* let action1 = new BuyAction('IBM');
|
|
918
|
-
* let action2 = new SellAction('TSLA');
|
|
919
|
-
* dispatch(action1);
|
|
920
|
-
* dispatch(action2);
|
|
921
|
-
* await store.waitAllActions([action1, action2]);
|
|
922
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
923
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
924
|
-
*
|
|
925
|
-
* // Dispatches two actions in SERIES and wait for them:
|
|
926
|
-
* await dispatchAndWait(new BuyAction('IBM'));
|
|
927
|
-
* await dispatchAndWait(new SellAction('TSLA'));
|
|
928
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
929
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
930
|
-
*
|
|
931
|
-
* // Wait until some action of a given type is dispatched.
|
|
932
|
-
* dispatch(new DoALotOfStuffAction());
|
|
933
|
-
* let action = await store.waitActionType(ChangeNameAction);
|
|
934
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
935
|
-
* expect(action.status.isCompletedOk).toBe(true);
|
|
936
|
-
* expect(store.state.name).toBe('Bill');
|
|
937
|
-
*
|
|
938
|
-
* // Wait until some action of the given types is dispatched.
|
|
939
|
-
* dispatch(new ProcessStocksAction());
|
|
940
|
-
* let action = await store.waitAnyActionTypeFinishes([BuyAction, SellAction]);
|
|
941
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
942
|
-
* ```
|
|
943
|
-
*
|
|
944
|
-
* See also:
|
|
945
|
-
* `waitCondition` - Waits until the state is in a given condition.
|
|
946
|
-
* `waitActionCondition` - Waits until the actions in progress meet a given condition.
|
|
947
|
-
* `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
|
|
948
|
-
* `waitActionType` - Waits until an action of a given type is NOT in progress.
|
|
949
|
-
* `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
|
|
950
|
-
* `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
|
|
951
|
-
*
|
|
952
|
-
* You should only use this method in tests.
|
|
953
|
-
*/
|
|
954
|
-
async waitAllActionTypes(actionTypes, { completeImmediately = false, timeoutMillis = null } = {}) {
|
|
955
|
-
return this.store.waitAllActionTypes(actionTypes, {
|
|
956
|
-
completeImmediately: completeImmediately,
|
|
957
|
-
timeoutMillis: timeoutMillis
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Returns a promise which will complete when ANY action of the given types FINISHES
|
|
962
|
-
* dispatching. IMPORTANT: This method is different from the other similar methods, because
|
|
963
|
-
* it does NOT complete immediately if no action of the given types is in progress. Instead,
|
|
964
|
-
* it waits until an action of the given types finishes dispatching, even if they
|
|
965
|
-
* were not yet in progress when the method was called.
|
|
966
|
-
*
|
|
967
|
-
* This method returns the action that completed the promise, which you can use to check
|
|
968
|
-
* its `status`.
|
|
969
|
-
*
|
|
970
|
-
* It's useful when the actions you are waiting for are not yet dispatched when you call this
|
|
971
|
-
* method. For example, suppose action `StartAction` starts a process that takes some time
|
|
972
|
-
* to run and then dispatches an action called `MyFinalAction`. You can then write:
|
|
973
|
-
*
|
|
974
|
-
* ```dart
|
|
975
|
-
* dispatch(StartAction());
|
|
976
|
-
* let action = await store.waitAnyActionTypeFinishes([MyFinalAction]);
|
|
977
|
-
* expect(action.status.originalError).toBeInstanceOf(UserException>);
|
|
978
|
-
* ```
|
|
979
|
-
*
|
|
980
|
-
* You may also provide a `timeoutMillis`, which by default is 10 minutes.
|
|
981
|
-
* To disable the timeout, make it 0 or -1.
|
|
982
|
-
* If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
|
|
983
|
-
*
|
|
984
|
-
* Examples:
|
|
985
|
-
*
|
|
986
|
-
* ```ts
|
|
987
|
-
* // Dispatches an actions that changes the state, then await for the state change:
|
|
988
|
-
* expect(store.state.name).toBe('John');
|
|
989
|
-
* dispatch(new ChangeNameAction("Bill"));
|
|
990
|
-
* let action = await store.waitCondition((state) => state.name == "Bill");
|
|
991
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
992
|
-
* expect(store.state.name).toBe('Bill');
|
|
993
|
-
*
|
|
994
|
-
* // Dispatches actions and wait until no actions are in progress.
|
|
995
|
-
* dispatch(new BuyAction('IBM'));
|
|
996
|
-
* dispatch(new BuyAction('TSLA'));
|
|
997
|
-
* await waitAllActions();
|
|
998
|
-
* expect(state.stocks).toEqual(['IBM', 'TSLA']);
|
|
999
|
-
*
|
|
1000
|
-
* // Dispatches two actions in PARALLEL and wait for their TYPES:
|
|
1001
|
-
* expect(store.state.portfolio).toEqual(['TSLA']);
|
|
1002
|
-
* dispatch(new BuyAction('IBM'));
|
|
1003
|
-
* dispatch(new SellAction('TSLA'));
|
|
1004
|
-
* await store.waitAllActionTypes([BuyAction, SellAction]);
|
|
1005
|
-
* expect(store.state.portfolio).toEqual(['IBM']);
|
|
1006
|
-
*
|
|
1007
|
-
* // Dispatches actions in PARALLEL and wait until no actions are in progress.
|
|
1008
|
-
* dispatch(new BuyAction('IBM'));
|
|
1009
|
-
* dispatch(new BuyAction('TSLA'));
|
|
1010
|
-
* await store.waitAllActions();
|
|
1011
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
1012
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(true);
|
|
1013
|
-
*
|
|
1014
|
-
* // Dispatches two actions in PARALLEL and wait for them:
|
|
1015
|
-
* let action1 = new BuyAction('IBM');
|
|
1016
|
-
* let action2 = new SellAction('TSLA');
|
|
1017
|
-
* dispatch(action1);
|
|
1018
|
-
* dispatch(action2);
|
|
1019
|
-
* await store.waitAllActions([action1, action2]);
|
|
1020
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
1021
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
1022
|
-
*
|
|
1023
|
-
* // Dispatches two actions in SERIES and wait for them:
|
|
1024
|
-
* await dispatchAndWait(new BuyAction('IBM'));
|
|
1025
|
-
* await dispatchAndWait(new SellAction('TSLA'));
|
|
1026
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
1027
|
-
* expect(store.state.portfolio.includes('TSLA')).toBe(false);
|
|
1028
|
-
*
|
|
1029
|
-
* // Wait until some action of a given type is dispatched.
|
|
1030
|
-
* dispatch(new DoALotOfStuffAction());
|
|
1031
|
-
* let action = await store.waitActionType(ChangeNameAction);
|
|
1032
|
-
* expect(action instanceof ChangeNameAction).toBe(true);
|
|
1033
|
-
* expect(action.status.isCompletedOk).toBe(true);
|
|
1034
|
-
* expect(store.state.name).toBe('Bill');
|
|
1035
|
-
*
|
|
1036
|
-
* // Wait until some action of the given types is dispatched.
|
|
1037
|
-
* dispatch(new ProcessStocksAction());
|
|
1038
|
-
* let action = await store.waitAnyActionTypeFinishes([BuyAction, SellAction]);
|
|
1039
|
-
* expect(store.state.portfolio.includes('IBM')).toBe(true);
|
|
1040
|
-
* ```
|
|
1041
|
-
*
|
|
1042
|
-
* See also:
|
|
1043
|
-
* `waitCondition` - Waits until the state is in a given condition.
|
|
1044
|
-
* `waitActionCondition` - Waits until the actions in progress meet a given condition.
|
|
1045
|
-
* `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
|
|
1046
|
-
* `waitActionType` - Waits until an action of a given type is NOT in progress.
|
|
1047
|
-
* `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
|
|
1048
|
-
* `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
|
|
1049
|
-
*
|
|
1050
|
-
* You should only use this method in tests.
|
|
1051
|
-
*/
|
|
1052
|
-
async waitAnyActionTypeFinishes(actionTypes, { timeoutMillis = null } = {}) {
|
|
1053
|
-
return this.store.waitAnyActionTypeFinishes(actionTypes, {
|
|
1054
|
-
timeoutMillis: timeoutMillis
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
/**
|
|
1058
|
-
* For Kiss internal use only.
|
|
1059
|
-
*/
|
|
1060
|
-
_injectStore(_store) {
|
|
1061
|
-
this._store = _store;
|
|
1062
|
-
this._initialState = _store.state;
|
|
1063
|
-
if (!!this.retry) {
|
|
1064
|
-
this._retry = { ...this._retry, ...this.retry, on: true };
|
|
1065
|
-
this.retry = this._retry;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
/**
|
|
1069
|
-
* For Kiss internal use only.
|
|
1070
|
-
*/
|
|
1071
|
-
_changeStatus(params = {}) {
|
|
1072
|
-
this._status = this._status.copy(params);
|
|
1073
|
-
}
|
|
1074
|
-
/**
|
|
1075
|
-
* For Kiss internal use only.
|
|
1076
|
-
*/
|
|
1077
|
-
_createPromise() {
|
|
1078
|
-
return new Promise((resolve, _reject) => {
|
|
1079
|
-
this._resolve = resolve;
|
|
1080
|
-
});
|
|
1081
|
-
}
|
|
1082
|
-
/**
|
|
1083
|
-
* For Kiss internal use only.
|
|
1084
|
-
*/
|
|
1085
|
-
_resolvePromise() {
|
|
1086
|
-
// Resolves the promise created by `dispatchAndWait()`, and returns the action status.
|
|
1087
|
-
this._resolve?.(this.status);
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* Prints a readable description of the action, for debugging purposes.
|
|
1091
|
-
* Example: `MyAction(increment:10)`.
|
|
1092
|
-
*/
|
|
1093
|
-
toString() {
|
|
1094
|
-
// Initialize an array to hold key-value pairs as strings
|
|
1095
|
-
const keyValuePairs = [];
|
|
1096
|
-
for (const key of Object.keys(this)) {
|
|
1097
|
-
if (!key.startsWith('_') && (key != 'nonReentrant') && (key != 'retry') && (key != 'wrapReduce')) { // Continue to exclude base class/internal fields
|
|
1098
|
-
// For each property, push "key:value" string to the array
|
|
1099
|
-
// Note: This simple line assumes that `value` can be meaningfully represented as a string.
|
|
1100
|
-
// You might need a more complex handling for objects, arrays, etc.
|
|
1101
|
-
const value = this[key];
|
|
1102
|
-
keyValuePairs.push(`${key}:${JSON.stringify(value)}`);
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
// Join all key-value pairs with a comma and space, and format it according to your requirements
|
|
1106
|
-
return `${this.constructor.name}(${keyValuePairs.join(', ').replace(/"/g, '')})`;
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
/**
|
|
1110
|
-
* The `status` is a property of the action, used to keep track of the action's lifecycle.
|
|
1111
|
-
* If you have a reference to the action you can check its status at any time with `action.status`:
|
|
1112
|
-
*
|
|
1113
|
-
* ```ts
|
|
1114
|
-
* const action = new MyAction();
|
|
1115
|
-
* await store.dispatchAndWait(new MyAction());
|
|
1116
|
-
* if (action.isFinishedWithoutErrors) { ... }
|
|
1117
|
-
* ```
|
|
1118
|
-
*
|
|
1119
|
-
* However, `dispatchAndWait` also returns the action status after it finishes:
|
|
1120
|
-
*
|
|
1121
|
-
* ```ts
|
|
1122
|
-
* const status = await store.dispatchAndWait(new MyAction());
|
|
1123
|
-
* if (status.isFinishedWithoutErrors) { ... }
|
|
1124
|
-
* ```
|
|
1125
|
-
*/
|
|
1126
|
-
export class ActionStatus {
|
|
1127
|
-
/**
|
|
1128
|
-
* Returns true if the action was already dispatched. An action cannot be dispatched
|
|
1129
|
-
* more than once, which means that you have to create a new action each time.
|
|
1130
|
-
*
|
|
1131
|
-
* Note this may be true even if the action has not yet FINISHED dispatching.
|
|
1132
|
-
* To check if it has finished, use `action.isFinished`.
|
|
1133
|
-
*/
|
|
1134
|
-
isDispatched;
|
|
1135
|
-
/**
|
|
1136
|
-
* Is true when the `before` method finished executing normally.
|
|
1137
|
-
* Is false if it has not yet finished executing or if it threw an error.
|
|
1138
|
-
*/
|
|
1139
|
-
hasFinishedMethodBefore;
|
|
1140
|
-
/**
|
|
1141
|
-
* Is true when the `reduce` method finished executing normally, returning a value.
|
|
1142
|
-
* Is false if it has not yet finished executing or if it threw an error.
|
|
1143
|
-
*/
|
|
1144
|
-
hasFinishedMethodReduce;
|
|
1145
|
-
/**
|
|
1146
|
-
* Is true if the `after` method finished executing. Note the `after` method should
|
|
1147
|
-
* never throw any errors, but if it does the error will be swallowed and ignored.
|
|
1148
|
-
* Is false if it has not yet finished executing.
|
|
1149
|
-
*/
|
|
1150
|
-
hasFinishedMethodAfter;
|
|
1151
|
-
/**
|
|
1152
|
-
* Holds the error thrown by the action's before/reduce methods, if any.
|
|
1153
|
-
* This may or may not be equal to the error thrown by the action, because the original error
|
|
1154
|
-
* will still be processed by the action's `wrapError` and the `globalWrapError`. However,
|
|
1155
|
-
* if `originalError` is non-null, it means the reducer did not finish running.
|
|
1156
|
-
*/
|
|
1157
|
-
originalError;
|
|
1158
|
-
/**
|
|
1159
|
-
* Holds the error thrown by the action. This may or may not be the same as `originalError`,
|
|
1160
|
-
* because any errors thrown by the action's before/reduce methods may still be changed or
|
|
1161
|
-
* cancelled by the action's `wrapError` and the `globalWrapError`. This is the final error
|
|
1162
|
-
* after all these wraps.
|
|
1163
|
-
*/
|
|
1164
|
-
wrappedError;
|
|
1165
|
-
/**
|
|
1166
|
-
* Returns true only if the action has completed executing, either with or without errors.
|
|
1167
|
-
* If this is true, the 'after' method already ran.
|
|
1168
|
-
*/
|
|
1169
|
-
get isCompleted() {
|
|
1170
|
-
return this.hasFinishedMethodAfter;
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Returns true only if the action has completed, and none of the 'before' or 'reduce'
|
|
1174
|
-
* methods have thrown an error. This indicates that the 'reduce' method completed and
|
|
1175
|
-
* returned a result (even if the result was null). The 'after' method also already ran.
|
|
1176
|
-
*
|
|
1177
|
-
* This can be useful if you need to dispatch a second method only if the first method
|
|
1178
|
-
* succeeded:
|
|
1179
|
-
*
|
|
1180
|
-
* ```ts
|
|
1181
|
-
* let action = new LoadInfo();
|
|
1182
|
-
* await dispatchAndWait(action);
|
|
1183
|
-
* if (action.isCompletedOk) dispatch(new ShowInfo());
|
|
1184
|
-
* ```
|
|
1185
|
-
*
|
|
1186
|
-
* Or you can also get the state directly from `dispatchAndWait`:
|
|
1187
|
-
*
|
|
1188
|
-
* ```ts
|
|
1189
|
-
* let status = await dispatchAndWait(new LoadInfo());
|
|
1190
|
-
* if (status.isCompletedOk) dispatch(new ShowInfo());
|
|
1191
|
-
* ```
|
|
1192
|
-
*/
|
|
1193
|
-
get isCompletedOk() {
|
|
1194
|
-
return this.isCompleted && (this.originalError === null);
|
|
1195
|
-
}
|
|
1196
|
-
/**
|
|
1197
|
-
* Returns true only if the action has completed (the 'after' method already ran), but either
|
|
1198
|
-
* the 'before' or the 'reduce' methods have thrown an error. If this is true, it indicates that
|
|
1199
|
-
* the reducer could NOT complete, and could not return a value to change the state.
|
|
1200
|
-
*/
|
|
1201
|
-
get isCompletedFailed() {
|
|
1202
|
-
return this.isCompleted && (this.originalError != null);
|
|
1203
|
-
}
|
|
1204
|
-
constructor(params = {}) {
|
|
1205
|
-
this.isDispatched = params.isDispatched ?? false;
|
|
1206
|
-
this.hasFinishedMethodBefore = params.hasFinishedMethodBefore ?? false;
|
|
1207
|
-
this.hasFinishedMethodReduce = params.hasFinishedMethodReduce ?? false;
|
|
1208
|
-
this.hasFinishedMethodAfter = params.hasFinishedMethodAfter ?? false;
|
|
1209
|
-
this.originalError = params.originalError ?? null;
|
|
1210
|
-
this.wrappedError = params.wrappedError ?? null;
|
|
1211
|
-
}
|
|
1212
|
-
copy(params) {
|
|
1213
|
-
return new ActionStatus({
|
|
1214
|
-
isDispatched: params.isDispatched ?? this.isDispatched,
|
|
1215
|
-
hasFinishedMethodBefore: params.hasFinishedMethodBefore ?? this.hasFinishedMethodBefore,
|
|
1216
|
-
hasFinishedMethodReduce: params.hasFinishedMethodReduce ?? this.hasFinishedMethodReduce,
|
|
1217
|
-
hasFinishedMethodAfter: params.hasFinishedMethodAfter ?? this.hasFinishedMethodAfter,
|
|
1218
|
-
originalError: params.originalError ?? this.originalError,
|
|
1219
|
-
wrappedError: params.wrappedError ?? this.wrappedError,
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
/**
|
|
1224
|
-
* The `OptimisticUpdate` abstract class is designed to facilitate optimistic updates in your application.
|
|
1225
|
-
* This pattern can significantly enhance the user experience by immediately reflecting changes in the UI
|
|
1226
|
-
* before confirming those changes on the backend. It is particularly useful in scenarios where
|
|
1227
|
-
* you're dealing with asynchronous updates, such as saving or updating data on a remote server.
|
|
1228
|
-
*
|
|
1229
|
-
* This class provides a structured way to implement optimistic updates by defining a series of abstract
|
|
1230
|
-
* methods that you'll need to override in your subclasses. These methods include:
|
|
1231
|
-
*
|
|
1232
|
-
* - `newValue()`: Define the new value that you intend to add or update in your application state.
|
|
1233
|
-
* - `getValueFromState(state)`: Extract and return the current value from the given state.
|
|
1234
|
-
* - `applyState(value, state)`: Apply the given value to the specified state and return the updated state.
|
|
1235
|
-
* - `saveValue(newValue)`: Handle the saving of the new value to your backend or cloud service.
|
|
1236
|
-
* - `reloadValue()`: Optionally, reload the value from the backend to ensure the UI is in sync with the latest data.
|
|
1237
|
-
*
|
|
1238
|
-
* By implementing these methods, `OptimisticUpdate` helps manage the optimistic update process,
|
|
1239
|
-
* including rolling back changes if necessary. This approach allows for a smoother and more responsive
|
|
1240
|
-
* user interface, even when operations may fail or require more time to complete.
|
|
1241
|
-
*
|
|
1242
|
-
* ---
|
|
1243
|
-
*
|
|
1244
|
-
* The `OptimisticUpdate` abstract class is still EXPERIMENTAL. You can use it, but test it well.
|
|
1245
|
-
*
|
|
1246
|
-
* Let's use this example: We want to save a new TodoItem to a TodoList.
|
|
1247
|
-
*
|
|
1248
|
-
* This code saves the TodoItem, then reloads the TodoList from the cloud:
|
|
1249
|
-
*
|
|
1250
|
-
* ```typescript
|
|
1251
|
-
* class SaveTodo extends KissActionppState> {
|
|
1252
|
-
* newTodo: TodoItem;
|
|
1253
|
-
* constructor(newTodo: TodoItem) {
|
|
1254
|
-
* super();
|
|
1255
|
-
* this.newTodo = newTodo;
|
|
1256
|
-
* }
|
|
1257
|
-
*
|
|
1258
|
-
* async reduce() {
|
|
1259
|
-
*
|
|
1260
|
-
* try {
|
|
1261
|
-
* // Saves the new TodoItem to the cloud.
|
|
1262
|
-
* await saveTodoItem(this.newTodo);
|
|
1263
|
-
* } finally {
|
|
1264
|
-
* // Loads the complete TodoList from the cloud.
|
|
1265
|
-
* let reloadedTodoList = await loadTodoList();
|
|
1266
|
-
* return this.state.copy({ todoList: reloadedTodoList });
|
|
1267
|
-
* }
|
|
1268
|
-
* }
|
|
1269
|
-
* }
|
|
1270
|
-
* ```
|
|
1271
|
-
*
|
|
1272
|
-
* The problem with the above code is that it may take a second to update the TodoList on
|
|
1273
|
-
* the screen, while we save then load, which is not a good user experience.
|
|
1274
|
-
*
|
|
1275
|
-
* The solution is optimistically updating the TodoList before saving the new TodoItem to the cloud:
|
|
1276
|
-
*
|
|
1277
|
-
* ```typescript
|
|
1278
|
-
* class SaveTodo extends KissActionppState> {
|
|
1279
|
-
* newTodo: TodoItem;
|
|
1280
|
-
* constructor(newTodo: TodoItem) {
|
|
1281
|
-
* super();
|
|
1282
|
-
* this.newTodo = newTodo;
|
|
1283
|
-
* }
|
|
1284
|
-
*
|
|
1285
|
-
* async reduce() {
|
|
1286
|
-
*
|
|
1287
|
-
* // Updates the TodoList optimistically.
|
|
1288
|
-
* this.dispatch(new UpdateStateAction((state: AppState) => state.copy({ todoList: state.todoList.add(this.newTodo) })));
|
|
1289
|
-
*
|
|
1290
|
-
* try {
|
|
1291
|
-
* // Saves the new TodoItem to the cloud.
|
|
1292
|
-
* await saveTodoItem(this.newTodo);
|
|
1293
|
-
* } finally {
|
|
1294
|
-
* // Loads the complete TodoList from the cloud.
|
|
1295
|
-
* let reloadedTodoList = await loadTodoList();
|
|
1296
|
-
* this.dispatch(new UpdateStateAction((state: AppState) => state.copy({ todoList: reloadedTodoList })));
|
|
1297
|
-
* }
|
|
1298
|
-
* }
|
|
1299
|
-
* }
|
|
1300
|
-
* ```
|
|
1301
|
-
*
|
|
1302
|
-
* That's better. But if the saving fails, the users still have to wait for the reload until
|
|
1303
|
-
* they see the reverted state. We can further improve this:
|
|
1304
|
-
*
|
|
1305
|
-
* ```typescript
|
|
1306
|
-
* class SaveTodo extends KissActionppState> {
|
|
1307
|
-
* newTodo: TodoItem;
|
|
1308
|
-
* constructor(newTodo: TodoItem) {
|
|
1309
|
-
* super();
|
|
1310
|
-
* this.newTodo = newTodo;
|
|
1311
|
-
* }
|
|
1312
|
-
*
|
|
1313
|
-
* async reduce() {
|
|
1314
|
-
*
|
|
1315
|
-
* // Updates the TodoList optimistically.
|
|
1316
|
-
* let newTodoList = state.todoList.add(this.newTodo);
|
|
1317
|
-
* this.dispatch(new UpdateStateAction((state: AppState) => state.copy({ todoList: newTodoList })));
|
|
1318
|
-
*
|
|
1319
|
-
* try {
|
|
1320
|
-
* // Saves the new TodoItem to the cloud.
|
|
1321
|
-
* await saveTodoItem(this.newTodo);
|
|
1322
|
-
* } catch (e) {
|
|
1323
|
-
* // If the state still contains our optimistic update, we roll back.
|
|
1324
|
-
* // If the state now contains something else, we DO NOT roll back.
|
|
1325
|
-
* if (this.state.todoList === newTodoList) {
|
|
1326
|
-
* return state.copy({ todoList: initialState.todoList }); // Rollback.
|
|
1327
|
-
* }
|
|
1328
|
-
* } finally {
|
|
1329
|
-
* // Loads the complete TodoList from the cloud.
|
|
1330
|
-
* let reloadedTodoList = await loadTodoList();
|
|
1331
|
-
* this.dispatch(new UpdateStateAction((state: AppState) => state.copy({ todoList: reloadedTodoList })));
|
|
1332
|
-
* }
|
|
1333
|
-
* }
|
|
1334
|
-
* }
|
|
1335
|
-
* ```
|
|
1336
|
-
*
|
|
1337
|
-
* Now the user sees the rollback immediately after the saving fails.
|
|
1338
|
-
*
|
|
1339
|
-
* Note: If you are using a realtime database or WebSockets to receive real-time updates from the
|
|
1340
|
-
* server, you may not need the finally block above, as long as the `newTodoList` above can be
|
|
1341
|
-
* told apart from the current `state.todoList`. This can be a problem if the state in question
|
|
1342
|
-
* is a primitive (boolean, number, etc.) or string.
|
|
1343
|
-
*
|
|
1344
|
-
* The `OptimisticUpdate` abstract class helps you implement the above code for you when you
|
|
1345
|
-
* provide the following:
|
|
1346
|
-
*
|
|
1347
|
-
* * `newValue()`: Is the new value, that you want to see saved and applied to the state.
|
|
1348
|
-
* * `getValueFromState(state: St)`: Is a function that extracts the value from the given state.
|
|
1349
|
-
* * `reloadValue()`: Is a function that reloads the value from the cloud.
|
|
1350
|
-
* * `applyState(value: any, state: St)`: Is a function that applies the given value to the given state.
|
|
1351
|
-
*/
|
|
1352
|
-
export class OptimisticUpdate extends KissAction {
|
|
1353
|
-
async reduce() {
|
|
1354
|
-
// Updates the value optimistically.
|
|
1355
|
-
const _newValue = this.newValue();
|
|
1356
|
-
const action = new UpdateStateAction((state) => this.applyState(_newValue, state));
|
|
1357
|
-
this.dispatch(action);
|
|
1358
|
-
try {
|
|
1359
|
-
// Saves the new value to the cloud.
|
|
1360
|
-
await this.saveValue(_newValue);
|
|
1361
|
-
}
|
|
1362
|
-
catch (e) {
|
|
1363
|
-
// If the state still contains our optimistic update, we roll back.
|
|
1364
|
-
// If the state now contains something else, we DO NOT roll back.
|
|
1365
|
-
if (this.getValueFromState(this.state) === _newValue) {
|
|
1366
|
-
let initialValue = this.getValueFromState(this.initialState);
|
|
1367
|
-
return (state) => this.applyState(initialValue, state); // Rollback.
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
finally {
|
|
1371
|
-
try {
|
|
1372
|
-
let reloadedValue = await this.reloadValue();
|
|
1373
|
-
const action = new UpdateStateAction((state) => this.applyState(reloadedValue, state));
|
|
1374
|
-
this.dispatch(action);
|
|
1375
|
-
}
|
|
1376
|
-
catch (e) {
|
|
1377
|
-
// If the reload was not implemented, do nothing.
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
return null;
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
/**
|
|
1384
|
-
* The `UpdateStateAction` replaces all the store state, synchronously,
|
|
1385
|
-
* using the given `stateUpdateFunction`.
|
|
1386
|
-
*
|
|
1387
|
-
* By default, `ifPersists` is true, which means the persistor may persist
|
|
1388
|
-
* the state change.
|
|
1389
|
-
*
|
|
1390
|
-
* However, if `ifPersists` is false, the persistor will ignore this state change,
|
|
1391
|
-
* and won't persist the state change. This is useful when you read some state from
|
|
1392
|
-
* the local persistence (the device disk) and you don't want to persist it again.
|
|
1393
|
-
*/
|
|
1394
|
-
export class UpdateStateAction extends KissAction {
|
|
1395
|
-
updateFunction;
|
|
1396
|
-
ifPersists;
|
|
1397
|
-
constructor(updateFunction, ifPersists = true) {
|
|
1398
|
-
super();
|
|
1399
|
-
this.updateFunction = updateFunction;
|
|
1400
|
-
this.ifPersists = ifPersists;
|
|
1401
|
-
}
|
|
1402
|
-
reduce() {
|
|
1403
|
-
return this.updateFunction(this.state);
|
|
1404
|
-
}
|
|
1405
|
-
toString() {
|
|
1406
|
-
return `${this.constructor.name}(state)`;
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
/** The `UserException` is a special type of error that Kiss automatically
|
|
1410
|
-
* catches and shows to the user in a dialog, or other UI of your choice.
|
|
1411
|
-
*
|
|
1412
|
-
* For this to work, you must throw the `UserException` from inside an action's
|
|
1413
|
-
* `before()` or `reduce()` functions. Only then, Kiss will be able to
|
|
1414
|
-
* catch the exception and show it to the user.
|
|
1415
|
-
*
|
|
1416
|
-
* However, if you are **not** inside an action, but you still want to show an
|
|
1417
|
-
* error dialog to the user, you may use the provided `UserExceptionAction`.
|
|
1418
|
-
*
|
|
1419
|
-
* ```ts
|
|
1420
|
-
* dispatch(new UserExceptionAction('Please enter a valid number'));
|
|
1421
|
-
* ```
|
|
1422
|
-
*
|
|
1423
|
-
* This action simply throws a corresponding `UserException` from its
|
|
1424
|
-
* own `reduce()` function.
|
|
1425
|
-
*
|
|
1426
|
-
* The `UserExceptionAction` is also useful inside of actions themselves,
|
|
1427
|
-
* if you want to display an error dialog to the user, but you don't want
|
|
1428
|
-
* to interrupt the action by throwing an exception.
|
|
1429
|
-
*
|
|
1430
|
-
* For example, here an invalid number will show an error dialog to the user,
|
|
1431
|
-
* but the action will continue running and set the counter state to `0`:
|
|
1432
|
-
*
|
|
1433
|
-
* ```ts
|
|
1434
|
-
* class ConvertAction {
|
|
1435
|
-
* constructor(private text: string) {}
|
|
1436
|
-
*
|
|
1437
|
-
* reduce() {
|
|
1438
|
-
* let value = parseInt(this.text);
|
|
1439
|
-
*
|
|
1440
|
-
* if (isNaN(value)) {
|
|
1441
|
-
* dispatch(new UserExceptionAction('Please enter a valid number'));
|
|
1442
|
-
* value = 0;
|
|
1443
|
-
* }
|
|
1444
|
-
*
|
|
1445
|
-
* return { counter: value };
|
|
1446
|
-
* }
|
|
1447
|
-
* }
|
|
1448
|
-
* ```
|
|
1449
|
-
*/
|
|
1450
|
-
export class UserExceptionAction extends KissAction {
|
|
1451
|
-
message;
|
|
1452
|
-
constructor(message) {
|
|
1453
|
-
super();
|
|
1454
|
-
this.message = message;
|
|
1455
|
-
}
|
|
1456
|
-
reduce() {
|
|
1457
|
-
throw new UserException(this.message);
|
|
1458
|
-
}
|
|
1459
|
-
}
|