kiss-for-react 1.0.0

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.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +555 -0
  3. package/lib/cjs/ClassPersistor.js +112 -0
  4. package/lib/cjs/Esserializer/DeserializationOptions.js +4 -0
  5. package/lib/cjs/Esserializer/SerializeOptions.js +4 -0
  6. package/lib/cjs/Esserializer/constant.js +131 -0
  7. package/lib/cjs/Esserializer/deserializer.js +313 -0
  8. package/lib/cjs/Esserializer/general.js +39 -0
  9. package/lib/cjs/Esserializer/index.js +43 -0
  10. package/lib/cjs/Esserializer/serializer.js +133 -0
  11. package/lib/cjs/Hooks.js +969 -0
  12. package/lib/cjs/KissAction.js +1268 -0
  13. package/lib/cjs/Persistor.js +120 -0
  14. package/lib/cjs/ProcessPersistence.js +262 -0
  15. package/lib/cjs/Store.js +1534 -0
  16. package/lib/cjs/StoreException.js +75 -0
  17. package/lib/cjs/UnmodifiableSetView.js +53 -0
  18. package/lib/cjs/UserException.js +218 -0
  19. package/lib/cjs/Wait.js +309 -0
  20. package/lib/cjs/index.js +42 -0
  21. package/lib/cjs/types/ClassPersistor.d.ts +113 -0
  22. package/lib/cjs/types/ClassPersistor.d.ts.map +1 -0
  23. package/lib/cjs/types/Esserializer/DeserializationOptions.d.ts +7 -0
  24. package/lib/cjs/types/Esserializer/DeserializationOptions.d.ts.map +1 -0
  25. package/lib/cjs/types/Esserializer/SerializeOptions.d.ts +6 -0
  26. package/lib/cjs/types/Esserializer/SerializeOptions.d.ts.map +1 -0
  27. package/lib/cjs/types/Esserializer/constant.d.ts +50 -0
  28. package/lib/cjs/types/Esserializer/constant.d.ts.map +1 -0
  29. package/lib/cjs/types/Esserializer/deserializer.d.ts +18 -0
  30. package/lib/cjs/types/Esserializer/deserializer.d.ts.map +1 -0
  31. package/lib/cjs/types/Esserializer/general.d.ts +5 -0
  32. package/lib/cjs/types/Esserializer/general.d.ts.map +1 -0
  33. package/lib/cjs/types/Esserializer/index.d.ts +30 -0
  34. package/lib/cjs/types/Esserializer/index.d.ts.map +1 -0
  35. package/lib/cjs/types/Esserializer/serializer.d.ts +4 -0
  36. package/lib/cjs/types/Esserializer/serializer.d.ts.map +1 -0
  37. package/lib/cjs/types/Hooks.d.ts +838 -0
  38. package/lib/cjs/types/Hooks.d.ts.map +1 -0
  39. package/lib/cjs/types/KissAction.d.ts +1324 -0
  40. package/lib/cjs/types/KissAction.d.ts.map +1 -0
  41. package/lib/cjs/types/Persistor.d.ts +119 -0
  42. package/lib/cjs/types/Persistor.d.ts.map +1 -0
  43. package/lib/cjs/types/ProcessPersistence.d.ts +100 -0
  44. package/lib/cjs/types/ProcessPersistence.d.ts.map +1 -0
  45. package/lib/cjs/types/Store.d.ts +1043 -0
  46. package/lib/cjs/types/Store.d.ts.map +1 -0
  47. package/lib/cjs/types/StoreException.d.ts +29 -0
  48. package/lib/cjs/types/StoreException.d.ts.map +1 -0
  49. package/lib/cjs/types/UnmodifiableSetView.d.ts +24 -0
  50. package/lib/cjs/types/UnmodifiableSetView.d.ts.map +1 -0
  51. package/lib/cjs/types/UserException.d.ts +170 -0
  52. package/lib/cjs/types/UserException.d.ts.map +1 -0
  53. package/lib/cjs/types/Wait.d.ts +1 -0
  54. package/lib/cjs/types/Wait.d.ts.map +1 -0
  55. package/lib/cjs/types/index.d.ts +10 -0
  56. package/lib/cjs/types/index.d.ts.map +1 -0
  57. package/lib/cjs/types/utils.d.ts +2 -0
  58. package/lib/cjs/types/utils.d.ts.map +1 -0
  59. package/lib/cjs/utils.js +7 -0
  60. package/lib/esm/ClassPersistor.js +112 -0
  61. package/lib/esm/Esserializer/DeserializationOptions.js +3 -0
  62. package/lib/esm/Esserializer/SerializeOptions.js +3 -0
  63. package/lib/esm/Esserializer/constant.js +81 -0
  64. package/lib/esm/Esserializer/deserializer.js +307 -0
  65. package/lib/esm/Esserializer/general.js +34 -0
  66. package/lib/esm/Esserializer/index.js +39 -0
  67. package/lib/esm/Esserializer/serializer.js +130 -0
  68. package/lib/esm/Hooks.js +955 -0
  69. package/lib/esm/KissAction.js +1368 -0
  70. package/lib/esm/Persistor.js +113 -0
  71. package/lib/esm/ProcessPersistence.js +262 -0
  72. package/lib/esm/Store.js +1606 -0
  73. package/lib/esm/StoreException.js +69 -0
  74. package/lib/esm/UnmodifiableSetView.js +50 -0
  75. package/lib/esm/UserException.js +246 -0
  76. package/lib/esm/Wait.js +309 -0
  77. package/lib/esm/index.mjs +9 -0
  78. package/lib/esm/types/ClassPersistor.d.ts +113 -0
  79. package/lib/esm/types/ClassPersistor.d.ts.map +1 -0
  80. package/lib/esm/types/Esserializer/DeserializationOptions.d.ts +7 -0
  81. package/lib/esm/types/Esserializer/DeserializationOptions.d.ts.map +1 -0
  82. package/lib/esm/types/Esserializer/SerializeOptions.d.ts +6 -0
  83. package/lib/esm/types/Esserializer/SerializeOptions.d.ts.map +1 -0
  84. package/lib/esm/types/Esserializer/constant.d.ts +50 -0
  85. package/lib/esm/types/Esserializer/constant.d.ts.map +1 -0
  86. package/lib/esm/types/Esserializer/deserializer.d.ts +18 -0
  87. package/lib/esm/types/Esserializer/deserializer.d.ts.map +1 -0
  88. package/lib/esm/types/Esserializer/general.d.ts +5 -0
  89. package/lib/esm/types/Esserializer/general.d.ts.map +1 -0
  90. package/lib/esm/types/Esserializer/index.d.ts +30 -0
  91. package/lib/esm/types/Esserializer/index.d.ts.map +1 -0
  92. package/lib/esm/types/Esserializer/serializer.d.ts +4 -0
  93. package/lib/esm/types/Esserializer/serializer.d.ts.map +1 -0
  94. package/lib/esm/types/Hooks.d.ts +838 -0
  95. package/lib/esm/types/Hooks.d.ts.map +1 -0
  96. package/lib/esm/types/KissAction.d.ts +1324 -0
  97. package/lib/esm/types/KissAction.d.ts.map +1 -0
  98. package/lib/esm/types/Persistor.d.ts +119 -0
  99. package/lib/esm/types/Persistor.d.ts.map +1 -0
  100. package/lib/esm/types/ProcessPersistence.d.ts +100 -0
  101. package/lib/esm/types/ProcessPersistence.d.ts.map +1 -0
  102. package/lib/esm/types/Store.d.ts +1043 -0
  103. package/lib/esm/types/Store.d.ts.map +1 -0
  104. package/lib/esm/types/StoreException.d.ts +29 -0
  105. package/lib/esm/types/StoreException.d.ts.map +1 -0
  106. package/lib/esm/types/UnmodifiableSetView.d.ts +24 -0
  107. package/lib/esm/types/UnmodifiableSetView.d.ts.map +1 -0
  108. package/lib/esm/types/UserException.d.ts +170 -0
  109. package/lib/esm/types/UserException.d.ts.map +1 -0
  110. package/lib/esm/types/Wait.d.ts +1 -0
  111. package/lib/esm/types/Wait.d.ts.map +1 -0
  112. package/lib/esm/types/index.d.ts +10 -0
  113. package/lib/esm/types/index.d.ts.map +1 -0
  114. package/lib/esm/types/utils.d.ts +2 -0
  115. package/lib/esm/types/utils.d.ts.map +1 -0
  116. package/lib/esm/utils.js +3 -0
  117. package/package.json +87 -0
@@ -0,0 +1,1043 @@
1
+ import React from 'react';
2
+ import { UserException } from './UserException';
3
+ import { Persistor } from './Persistor';
4
+ import { ActionStatus, KissAction } from './KissAction';
5
+ interface ConstructorParams<St> {
6
+ /**
7
+ * The initial state of the app.
8
+ */
9
+ initialState: St;
10
+ /**
11
+ * Kiss calls this function automatically when actions throw `UserException`s, so that
12
+ * they can be shown to the user. Usually, this function opens some UI like a dialog or a toast,
13
+ * with the error message.
14
+ *
15
+ * The `count` parameter is the number of exceptions still in the queue.
16
+ *
17
+ * You should explicitly call `next` function when the user is ready to see the next exception
18
+ * in the queue, when the user dismisses the dialog or toast. If there are no more exceptions,
19
+ * `next` will do nothing. Otherwise, it will call `showUserException` again. Example:
20
+ *
21
+ * ```ts
22
+ * const showUserException: UserExceptionDialog =
23
+ * (exception, count, next) => {
24
+ * Alert.alert(
25
+ * exception.title || exception.message,
26
+ * exception.title ? exception.message : '',
27
+ * [{ text: 'OK', onPress: (_value?: string) => next() }]
28
+ * );
29
+ * };
30
+ * ```
31
+ */
32
+ showUserException?: (exception: UserException, count: number, next: () => void) => void;
33
+ /**
34
+ * The persistor saves and retrieves the application's state from the local device storage,
35
+ * ensuring data persistence across app restarts. Without a defined persistor, the app's state
36
+ * will not be saved.
37
+ *
38
+ * The `Persistor` is an abstract base class, allowing developers to easily craft their custom
39
+ * persistors. Kiss makes it easy, by automatically invoking the persistor upon any state
40
+ * modification, and passing it the information that needs to be saved as well as the last saved
41
+ * state.
42
+ *
43
+ * Kiss also offers a built-in `ClassPersistor` that can be used to persist the state by
44
+ * serializing it to a string and saving it to the local device storage.
45
+ */
46
+ persistor?: Persistor<St>;
47
+ /**
48
+ * The `logger` is a function that Kiss uses when it calls `Store.log()`
49
+ * to log information. It's set up during the creation of the store. For example:
50
+ *
51
+ * ```ts
52
+ * const store = new Store<State>({
53
+ * initialState: new State(),
54
+ * logger: (obj: any) => process.stdout.write(obj + '\n');
55
+ * });
56
+ * ```
57
+ *
58
+ * Or using a logger library:
59
+ *
60
+ * ```ts
61
+ * import { Logger } from 'my-logger-library';
62
+ *
63
+ * const store = new Store<State>({
64
+ * initialState: new State(),
65
+ * logger: (obj: any) => Logger.log(obj);
66
+ * });
67
+ * ```
68
+ *
69
+ * Note, if you don't define a logger yourself, the default is to print
70
+ * the log messages to the console with `console.log()`.
71
+ *
72
+ * This is how you may completely disable the default logger:
73
+ *
74
+ * ```ts
75
+ * const store = new Store<State>({
76
+ * initialState: new State(),
77
+ * logger: (obj: any) => {}
78
+ * });
79
+ * ```
80
+ */
81
+ logger: (obj: any) => void;
82
+ /**
83
+ * If `true`, will use Store.log() to log all state changes.
84
+ * It uses `Store.describeStateChange()` to create the description of those changes.
85
+ *
86
+ * Note this is true (turned on) by default, as it may be useful for development, testing and
87
+ * debugging. Be sure to turn it off in production, as it may slow down your application:
88
+ *
89
+ * ```ts
90
+ * // In production
91
+ * const store = new Store<State>({
92
+ * initialState: new State(),
93
+ * logStateChanges: false,
94
+ * });
95
+ * ```
96
+ */
97
+ logStateChanges: boolean;
98
+ /**
99
+ * Global function to wrap errors.
100
+ *
101
+ * This `globalWrapError` will be given all errors thrown in your actions, including those
102
+ * of type `UserException`. If and action already has a `wrapError` method, that method will
103
+ * be called first, and then the `globalWrapError` will be called with the result.
104
+ *
105
+ * A common use case for this is to have a global place to convert some exceptions into
106
+ * `UserException`s. For example, Firebase may throw some `PlatformExceptions` in response to
107
+ * a bad connection to the server. In this case, you may want to show the user a dialog
108
+ * explaining that the connection is bad, which you can do by converting it to a `UserException`.
109
+ * While this could also be done in the action's `wrapError`, you'd have to add it to all
110
+ * actions that use Firebase.
111
+ *
112
+ * IMPORTANT: If instead of RETURNING an error you throw an error inside the `globalWrapError`
113
+ * function, Kiss will catch this error and use it instead the original error. In other
114
+ * words, returning an error or throwing an error works the same way. But it's recommended that
115
+ * you return the error instead of throwing it anyway.
116
+ *
117
+ * Note: Don't use the `globalWrapError` to log errors, as you should prefer doing that
118
+ * in the `errorObserver`.
119
+ */
120
+ globalWrapError?: (error: any) => any;
121
+ /**
122
+ * An `actionObserver` can be set during the `Store` creation.
123
+ * It's called whenever actions are dispatched, and also when they finish.
124
+ * The action and the dispatch-count are available, as well as the `ini` parameter:
125
+ * If `ini` is true, this is right before the action is dispatched.
126
+ * If `ini` is false, this is right after the action finishes.
127
+ *
128
+ * The `actionObserver` is a good place to log which actions are dispatched by your application.
129
+ * For example, the following code logs actions to the console in development or test mode.
130
+ * and logs actions to Crashlytics in production mode:
131
+ *
132
+ * ```ts
133
+ * actionObserver: (action, dispatchCount, ini) => {
134
+ * if (inDevelopment() || inTests()) {
135
+ * if (ini) console.log('Action dispatched: ' + action);
136
+ * else console.log('Action finished: ' + action);
137
+ * }
138
+ * else Crashlytics.log('Dispatched: ' + action);
139
+ * }
140
+ * ```
141
+ */
142
+ actionObserver?: (action: KissAction<St>, dispatchCount: number, ini: boolean) => void;
143
+ /**
144
+ * A `stateObserver`s can be set during the `Store` creation.
145
+ * It's called for all dispatched actions, right after the reducer returns, before
146
+ * the action's `after()` method, before the action's `wrapError()`, and before
147
+ * the `globalWrapError()`.
148
+ *
149
+ * The parameters are:
150
+ *
151
+ * - action = The action itself.
152
+ *
153
+ * - prevState = The state right before the new state returned by the reducer is applied. Note
154
+ * this may be different from the state when the action was dispatched.
155
+ *
156
+ * - newState = The state returned by the reducer. Note: If you need to know if the state was
157
+ * changed or not by the reducer, you can compare both states:
158
+ * `let ifStateChanged = prevState !== newState;`
159
+ *
160
+ * - error = Is null if the action completed with no error. Otherwise, will be the error thrown
161
+ * by the reducer (before any wrapError is applied). Note that, in case of error, both
162
+ * `prevState` and `newState` will be the current store state when the error was thrown.
163
+ *
164
+ * - dispatchCount = The sequential number of the dispatch.
165
+ *
166
+ * <br>
167
+ *
168
+ * The state-observer is a good place to add an interface to the Redux DevTools.
169
+ * It's also a good place to add METRICS to your application. For example:
170
+ *
171
+ * ```ts
172
+ * function stateObserver(action, prevState, newState, error, dispatchCount) {
173
+ * saveMetrics(action, newState, error);
174
+ * }
175
+ * ```
176
+ *
177
+ * An interesting idea is to add a method to the Action base class called `setMetrics`, that
178
+ * allows actions to return tailored custom metrics about the action, and then use it in the
179
+ * state-observer to track those metrics. For example:
180
+ *
181
+ * ```ts
182
+ * class LoadUser extends Action {
183
+ * async reduce() {
184
+ * let user = await loadUser();
185
+ * this.log('User', user.id); // Here!
186
+ * return (state) => state.copy(user: user);
187
+ * }
188
+ * }
189
+ *
190
+ * stateObserver: (action, prevState, newState, error, dispatchCount) => {
191
+ * let actionLog = action.getLog(); // Here!
192
+ * saveMetrics(action, actionLog, newState, error);
193
+ * }
194
+ * ```
195
+ */
196
+ stateObserver?: (action: KissAction<St>, prevState: St, newState: St, error: any, dispatchCount: number) => void;
197
+ /**
198
+ * An `errorObserver` can be set during the `Store` creation.
199
+ * This will be given all errors that survive the action's `wrapError` and the `globalWrapError`,
200
+ * including those of type `UserException`.
201
+ *
202
+ * You also get the `action` and a reference to the `store`. IMPORTANT: Don't use the store to
203
+ * dispatch any actions, as this may have unpredictable results.
204
+ *
205
+ * The `errorObserver` is the ideal place to log errors, as you have all the information you may
206
+ * need, including the `action` that dispatched the error, which you can use to log the action
207
+ * name, as well as any action properties you may find interesting.
208
+ *
209
+ * After you log the error, you may then return `true` to let the error throw,
210
+ * or `false` to swallow it.
211
+ *
212
+ * For example, if you want to disable all errors in production, but log them;
213
+ * and you want to throw all errors during development and tests, this is how you can do it:
214
+ *
215
+ * ```
216
+ * errorObserver: (error, action) {
217
+ *
218
+ * // In development, we throw the error so that we can see it in the emulator/console.
219
+ * if (inDevelopment() || inTests() || (error instanceof UserException)) return true;
220
+ *
221
+ * // In production, we log the error, and swallow it.
222
+ * else {
223
+ * Logger.error(`Got ${error} in action ${action}.`);
224
+ * return false;
225
+ * }
226
+ * }
227
+ * ```
228
+ */
229
+ errorObserver?: (error: any, action: KissAction<St>, store: Store<St>) => boolean;
230
+ }
231
+ /**
232
+ * The store holds the state of the application and allows the state to be updated
233
+ * by dispatching actions. The store is also responsible for showing user exceptions
234
+ * to the user, persisting the state to the local device disk, processing wait states
235
+ * to show spinners while async operations are in progress, and more.
236
+ *
237
+ * You can create a store with `const store = createStore()` or `const store = new Store()`.
238
+ */
239
+ export declare function createStore<St>(params: ConstructorParams<St>): Store<St>;
240
+ declare class RefState<St, T> {
241
+ selectorAndValueAndSetValue: [(state: St) => T, T, React.Dispatch<React.SetStateAction<T>>];
242
+ constructor(selectorAndValueAndSetValue: [(state: St) => T, T, React.Dispatch<React.SetStateAction<T>>]);
243
+ }
244
+ declare class RefStore<St, T> {
245
+ selectorAndValueAndSetValue: [(store: Store<St>) => T, T, React.Dispatch<React.SetStateAction<T>>];
246
+ constructor(selectorAndValueAndSetValue: [(store: Store<St>) => T, T, React.Dispatch<React.SetStateAction<T>>]);
247
+ }
248
+ /**
249
+ * The store holds the state of the application and allows the state to be updated
250
+ * by dispatching actions. The store is also responsible for showing user exceptions
251
+ * to the user, persisting the state to the local device disk, processing wait states
252
+ * to show spinners while async operations are in progress, and more.
253
+ *
254
+ * You can create a store with `const store = createStore()` or `const store = new Store()`.
255
+ */
256
+ export declare class Store<St> {
257
+ _refStateHooks: Set<React.MutableRefObject<RefState<St, any> | undefined>>;
258
+ _refStoreHooks: Set<React.MutableRefObject<RefStore<St, any> | undefined>>;
259
+ private _rebuildFromStateHooks;
260
+ private _rebuildFromStoreHooks;
261
+ /**
262
+ * The `Store.log()` is a static function that Kiss uses internally to log information.
263
+ * If you want, you can also use it yourself, like this:
264
+ *
265
+ * ```ts
266
+ * Store.log('Some information: ' + someVariable);
267
+ * ```
268
+ *
269
+ * The log function is set during the creation of the store,
270
+ * using the `logger` constructor parameter. For example:
271
+ *
272
+ * ```ts
273
+ * const store = new Store<State>({
274
+ * initialState: new State(),
275
+ * logger: (obj: any) => process.stdout.write(obj + '\n');
276
+ * });
277
+ * ```
278
+ *
279
+ * Or using a logger library:
280
+ *
281
+ * ```ts
282
+ * import { Logger } from 'my-logger-library';
283
+ *
284
+ * const store = new Store<State>({
285
+ * initialState: new State(),
286
+ * logger: (obj: any) => Logger.log(obj);
287
+ * });
288
+ * ```
289
+ *
290
+ * Note, if you don't define a logger yourself, the default is to print
291
+ * the log messages to the console with `console.log()`.
292
+ *
293
+ * This is how you may completely disable the default logger:
294
+ *
295
+ * ```ts
296
+ * const store = new Store<State>({
297
+ * initialState: new State(),
298
+ * logger: (obj: any) => {};
299
+ * });
300
+ * ```
301
+ */
302
+ static log: (obj: any) => void;
303
+ private _state;
304
+ private _shutDown;
305
+ /**
306
+ * Set this to `true` when you want to abort any new actions that are dispatched.
307
+ * Note this will not stop async actions already running,
308
+ * but you can wait for them to finish:
309
+ *
310
+ * ```ts
311
+ * await store.waitAllActions(null, {
312
+ * timeoutMillis: 5000,
313
+ * completeImmediately: true
314
+ * }).catch((error) => { });
315
+ * ```
316
+ *
317
+ * Set this back to `false` to restart the store accepting new action dispatches.
318
+ */
319
+ setShutDown(shutDown: boolean): void;
320
+ /**
321
+ * A queue of errors of type UserException, thrown by actions.
322
+ * They are shown to the user using the function `showUserException`.
323
+ * This is public if you need it for advanced stuff, but you should probably not touch it.
324
+ */
325
+ readonly userExceptionsQueue: UserException[];
326
+ /**
327
+ * If `true`, will use Store.log() to log all state changes.
328
+ * It uses `Store.describeStateChange()` to create the description of those changes.
329
+ *
330
+ * Note this is true (turned on) by default, as it may be useful for development, testing and
331
+ * debugging. Be sure to turn it off in production, as it may slow down your application:
332
+ *
333
+ * ```ts
334
+ * // In production
335
+ * const store = new Store<State>({
336
+ * initialState: new State(),
337
+ * logStateChanges: false,
338
+ * });
339
+ * ```
340
+ */
341
+ private readonly _logStateChanges;
342
+ /**
343
+ * The async actions that are currently being processed.
344
+ * Use `isWaiting` to know if an action is currently being processed.
345
+ */
346
+ private readonly _actionsInProgress;
347
+ /**
348
+ * Async actions that we may put into `_asyncActionsInProgress`.
349
+ * This helps to know when to rebuild to make `isWaiting` work.
350
+ */
351
+ private readonly _awaitableActions;
352
+ /**
353
+ * The actions that have failed recently.
354
+ * When an action fails by throwing an `UserException`, it's added to this map
355
+ * (indexed by its action type), and then removed when it's dispatched.
356
+ *
357
+ * Use `isFailed`, `exceptionFor` and `clearExceptionFor` to know if you should display
358
+ * some error message due to an action failure.
359
+ *
360
+ * Note: Throwing an `UserException` can show a modal dialog to the user, and also show the error
361
+ * as a message in the UI. If you don't want to show the dialog you can use the `noDialog`
362
+ * getter in the error message: `throw UserException('Invalid input').noDialog`.
363
+ */
364
+ private readonly _failedActions;
365
+ /**
366
+ * Async actions that we may put into `_failedActions`.
367
+ * This helps to know when to rebuild to make `isWaiting` work.
368
+ */
369
+ private readonly _actionsWeCanCheckFailed;
370
+ /**
371
+ * Helps implement the waitCondition method.
372
+ */
373
+ private _waitConditions;
374
+ /**
375
+ * Helps implement the `waitActionCondition` method.
376
+ */
377
+ private _waitActionConditions;
378
+ private readonly _processPersistence;
379
+ private _dispatchCount;
380
+ private readonly _showUserException;
381
+ private readonly _globalWrapError?;
382
+ private readonly _actionObserver?;
383
+ private readonly _stateObserver?;
384
+ private readonly _errorObserver?;
385
+ /**
386
+ * You can use `store.mocks` to mock actions. You should use this for testing purposes, only.
387
+ *
388
+ * To mock actions and their reducers, use `store.mocks.add(actionType, mockFunction)`
389
+ * multiple times, one for each **action type** you want to mock.
390
+ *
391
+ * By adding mocks to the store, the `mockFunction` will be called
392
+ * to return a mocked action that will be used instead of the original actions, when dispatching.
393
+ * You can mock an action to return a specific state, to throw an error,
394
+ * or even to abort the action.
395
+ *
396
+ * Usage:
397
+ *
398
+ * - `store.mocks.add(actionType, (actionType) => mockAction)`:
399
+ * Adds a mock action to the store. Whenever an action of type `actionType` is
400
+ * dispatched, `mockAction` will be dispatched instead. If you pass `mockAction` as null,
401
+ * actions of type `actionType` will be ignored when dispatched.
402
+ *
403
+ * - `remove(actionType)`:
404
+ * Removes remove a mock action from the store. Note you should pass the
405
+ * type of the action that was mocked, and NOT the type of the mock.
406
+ *
407
+ * - `clear()`:
408
+ * Removes all mock actions from the store.
409
+ *
410
+ * Examples:
411
+ *
412
+ * ```ts
413
+ * // When an IncrementAction is dispatched, AddAction(1) will be dispatched instead.
414
+ * store.mocks.add(IncrementAction, (action) => new AddAction(1));
415
+ *
416
+ * // When an IncrementAction is dispatched, it will be ignored.
417
+ * store.mocks.add(IncrementAction, null);
418
+ *
419
+ * // Removes the mock for Increment.
420
+ * store.mocks.remove(Increment);
421
+ *
422
+ * // Removes all mocks.
423
+ * store.mocks.clear();
424
+ *
425
+ * // When an AddAction is dispatched, the value will be subtracted instead.
426
+ * store.mocks.add(AddAction, (action) => new AddAction(-action.value));
427
+ * ```ts
428
+ */
429
+ mocks: Mocks<St>;
430
+ readonly record: {
431
+ isRecording: boolean;
432
+ changes: {
433
+ action: KissAction<St>;
434
+ ini: boolean;
435
+ prevState: St;
436
+ newState: St;
437
+ error: any;
438
+ dispatchCount: number;
439
+ }[];
440
+ start: () => void;
441
+ stop: () => void;
442
+ result: () => {
443
+ action: KissAction<St>;
444
+ ini: boolean;
445
+ prevState: St;
446
+ newState: St;
447
+ error: any;
448
+ dispatchCount: number;
449
+ }[];
450
+ toString: () => string;
451
+ };
452
+ private _defaultLogger;
453
+ private _defaultShowUserException;
454
+ constructor({ initialState, showUserException, persistor, globalWrapError, actionObserver, stateObserver, errorObserver, logger, logStateChanges, }: ConstructorParams<St>);
455
+ get state(): St;
456
+ get dispatchCount(): number;
457
+ /**
458
+ * Dispatches the action to the Redux store, to potentially change the state.
459
+ *
460
+ * See also:
461
+ * - `dispatchAll` which dispatches all given actions in parallel.
462
+ * - `dispatchSync` which dispatches sync actions, and throws if the action is async.
463
+ * - `dispatchAndWait` which dispatches both sync and async actions, and returns a Promise.
464
+ * - `dispatchAndWaitAll` which dispatches all given actions, and returns a Promise.
465
+ */
466
+ dispatch(action: KissAction<St>): void;
467
+ /**
468
+ * Dispatches an action and returns a promise that resolves when the action finishes.
469
+ * While the state change from the action's reducer will have been applied when the promise
470
+ * resolves, other independent processes that the action may have started may still be in
471
+ * progress.
472
+ *
473
+ * Usage: `await store.dispatchAndWait(new MyAction())`.
474
+ *
475
+ * See also:
476
+ * - `dispatch` which dispatches both sync and async actions.
477
+ * - `dispatchSync` which dispatches sync actions, and throws if the action is async.
478
+ * - `dispatchAll` which dispatches all given actions in parallel.
479
+ * - `dispatchAndWaitAll` which dispatches all given actions, and returns a Promise.
480
+ */
481
+ dispatchAndWait(action: KissAction<St>): Promise<ActionStatus>;
482
+ /**
483
+ * Dispatches all given actions in parallel, applying their reducers, and possibly changing
484
+ * the store state. The actions may be sync or async. It returns a Promise that resolves when
485
+ * ALL actions finish.
486
+ *
487
+ * ```ts
488
+ * let actions = await store.dispatchAndWaitAll([new BuyAction('IBM'), new SellAction('TSLA')]);
489
+ * ```
490
+ *
491
+ * Note this is exactly the same as doing:
492
+ *
493
+ * ```ts
494
+ * let action1 = new BuyAction('IBM');
495
+ * let action2 = new SellAction('TSLA');
496
+ * store.dispatch(action1);
497
+ * store.dispatch(action2);
498
+ * await store.waitAllActions([action1, action2], true);
499
+ * let actions = [action1, action2];
500
+ * ```
501
+ *
502
+ * Note: While the state change from the action's reducers will have been applied when the
503
+ * Promise resolves, other independent processes that the action may have started may still
504
+ * be in progress.
505
+ *
506
+ * See also:
507
+ * - `dispatch` which dispatches both sync and async actions.
508
+ * - `dispatchAndWait` which dispatches both sync and async actions, and returns a Promise.
509
+ * - `dispatchSync` which dispatches sync actions, and throws if the action is async.
510
+ * - `dispatchAll` which dispatches all given actions in parallel.
511
+ */
512
+ dispatchAndWaitAll(actions: KissAction<St>[]): Promise<KissAction<St>[]>;
513
+ /**
514
+ * Dispatches all given actions in parallel, applying their reducer, and possibly changing
515
+ * the store state. It returns the same list of actions, so that you can instantiate them
516
+ * inline, but still get a list of them.
517
+ *
518
+ * ```ts
519
+ * let actions = store.dispatchAll([new BuyAction('IBM'), new SellAction('TSLA')]);
520
+ * ```
521
+ *
522
+ * See also:
523
+ * - `dispatch` which dispatches both sync and async actions.
524
+ * - `dispatchAndWait` which dispatches both sync and async actions, and returns a Promise.
525
+ * - `dispatchAndWaitAll` which dispatches all given actions, and returns a Promise.
526
+ * - `dispatchSync` which dispatches sync actions, and throws if the action is async. */
527
+ dispatchAll(actions: KissAction<St>[]): KissAction<St>[];
528
+ /**
529
+ * Dispatches the given action to the Redux store, to potentially change the state.
530
+ *
531
+ * This is exactly the same as the regular `dispatch`, except for the fact it
532
+ * will throw a `StoreException` if the action is ASYNC. Note an action is ASYNC
533
+ * if any of its `reduce()` or `before()` methods return a Promise.
534
+ *
535
+ * The only use for `dispatchSync` is when you need to guarantee (in runtime) that your
536
+ * action is SYNC, which means the state gets changed right after the dispatch call.
537
+ *
538
+ * See also:
539
+ * - `dispatch` which dispatches both sync and async actions.
540
+ * - `dispatchAndWait` which dispatches both sync and async actions, and returns a Promise.
541
+ * - `dispatchAndWaitAll` which dispatches all given actions, and returns a Promise.
542
+ * - `dispatchAll` which dispatches all given actions in parallel.
543
+ */
544
+ dispatchSync(action: KissAction<St>): void;
545
+ private _mockActionOrNot;
546
+ private _processDispatch;
547
+ _calculateIsWaitingIsFailed(action: KissAction<St>): void;
548
+ private _wraps;
549
+ private _wrapsAsync;
550
+ private _processWrapsError;
551
+ private _processWrapsFinally;
552
+ private _checkAllActionConditions;
553
+ private _runFromStart;
554
+ private _retryWrapReduce;
555
+ private _record;
556
+ private _runAsyncBeforeOnwards;
557
+ private _runAsyncReduceOnwards;
558
+ private _isFunction;
559
+ private _registerState;
560
+ /**
561
+ * For this to work, we have to pass a function `showUserException` in the constructor
562
+ * of the Store, that will open some UI to show the error to the user.
563
+ *
564
+ * 1) If the UI is still open, don't do anything.
565
+ * 2) If no UI is open, check to see if any errors are in the queue.
566
+ * If so, remove the first error from the queue and show it in the UI.
567
+ * 3) In this case, we mark the UI as open, and count the number of errors still in the queue.
568
+ * 4) When the UI calls `next()`, we mark the UI as closed, and call the method again, to
569
+ * process the next error in the queue, if any.
570
+ *
571
+ * IMPORTANT: Failing to call `next()` will prevent the UI to ever opening again, because
572
+ * Kiss will think the previous UI is still open. In contrast, calling `next()` as soon
573
+ * as the UI opens may result in opening more than one UI on top pf each other.
574
+ * Also, calling `next()` when there are no more errors in the queue will do nothing.
575
+ *
576
+ * An example using React Native:
577
+ *
578
+ * ```ts
579
+ * const showUserException = (exception: UserException, next: () => void) => {
580
+ * Alert.alert(
581
+ * exception.title || exception.message,
582
+ * exception.title ? exception.message : '',
583
+ * [{ text: 'OK', onPress: (_value?: string) => next() }]
584
+ * );
585
+ * };
586
+ * ```
587
+ */
588
+ private _openSomeUiToShowUserException;
589
+ private _isUserExceptionUiOpen;
590
+ private _addUserException;
591
+ /**
592
+ * You can use `isWaiting` and pass it an action `type`:
593
+ * - It returns true if an ASYNC action of the specific type is currently being processed.
594
+ * - It returns false if an ASYNC action of the specific type is NOT currently being processed.
595
+ * - This is only useful for ASYNC actions, since it always returns `false` when the action is SYNC.
596
+ *
597
+ * Note an action is ASYNC if it returns a promise from its `before` OR its `reduce` methods.
598
+ *
599
+ * ```ts
600
+ * dispatch(MyAction());
601
+ * if (store.isWaiting(MyAction)) { // Show a spinner } *
602
+ * ```
603
+ */
604
+ isWaiting<T extends KissAction<St>>(type: {
605
+ new (...args: any[]): T;
606
+ }): boolean;
607
+ /**
608
+ * Returns true if the given action `type` failed with an `UserException`.
609
+ * Note: This method uses the EXACT action type. Subtypes are not considered.
610
+ */
611
+ isFailed<T extends KissAction<any>>(type: {
612
+ new (...args: any[]): T;
613
+ }): boolean;
614
+ /**
615
+ * Returns the `UserException` of the `type` that failed.
616
+ * Note: This method uses the EXACT type in `type`. Subtypes are not considered.
617
+ */
618
+ exceptionFor<T extends KissAction<St>>(type: {
619
+ new (...args: any[]): T;
620
+ }): (UserException | null);
621
+ /**
622
+ * Removes the exact given action `type` from the list of action types that failed.
623
+ * Note it clears the EXACT given type. Subtypes are not considered.
624
+ *
625
+ * Even if you never call this method explicitly, just dispatching an action already clears that action type
626
+ * from the list of failing action types. But you can call this method explicitly if you want to clear the
627
+ * action type before it's used again.
628
+ *
629
+ * Usage:
630
+ * ```ts
631
+ * store.clearExceptionFor(MyAction);
632
+ * ```
633
+ */
634
+ clearExceptionFor<T extends KissAction<St>>(type: {
635
+ new (...args: any[]): T;
636
+ }): void;
637
+ /**
638
+ * Function `Store.describeStateChange()` returns a string describing only the differences between
639
+ * two given objects.
640
+ *
641
+ * By default, when `logStateChanges` is set to `true` in the Store constructor, function
642
+ * `describeStateChange` is used together with `Store.log()` to print all state changes to
643
+ * the console. Note you should turn this off in production.
644
+ */
645
+ static describeStateChange(obj1: any, obj2: any, path?: string): String;
646
+ /**
647
+ * Call `logOut()` when you want to delete the persisted state, and return the store
648
+ * state to the given initial-state. That's usually necessary when the user logs out
649
+ * of your app, or the user deletes its account, so that another user may log in,
650
+ * or start a new sign-up process.
651
+ *
652
+ * Note: If you know about any timers or async processes that you may have started,
653
+ * you should stop/cancel them all before calling this method.
654
+ *
655
+ * You may opt to:
656
+ *
657
+ * - Wait for `throttle` milliseconds to make sure all async processes that the app may
658
+ * have started have time to finish. The default `throttle` is 3000 milliseconds (3 seconds).
659
+ *
660
+ * - Wait for all actions currently running to finish, but wait at most `actionsThrottle`
661
+ * milliseconds. If the actions are not finished by then, the state will be deleted anyway.
662
+ * The default `actionsThrottle` is 6000 milliseconds (6 seconds).
663
+ */
664
+ logOut({ initialState, throttle, actionsThrottle, }: {
665
+ store: Store<St>;
666
+ initialState: St;
667
+ throttle?: number;
668
+ actionsThrottle?: number;
669
+ }): Promise<void>;
670
+ /**
671
+ * Pause the Persistor temporarily.
672
+ *
673
+ * When pausePersistor is called, the Persistor will not start a new persistence process, until method
674
+ * resumePersistor is called. This will not affect the current persistence process, if one is currently
675
+ * running.
676
+ *
677
+ * Note: A persistence process starts when the Persistor.persistDifference method is called,
678
+ * and finishes when the promise returned by that method completes.
679
+ */
680
+ pausePersistor(): void;
681
+ /**
682
+ * Persists the current state (if it's not yet persisted), then pauses the Persistor temporarily.
683
+ *
684
+ * When persistAndPausePersistor is called, this will not affect the current persistence
685
+ * process, if one is currently running. If no persistence process was running, it will
686
+ * immediately start a new persistence process (ignoring Persistor.throttle).
687
+ *
688
+ * Then, the Persistor will not start another persistence process, until method
689
+ * resumePersistor is called.
690
+ *
691
+ * Note: A persistence process starts when the Persistor.persistDifference method is called,
692
+ * and finishes when the promise returned by that method completes.
693
+ */
694
+ persistAndPausePersistor(): void;
695
+ /**
696
+ * Resumes persistence by the Persistor,
697
+ * after calling pausePersistor or persistAndPausePersistor.
698
+ */
699
+ resumePersistor(): void;
700
+ /**
701
+ * Asks the Persistor to save the initialState in the local persistence.
702
+ */
703
+ saveInitialStateInPersistence(initialState: St): Promise<void>;
704
+ /**
705
+ * Asks the Persistor to read the state from the local persistence.
706
+ * Important: If you use this, you MUST put this state into the store.
707
+ * Kiss will assume that's the case, and will not work properly otherwise.
708
+ */
709
+ readStateFromPersistence(): Promise<St | null>;
710
+ /**
711
+ * Asks the Persistor to delete the saved state from the local persistence.
712
+ */
713
+ deleteStateFromPersistence(): Promise<void>;
714
+ /**
715
+ * Gets, from the Persistor, the last state that was saved to the local persistence.
716
+ */
717
+ getLastPersistedStateFromPersistor(): St | null;
718
+ /**
719
+ * Returns a promise which will resolve when the given state `condition` is true.
720
+ * If the condition is already true when the method is called, the promise resolves immediately.
721
+ *
722
+ * You may also provide a `timeoutMillis`, which by default is 10 minutes. If you want, you
723
+ * can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
724
+ * To disable the timeout, make it 0 or -1.
725
+ *
726
+ * This method is useful in tests, and it returns the action which changed
727
+ * the store state into the condition, in case you need it:
728
+ *
729
+ * ```typescript
730
+ * let action = await store.waitCondition((state) => state.name == "Bill");
731
+ * expect(action instanceof ChangeNameAction).toBe(true);
732
+ * ```
733
+ *
734
+ * This method is also eventually useful in production code, in which case you
735
+ * should avoid waiting for conditions that may take a very long time to complete,
736
+ * as checking the condition is an overhead to every state change.
737
+ *
738
+ * Examples:
739
+ *
740
+ * // Dispatch actions and wait for the state change:
741
+ * expect(store.state.user.isLoggedIn).toBe(false);
742
+ * dispatch(new LogInUser("Mary"));
743
+ * await store.waitCondition((state) => state.user.isLoggedIn);
744
+ * expect(store.state.user.name, "Mary");
745
+ *
746
+ * See also:
747
+ * `waitActionCondition` - Waits until the actions in progress meet a given condition.
748
+ * `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
749
+ * `waitActionType` - Waits until an action of a given type is NOT in progress.
750
+ * `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
751
+ * `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
752
+ */
753
+ waitCondition(condition: (state: St) => boolean, timeoutMillis?: number | null): Promise<KissAction<St> | null>;
754
+ /**
755
+ * Returns a Promise that resolves when some actions meet the given `condition`.
756
+ *
757
+ * If `completeImmediately` is false (the default), this method will throw an error if the
758
+ * condition was already true when the method was called. Otherwise, the promise will complete
759
+ * immediately and throw no error.
760
+ *
761
+ * The `condition` is a function that takes the set of actions "in progress", as well as an
762
+ * action that just entered the set (by being dispatched) or left the set (by finishing
763
+ * dispatching). The function should return `true` when the condition is met, and `false`
764
+ * otherwise. For example:
765
+ *
766
+ * ```ts
767
+ * let action = await store.waitActionCondition((actionsInProgress, triggerAction) => { ... });
768
+ * ```
769
+ *
770
+ * Note: Your condition function should NOT try and modify the set of actions it got in
771
+ * the `actionsInProgress` parameter. If you do, Kiss will throw an error.
772
+ *
773
+ * You get back the set of the actions being dispatched that met the condition, as well as
774
+ * the action that triggered the condition by being added or removed from the set.
775
+ *
776
+ * Note: The condition is only checked when some action is dispatched or finishes dispatching.
777
+ * It's not checked every time action statuses change.
778
+ *
779
+ * You may also provide a `timeoutMillis`, which by default is 10 minutes.
780
+ * To disable the timeout, make it 0 or -1.
781
+ * If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
782
+ *
783
+ * See also:
784
+ * `waitCondition` - Waits until the state is in a given condition.
785
+ * `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
786
+ * `waitActionType` - Waits until an action of a given type is NOT in progress.
787
+ * `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
788
+ * `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
789
+ *
790
+ * You should only use this method in tests.
791
+ */
792
+ waitActionCondition(condition: (actions: Set<KissAction<St>>, triggerAction: KissAction<St> | null) => boolean, { completeImmediately, completedErrorMessage, timeoutMillis, }?: {
793
+ completeImmediately?: boolean;
794
+ completedErrorMessage?: string;
795
+ timeoutMillis?: number | null;
796
+ }): Promise<{
797
+ actions: Set<KissAction<St>>;
798
+ triggerAction: KissAction<St> | null;
799
+ }>;
800
+ /**
801
+ * Returns a promise that resolves when ALL given actions finished dispatching.
802
+ *
803
+ * If `completeImmediately` is false (the default), this method will throw an error if none
804
+ * of the given actions are in progress when the method is called. Otherwise, the promise will
805
+ * complete immediately and throw no error.
806
+ *
807
+ * However, if you don't provide any actions (empty list or `null`), the promise will complete
808
+ * when ALL current actions in progress finish dispatching. In other words, when no actions are
809
+ * currently in progress. In this case, if [completeImmediately] is `false`, the method will
810
+ * throw an error if no actions are in progress when the method is called.
811
+ *
812
+ * Note: Waiting until no actions are in progress should only be done in test, never in
813
+ * production, as it's very easy to create a deadlock. However, waiting for specific actions to
814
+ * finish is safe in production, as long as you're waiting for actions you just dispatched.
815
+ *
816
+ * You may also provide a [timeoutMillis], which by default is 10 minutes.
817
+ * To disable the timeout, make it 0 or -1.
818
+ * If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
819
+ *
820
+ * Examples:
821
+ *
822
+ * ```ts
823
+ * // Dispatch actions in PARALLEL and wait until no actions are in progress.
824
+ * expect(state.stocks).toEqual(['TSLA']);
825
+ * dispatch(new BuyAction('IBM'));
826
+ * dispatch(new SellAction('TSLA'));
827
+ * await waitAllActions([]);
828
+ * expect(state.stocks).toEqual(['IBM']);
829
+ *
830
+ * // Dispatch two actions in PARALLEL and wait for them to finish:
831
+ * expect(state.stocks).toEqual(['TSLA']);
832
+ * let action1 = new BuyAction('IBM');
833
+ * let action2 = new SellAction('TSLA');
834
+ * dispatch(action1);
835
+ * dispatch(action2);
836
+ * await store.waitAllActions([action1, action2]);
837
+ * expect(state.stocks).toEqual(['IBM']);
838
+ *
839
+ * // This could also have been achieved by dispatching two actions in PARALLEL
840
+ * // by using with `dispatchAndWaitAll` to wait for them:
841
+ * expect(state.stocks).toEqual(['TSLA']);
842
+ * await dispatchAndWaitAll([
843
+ * new SellAction('IBM'),
844
+ * new BuyAction('TSLA')
845
+ * ]);
846
+ * expect(state.stocks).toEqual(['IBM']);
847
+ *
848
+ * // This could also have been achieved by dispatching two actions in SERIES
849
+ * // by using `dispatchAndWait` to wait for them:
850
+ * expect(state.stocks).toEqual(['TSLA']);
851
+ * await dispatchAndWait(new BuyAction('IBM'));
852
+ * await dispatchAndWait(new SellAction('TSLA'));
853
+ * expect(state.stocks).toEqual(['IBM']);
854
+ * ```
855
+ *
856
+ * See also:
857
+ * `waitCondition` - Waits until the state is in a given condition.
858
+ * `waitActionCondition` - Waits until the actions in progress meet a given condition.
859
+ * `waitActionType` - Waits until an action of a given type is NOT in progress.
860
+ * `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
861
+ * `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
862
+ *
863
+ * You should only use this method in tests.
864
+ */
865
+ waitAllActions(actions: KissAction<St>[] | null, { completeImmediately, timeoutMillis }?: {
866
+ completeImmediately?: boolean;
867
+ timeoutMillis?: number | null;
868
+ }): Promise<{
869
+ actions: Set<KissAction<St>>;
870
+ triggerAction: KissAction<St> | null;
871
+ }>;
872
+ /**
873
+ * Returns a promise that completes when an action of the given type in NOT in progress
874
+ * (it's not being dispatched):
875
+ *
876
+ * - If NO action of the given type is currently in progress when the method is called,
877
+ * and `completeImmediately` is false (the default), this method will throw an error.
878
+ *
879
+ * - If NO action of the given type is currently in progress when the method is called,
880
+ * and `completeImmediately` is true, the promise completes immediately, returns `null`,
881
+ * and throws no error.
882
+ *
883
+ * - If an action of the given type is in progress, the promise completes when the action
884
+ * finishes, and returns the action. You can use the returned action to check its `status`:
885
+ *
886
+ * ```dart
887
+ * var action = await store.waitActionType(MyAction);
888
+ * expect(action.status.originalError, isA<UserException>());
889
+ * ```
890
+ *
891
+ * You may also provide a `timeoutMillis`, which by default is 10 minutes.
892
+ * To disable the timeout, make it 0 or -1.
893
+ * If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
894
+ *
895
+ * Examples:
896
+ *
897
+ * ```ts
898
+ * // Wait until some action of a given type is dispatched.
899
+ * dispatch(new DoALotOfStuffAction());
900
+ * let action = await store.waitActionType(ChangeNameAction);
901
+ * expect(action instanceof ChangeNameAction).toBe(true);
902
+ * expect(action.status.isCompletedOk).toBe(true);
903
+ * expect(store.state.name).toBe('Bill');
904
+ * ```
905
+ *
906
+ * See also:
907
+ * `waitCondition` - Waits until the state is in a given condition.
908
+ * `waitActionCondition` - Waits until the actions in progress meet a given condition.
909
+ * `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
910
+ * `waitActionType` - Waits until an action of a given type is NOT in progress.
911
+ * `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
912
+ * `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
913
+ *
914
+ * You should only use this method in tests.
915
+ */
916
+ waitActionType(actionType: {
917
+ new (...args: any[]): KissAction<St>;
918
+ }, { completeImmediately, timeoutMillis }?: {
919
+ completeImmediately?: boolean;
920
+ timeoutMillis?: number | null;
921
+ }): Promise<KissAction<St> | null>;
922
+ /**
923
+ * Returns a promise that completes when ALL actions of the given type are NOT in progress
924
+ * (none of them is being dispatched):
925
+ *
926
+ * - If NO action of the given types is currently in progress when the method is called,
927
+ * and `completeImmediately` is false (the default), this method will throw an error.
928
+ *
929
+ * - If NO action of the given type is currently in progress when the method is called,
930
+ * and `completeImmediately` is true, the promise completes immediately and throws no error.
931
+ *
932
+ * - If any action of the given types is in progress, the promise completes only when
933
+ * no action of the given types is in progress anymore.
934
+ *
935
+ * You may also provide a `timeoutMillis`, which by default is 10 minutes.
936
+ * To disable the timeout, make it 0 or -1.
937
+ * If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
938
+ *
939
+ * Examples:
940
+ *
941
+ * ```ts
942
+ * // Dispatches two actions in PARALLEL and wait for their TYPES:
943
+ * expect(store.state.portfolio).toEqual(['TSLA']);
944
+ * dispatch(new BuyAction('IBM'));
945
+ * dispatch(new SellAction('TSLA'));
946
+ * await store.waitAllActionTypes([BuyAction, SellAction]);
947
+ * expect(store.state.portfolio).toEqual(['IBM']);
948
+ * ```
949
+ *
950
+ * See also:
951
+ * `waitCondition` - Waits until the state is in a given condition.
952
+ * `waitActionCondition` - Waits until the actions in progress meet a given condition.
953
+ * `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
954
+ * `waitActionType` - Waits until an action of a given type is NOT in progress.
955
+ * `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
956
+ * `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
957
+ *
958
+ * You should only use this method in tests.
959
+ */
960
+ waitAllActionTypes(actionTypes: {
961
+ new (...args: any[]): KissAction<St>;
962
+ }[], { completeImmediately, timeoutMillis }?: {
963
+ completeImmediately?: boolean;
964
+ timeoutMillis?: number | null;
965
+ }): Promise<void>;
966
+ /**
967
+ * Returns a promise which will complete when ANY action of the given types FINISHES
968
+ * dispatching. IMPORTANT: This method is different from the other similar methods, because
969
+ * it does NOT complete immediately if no action of the given types is in progress. Instead,
970
+ * it waits until an action of the given types finishes dispatching, even if they
971
+ * were not yet in progress when the method was called.
972
+ *
973
+ * This method returns the action that completed the promise, which you can use to check
974
+ * its `status`.
975
+ *
976
+ * It's useful when the actions you are waiting for are not yet dispatched when you call this
977
+ * method. For example, suppose action `StartAction` starts a process that takes some time
978
+ * to run and then dispatches an action called `MyFinalAction`. You can then write:
979
+ *
980
+ * ```dart
981
+ * dispatch(StartAction());
982
+ * let action = await store.waitAnyActionTypeFinishes([MyFinalAction]);
983
+ * expect(action.status.originalError).toBeInstanceOf(UserException>);
984
+ * ```
985
+ *
986
+ * You may also provide a `timeoutMillis`, which by default is 10 minutes.
987
+ * To disable the timeout, make it 0 or -1.
988
+ * If you want, you can modify `TimeoutException.defaultTimeoutMillis` to change the default timeout.
989
+ *
990
+ * Examples:
991
+ *
992
+ * ```ts
993
+ * // Wait until some action of the given types is dispatched.
994
+ * dispatch(new ProcessStocksAction());
995
+ * let action = await store.waitAnyActionTypeFinishes([BuyAction, SellAction]);
996
+ * expect(store.state.portfolio.includes('IBM')).toBe(true);
997
+ * ```
998
+ *
999
+ * See also:
1000
+ * `waitCondition` - Waits until the state is in a given condition.
1001
+ * `waitActionCondition` - Waits until the actions in progress meet a given condition.
1002
+ * `waitAllActions` - Waits until the given actions are NOT in progress, or no actions are in progress.
1003
+ * `waitActionType` - Waits until an action of a given type is NOT in progress.
1004
+ * `waitAllActionTypes` - Waits until all actions of the given type are NOT in progress.
1005
+ * `waitAnyActionTypeFinishes` - Waits until ANY action of the given types finish dispatching.
1006
+ *
1007
+ * You should only use this method in tests.
1008
+ */
1009
+ waitAnyActionTypeFinishes(actionTypes: {
1010
+ new (...args: any[]): KissAction<St>;
1011
+ }[], { timeoutMillis }: {
1012
+ timeoutMillis?: number | null;
1013
+ }): Promise<KissAction<St>>;
1014
+ /**
1015
+ * Returns an unmodifiable set of the actions on progress.
1016
+ * For debug purposes, the `toString` method of the returned set will
1017
+ * call `KissAction.toString()` for all actions.
1018
+ */
1019
+ actionsInProgress(): Set<KissAction<St>>;
1020
+ /**
1021
+ * Waits until the store state meets a certain condition, and then dispatches an action.
1022
+ */
1023
+ dispatchWhen(action: KissAction<St>, condition: (state: St) => boolean): void;
1024
+ }
1025
+ interface StoreProviderProps<St> {
1026
+ store: Store<St>;
1027
+ children: React.ReactNode;
1028
+ }
1029
+ export interface StoreContextType<St> {
1030
+ store: Store<St> | null;
1031
+ }
1032
+ export declare const StoreContext: React.Context<StoreContextType<any>>;
1033
+ export declare function StoreProvider<St>({ store, children }: StoreProviderProps<St>): JSX.Element;
1034
+ declare class Mocks<St> {
1035
+ private mocks;
1036
+ add<T extends KissAction<St>>(actionType: new (...args: any[]) => T, mockFunction: (action: T) => KissAction<St> | null): void;
1037
+ remove(actionType: new () => KissAction<St>): void;
1038
+ clear(): void;
1039
+ get(actionType: new () => KissAction<St>): ((action: KissAction<St>) => KissAction<St> | null) | undefined;
1040
+ }
1041
+ export declare type ShowUserException = (exception: UserException, count: number, next: () => void) => void;
1042
+ export {};
1043
+ //# sourceMappingURL=Store.d.ts.map