kiss-for-react 1.0.3 → 2.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.
- 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 +226 -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 +1472 -969
- package/lib/cjs/KissAction.js +4635 -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 +4278 -1534
- package/lib/cjs/StoreException.js +162 -75
- package/lib/cjs/StoreProvider.js +88 -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 +5199 -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 +2253 -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 +80 -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 +221 -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 +1446 -0
- package/lib/esm/KissAction.mjs +4689 -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 +4400 -0
- package/lib/esm/StoreException.mjs +153 -0
- package/lib/esm/StoreProvider.mjs +80 -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 +5199 -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 +2253 -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 +80 -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 +55 -31
- 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
|
@@ -1,309 +1,309 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// TODO: DONT REMOVE (This will be implemented in the future)
|
|
3
|
-
// /**
|
|
4
|
-
// * Immutable object to keep track of boolean flags that indicate if some
|
|
5
|
-
// * process is in progress (the user is "waiting").
|
|
6
|
-
// *
|
|
7
|
-
// * The flags and flag-references can be any immutable object.
|
|
8
|
-
// * They must be immutable to make sure [Wait] is also immutable.
|
|
9
|
-
// *
|
|
10
|
-
// * Use it in Redux store states, like this:
|
|
11
|
-
// * * To add a flag: state.copy(wait: state.wait.add(flag: myFlag));
|
|
12
|
-
// * * To remove a flag: state.copy(wait: state.wait.remove(flag: myFlag));
|
|
13
|
-
// * * To clear all flags: state.copy(wait: state.wait.clear());
|
|
14
|
-
// *
|
|
15
|
-
// * If can also use have a flag with a reference, like this:
|
|
16
|
-
// * * To add a flag with reference: state.copy(wait: state.wait.add(flag: myFlag, ref:MyRef));
|
|
17
|
-
// * * To remove a flag with reference: state.copy(wait: state.wait.remove(flag: myFlag, ref:MyRef));
|
|
18
|
-
// * * To clear all references for a flag: state.copy(wait: state.wait.clear(flag: myFlag));
|
|
19
|
-
// *
|
|
20
|
-
// * In the ViewModel, you can check the flags/references, like this:
|
|
21
|
-
// *
|
|
22
|
-
// * * To check if there is any waiting: state.wait.isWaiting
|
|
23
|
-
// * * To check if it's waiting a specific flag: state.wait.isWaitingFor(myFlag);
|
|
24
|
-
// * * To check if it's waiting a specific flag/reference: state.wait.isWaitingFor(myFlag, ref: myRef);
|
|
25
|
-
// *
|
|
26
|
-
// */
|
|
27
|
-
// export class Wait {
|
|
28
|
-
// private readonly _flags: FlagsMap;
|
|
29
|
-
//
|
|
30
|
-
// constructor();
|
|
31
|
-
// constructor(flags: FlagsMap);
|
|
32
|
-
// constructor(flags?: FlagsMap) {
|
|
33
|
-
// this._flags = flags || {};
|
|
34
|
-
// }
|
|
35
|
-
//
|
|
36
|
-
// /**
|
|
37
|
-
// * Convenience flag that you can use when a `null` value means ALL.
|
|
38
|
-
// * For example, suppose if you want until an async process schedules an `appointment`
|
|
39
|
-
// * for specific `time`. However, if no time is selected, you want to schedule the whole
|
|
40
|
-
// * day (all "times"). You can do:
|
|
41
|
-
// * `dispatch(WaitAction.add(appointment, ref: time ?? Wait.ALL));`
|
|
42
|
-
// *
|
|
43
|
-
// * And then later check if you are waiting for a specific time:
|
|
44
|
-
// * `if (wait.isWaitingFor(appointment, ref: time) { ... }`
|
|
45
|
-
// *
|
|
46
|
-
// * Or if you are waiting for the whole day:
|
|
47
|
-
// * `if (wait.isWaitingFor(appointment, ref: Wait.ALL) { ... }`
|
|
48
|
-
// *
|
|
49
|
-
// */
|
|
50
|
-
// static readonly ALL = {};
|
|
51
|
-
//
|
|
52
|
-
// add(flag: any, ref: any = null): Wait {
|
|
53
|
-
// const newFlags = this._deepCopy();
|
|
54
|
-
//
|
|
55
|
-
// if (!newFlags[flag]) {
|
|
56
|
-
// newFlags[flag] = new Set();
|
|
57
|
-
// }
|
|
58
|
-
//
|
|
59
|
-
// newFlags[flag].add(ref);
|
|
60
|
-
//
|
|
61
|
-
// return new Wait(newFlags);
|
|
62
|
-
// }
|
|
63
|
-
//
|
|
64
|
-
// remove(flag: any, ref: any = null): Wait {
|
|
65
|
-
// if (Object.keys(this._flags).length === 0) {
|
|
66
|
-
// return this;
|
|
67
|
-
// } else {
|
|
68
|
-
// const newFlags = this._deepCopy();
|
|
69
|
-
//
|
|
70
|
-
// if (ref === null) {
|
|
71
|
-
// delete newFlags[flag];
|
|
72
|
-
// } else {
|
|
73
|
-
// newFlags[flag]?.delete(ref);
|
|
74
|
-
// if (newFlags[flag]?.size === 0) {
|
|
75
|
-
// delete newFlags[flag];
|
|
76
|
-
// }
|
|
77
|
-
// }
|
|
78
|
-
//
|
|
79
|
-
// if (Object.keys(newFlags).length === 0) {
|
|
80
|
-
// return new Wait();
|
|
81
|
-
// } else {
|
|
82
|
-
// return new Wait(newFlags);
|
|
83
|
-
// }
|
|
84
|
-
// }
|
|
85
|
-
// }
|
|
86
|
-
//
|
|
87
|
-
// clear(flag: any = null): Wait {
|
|
88
|
-
// if (flag === null) {
|
|
89
|
-
// return new Wait();
|
|
90
|
-
// } else {
|
|
91
|
-
// const newFlags = this._deepCopy();
|
|
92
|
-
// delete newFlags[flag];
|
|
93
|
-
// return new Wait(newFlags);
|
|
94
|
-
// }
|
|
95
|
-
// }
|
|
96
|
-
//
|
|
97
|
-
// /**
|
|
98
|
-
// * Return true if there is any waiting (any flag).
|
|
99
|
-
// */
|
|
100
|
-
// isWaiting(): boolean {
|
|
101
|
-
// return Object.keys(this._flags).length > 0;
|
|
102
|
-
// }
|
|
103
|
-
//
|
|
104
|
-
// /**
|
|
105
|
-
// * Return true if is waiting for a specific flag.
|
|
106
|
-
// * If [ref] is null, it returns true if it's waiting for any reference of the flag.
|
|
107
|
-
// * If [ref] is not null, it returns true if it's waiting for that specific reference of the flag.
|
|
108
|
-
// */
|
|
109
|
-
// isWaitingFor(flag: any, ref: any = null): boolean {
|
|
110
|
-
// const refs = this._flags[flag];
|
|
111
|
-
//
|
|
112
|
-
// if (ref === null) {
|
|
113
|
-
// return !!refs && refs.size > 0;
|
|
114
|
-
// } else {
|
|
115
|
-
// return !!refs && refs.has(ref);
|
|
116
|
-
// }
|
|
117
|
-
// }
|
|
118
|
-
//
|
|
119
|
-
// /**
|
|
120
|
-
// * Return true if is waiting for ANY flag of the specific type.
|
|
121
|
-
// *
|
|
122
|
-
// * This is useful when you want to wait for an Action to finish. For example:
|
|
123
|
-
// *
|
|
124
|
-
// * ```
|
|
125
|
-
// * class MyAction extends KissAction<AppState> {
|
|
126
|
-
// * Future<AppState?> reduce() async {
|
|
127
|
-
// * await doSomething();
|
|
128
|
-
// * return null;
|
|
129
|
-
// * }
|
|
130
|
-
// *
|
|
131
|
-
// * void before() => dispatch(WaitAction.add(this));
|
|
132
|
-
// * void after() => dispatch(WaitAction.remove(this));
|
|
133
|
-
// * }
|
|
134
|
-
// *
|
|
135
|
-
// * // Then, in some widget or connector:
|
|
136
|
-
// * if (wait.isWaitingForType<MyAction>()) { ... }
|
|
137
|
-
// * ```
|
|
138
|
-
// */
|
|
139
|
-
// isWaitingForType<T>(type: { new(...args: any[]): T }): boolean {
|
|
140
|
-
// return Object.keys(this._flags).some((flag) => this._flags[flag] instanceof type);
|
|
141
|
-
// }
|
|
142
|
-
//
|
|
143
|
-
// private _deepCopy(): FlagsMap {
|
|
144
|
-
// const newFlags: FlagsMap = {};
|
|
145
|
-
//
|
|
146
|
-
// Object.entries(this._flags).forEach(([flag, refs]) => {
|
|
147
|
-
// newFlags[flag] = new Set(refs);
|
|
148
|
-
// });
|
|
149
|
-
//
|
|
150
|
-
// return newFlags;
|
|
151
|
-
// }
|
|
152
|
-
//
|
|
153
|
-
// process(operation: WaitOperation, flag: any, ref?: any): Wait {
|
|
154
|
-
// if (operation === WaitOperation.add)
|
|
155
|
-
// return this.add(flag, ref);
|
|
156
|
-
// else if (operation === WaitOperation.remove)
|
|
157
|
-
// return this.remove(flag, ref);
|
|
158
|
-
// else if (operation === WaitOperation.clear)
|
|
159
|
-
// return this.clear(flag);
|
|
160
|
-
// else
|
|
161
|
-
// throw new Error(`Invalid operation: ${operation}`);
|
|
162
|
-
// }
|
|
163
|
-
//
|
|
164
|
-
// toString(): string {
|
|
165
|
-
// return `Wait(${JSON.stringify(this._flags)})`;
|
|
166
|
-
// }
|
|
167
|
-
// }
|
|
168
|
-
//
|
|
169
|
-
// /**
|
|
170
|
-
// * Interface for the flags storage structure
|
|
171
|
-
// */
|
|
172
|
-
// interface FlagsMap {
|
|
173
|
-
// [key: string]: Set<any>;
|
|
174
|
-
// }
|
|
175
|
-
//
|
|
176
|
-
// export enum WaitOperation { add = 'add', remove = 'remove', clear = 'clear' }
|
|
177
|
-
//
|
|
178
|
-
// import { KissAction } from './KissAction';
|
|
179
|
-
// import { Wait, WaitOperation } from './Wait';
|
|
180
|
-
//
|
|
181
|
-
// /**
|
|
182
|
-
// * [WaitAction] and [Wait] work together to help you create boolean flags that
|
|
183
|
-
// * indicate some process is currently running. For this to work your store state
|
|
184
|
-
// * must have a `Wait` field named `wait`, and the state must have a `copy` or
|
|
185
|
-
// * `copyWith` method that copies this field as a named parameter. For example:
|
|
186
|
-
// *
|
|
187
|
-
// * ```
|
|
188
|
-
// * class AppState {
|
|
189
|
-
// * wait: Wait;
|
|
190
|
-
// * copy({wait :Wait}) :AppState => AppState({wait: wait});
|
|
191
|
-
// * }
|
|
192
|
-
// * ```
|
|
193
|
-
// */
|
|
194
|
-
// export class WaitAction<St> extends KissAction<St> {
|
|
195
|
-
// reduce(): St | Promise<St | null> | null {
|
|
196
|
-
// let wait: Wait = (this.state as any).wait ?? new Wait();
|
|
197
|
-
// return (this.state as any).copy(
|
|
198
|
-
// { wait: wait.process(this.operation, this.flag, this.ref) }
|
|
199
|
-
// );
|
|
200
|
-
// }
|
|
201
|
-
//
|
|
202
|
-
// readonly operation: WaitOperation;
|
|
203
|
-
// readonly flag: any;
|
|
204
|
-
// readonly ref: any;
|
|
205
|
-
// readonly delayMillis: number | undefined;
|
|
206
|
-
//
|
|
207
|
-
// private constructor({ operation, flag, ref, delayMillis }: {
|
|
208
|
-
// operation: WaitOperation,
|
|
209
|
-
// flag: any,
|
|
210
|
-
// ref: any,
|
|
211
|
-
// delayMillis: number | undefined,
|
|
212
|
-
// }) {
|
|
213
|
-
// super();
|
|
214
|
-
// this.operation = operation;
|
|
215
|
-
// this.flag = flag;
|
|
216
|
-
// this.ref = ref;
|
|
217
|
-
// this.delayMillis = delayMillis;
|
|
218
|
-
// }
|
|
219
|
-
//
|
|
220
|
-
// /// Adds a [flag] that indicates some process is currently running.
|
|
221
|
-
// /// Optionally, you can also have a flag-reference called [ref].
|
|
222
|
-
// ///
|
|
223
|
-
// /// Note: [flag] and [ref] must be immutable objects.
|
|
224
|
-
// ///
|
|
225
|
-
// /// ```
|
|
226
|
-
// /// // Add a wait state, using this as the flag.
|
|
227
|
-
// /// dispatch(WaitAction.add(this));
|
|
228
|
-
// ///
|
|
229
|
-
// /// // Add a wait state, using this as the flag, and 123 as a reference.
|
|
230
|
-
// /// dispatch(WaitAction.add(this, ref: 123));
|
|
231
|
-
// /// ```
|
|
232
|
-
// /// Note: When the process finishes running, you will have to remove
|
|
233
|
-
// /// the [flag] by using the [remove] or [clear] methods.
|
|
234
|
-
// ///
|
|
235
|
-
// /// If you pass a [delay], the flag will be added only after that
|
|
236
|
-
// /// duration has passed, after the [add] method is called.
|
|
237
|
-
// ///
|
|
238
|
-
// static add<St>(flag: any, ref?: any, delayMillis?: number): WaitAction<St> {
|
|
239
|
-
// return new WaitAction({
|
|
240
|
-
// operation: WaitOperation.add,
|
|
241
|
-
// flag: flag,
|
|
242
|
-
// ref: ref,
|
|
243
|
-
// delayMillis: delayMillis
|
|
244
|
-
// });
|
|
245
|
-
// }
|
|
246
|
-
//
|
|
247
|
-
//
|
|
248
|
-
// /// Removes a [flag] previously added with the [add] method.
|
|
249
|
-
// /// Removing the flag indicating some process finished running.
|
|
250
|
-
// ///
|
|
251
|
-
// /// If you added the flag with a reference [ref], you must also pass the
|
|
252
|
-
// /// same reference here to remove it. Alternatively, if you want to
|
|
253
|
-
// /// remove all references to that flag, use the [clear] method instead.
|
|
254
|
-
// ///
|
|
255
|
-
// /// ```
|
|
256
|
-
// /// // Add and remove a wait state, using this as the flag.
|
|
257
|
-
// /// dispatch(WaitAction.add(this));
|
|
258
|
-
// /// dispatch(WaitAction.remove(this));
|
|
259
|
-
// ///
|
|
260
|
-
// /// // Adds and remove a wait state, using this as the flag, and 123 as a reference.
|
|
261
|
-
// /// dispatch(WaitAction.add(this, ref: 123));
|
|
262
|
-
// /// dispatch(WaitAction.remove(this, ref: 123));
|
|
263
|
-
// /// ```
|
|
264
|
-
// ///
|
|
265
|
-
// /// If you pass a [delay], the flag will be removed only after that
|
|
266
|
-
// /// duration has passed, after the [add] method is called. Example:
|
|
267
|
-
// ///
|
|
268
|
-
// /// ```
|
|
269
|
-
// /// // Add a wait state that will be automatically removed after 3 seconds.
|
|
270
|
-
// /// dispatch(WaitAction.add(this));
|
|
271
|
-
// /// dispatch(WaitAction.remove(this, delay: Duration(seconds: 3)));
|
|
272
|
-
// /// ```
|
|
273
|
-
// ///
|
|
274
|
-
// static remove<St>(flag: any, ref?: any, delayMillis?: number): WaitAction<St> {
|
|
275
|
-
// return new WaitAction({
|
|
276
|
-
// operation: WaitOperation.remove,
|
|
277
|
-
// flag: flag,
|
|
278
|
-
// ref: ref,
|
|
279
|
-
// delayMillis: delayMillis
|
|
280
|
-
// });
|
|
281
|
-
// }
|
|
282
|
-
//
|
|
283
|
-
// /// Clears (removes) the [flag], with all its references.
|
|
284
|
-
// /// Removing the flag indicating some process finished running.
|
|
285
|
-
// ///
|
|
286
|
-
// /// ```
|
|
287
|
-
// /// dispatch(WaitAction.add(this, flag: 123));
|
|
288
|
-
// /// dispatch(WaitAction.add(this, flag: "xyz"));
|
|
289
|
-
// /// dispatch(WaitAction.clear(this);
|
|
290
|
-
// /// ```
|
|
291
|
-
// static clear<St>(flag: any, ref?: any, delayMillis?: number): WaitAction<St> {
|
|
292
|
-
// return new WaitAction({
|
|
293
|
-
// operation: WaitOperation.clear,
|
|
294
|
-
// flag: flag,
|
|
295
|
-
// ref: ref,
|
|
296
|
-
// delayMillis: delayMillis
|
|
297
|
-
// });
|
|
298
|
-
// }
|
|
299
|
-
//
|
|
300
|
-
//
|
|
301
|
-
// toString(): string {
|
|
302
|
-
// return `WaitAction.${this.operation}` +
|
|
303
|
-
// `(flag: ${this.flag.toString()}, ` +
|
|
304
|
-
// `ref: ${this.ref.toString()})`;
|
|
305
|
-
// }
|
|
306
|
-
// }
|
|
307
|
-
//
|
|
308
|
-
//
|
|
309
|
-
//
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO: DONT REMOVE (This will be implemented in the future)
|
|
3
|
+
// /**
|
|
4
|
+
// * Immutable object to keep track of boolean flags that indicate if some
|
|
5
|
+
// * process is in progress (the user is "waiting").
|
|
6
|
+
// *
|
|
7
|
+
// * The flags and flag-references can be any immutable object.
|
|
8
|
+
// * They must be immutable to make sure [Wait] is also immutable.
|
|
9
|
+
// *
|
|
10
|
+
// * Use it in Redux store states, like this:
|
|
11
|
+
// * * To add a flag: state.copy(wait: state.wait.add(flag: myFlag));
|
|
12
|
+
// * * To remove a flag: state.copy(wait: state.wait.remove(flag: myFlag));
|
|
13
|
+
// * * To clear all flags: state.copy(wait: state.wait.clear());
|
|
14
|
+
// *
|
|
15
|
+
// * If can also use have a flag with a reference, like this:
|
|
16
|
+
// * * To add a flag with reference: state.copy(wait: state.wait.add(flag: myFlag, ref:MyRef));
|
|
17
|
+
// * * To remove a flag with reference: state.copy(wait: state.wait.remove(flag: myFlag, ref:MyRef));
|
|
18
|
+
// * * To clear all references for a flag: state.copy(wait: state.wait.clear(flag: myFlag));
|
|
19
|
+
// *
|
|
20
|
+
// * In the ViewModel, you can check the flags/references, like this:
|
|
21
|
+
// *
|
|
22
|
+
// * * To check if there is any waiting: state.wait.isWaiting
|
|
23
|
+
// * * To check if it's waiting a specific flag: state.wait.isWaitingFor(myFlag);
|
|
24
|
+
// * * To check if it's waiting a specific flag/reference: state.wait.isWaitingFor(myFlag, ref: myRef);
|
|
25
|
+
// *
|
|
26
|
+
// */
|
|
27
|
+
// export class Wait {
|
|
28
|
+
// private readonly _flags: FlagsMap;
|
|
29
|
+
//
|
|
30
|
+
// constructor();
|
|
31
|
+
// constructor(flags: FlagsMap);
|
|
32
|
+
// constructor(flags?: FlagsMap) {
|
|
33
|
+
// this._flags = flags || {};
|
|
34
|
+
// }
|
|
35
|
+
//
|
|
36
|
+
// /**
|
|
37
|
+
// * Convenience flag that you can use when a `null` value means ALL.
|
|
38
|
+
// * For example, suppose if you want until an async process schedules an `appointment`
|
|
39
|
+
// * for specific `time`. However, if no time is selected, you want to schedule the whole
|
|
40
|
+
// * day (all "times"). You can do:
|
|
41
|
+
// * `dispatch(WaitAction.add(appointment, ref: time ?? Wait.ALL));`
|
|
42
|
+
// *
|
|
43
|
+
// * And then later check if you are waiting for a specific time:
|
|
44
|
+
// * `if (wait.isWaitingFor(appointment, ref: time) { ... }`
|
|
45
|
+
// *
|
|
46
|
+
// * Or if you are waiting for the whole day:
|
|
47
|
+
// * `if (wait.isWaitingFor(appointment, ref: Wait.ALL) { ... }`
|
|
48
|
+
// *
|
|
49
|
+
// */
|
|
50
|
+
// static readonly ALL = {};
|
|
51
|
+
//
|
|
52
|
+
// add(flag: any, ref: any = null): Wait {
|
|
53
|
+
// const newFlags = this._deepCopy();
|
|
54
|
+
//
|
|
55
|
+
// if (!newFlags[flag]) {
|
|
56
|
+
// newFlags[flag] = new Set();
|
|
57
|
+
// }
|
|
58
|
+
//
|
|
59
|
+
// newFlags[flag].add(ref);
|
|
60
|
+
//
|
|
61
|
+
// return new Wait(newFlags);
|
|
62
|
+
// }
|
|
63
|
+
//
|
|
64
|
+
// remove(flag: any, ref: any = null): Wait {
|
|
65
|
+
// if (Object.keys(this._flags).length === 0) {
|
|
66
|
+
// return this;
|
|
67
|
+
// } else {
|
|
68
|
+
// const newFlags = this._deepCopy();
|
|
69
|
+
//
|
|
70
|
+
// if (ref === null) {
|
|
71
|
+
// delete newFlags[flag];
|
|
72
|
+
// } else {
|
|
73
|
+
// newFlags[flag]?.delete(ref);
|
|
74
|
+
// if (newFlags[flag]?.size === 0) {
|
|
75
|
+
// delete newFlags[flag];
|
|
76
|
+
// }
|
|
77
|
+
// }
|
|
78
|
+
//
|
|
79
|
+
// if (Object.keys(newFlags).length === 0) {
|
|
80
|
+
// return new Wait();
|
|
81
|
+
// } else {
|
|
82
|
+
// return new Wait(newFlags);
|
|
83
|
+
// }
|
|
84
|
+
// }
|
|
85
|
+
// }
|
|
86
|
+
//
|
|
87
|
+
// clear(flag: any = null): Wait {
|
|
88
|
+
// if (flag === null) {
|
|
89
|
+
// return new Wait();
|
|
90
|
+
// } else {
|
|
91
|
+
// const newFlags = this._deepCopy();
|
|
92
|
+
// delete newFlags[flag];
|
|
93
|
+
// return new Wait(newFlags);
|
|
94
|
+
// }
|
|
95
|
+
// }
|
|
96
|
+
//
|
|
97
|
+
// /**
|
|
98
|
+
// * Return true if there is any waiting (any flag).
|
|
99
|
+
// */
|
|
100
|
+
// isWaiting(): boolean {
|
|
101
|
+
// return Object.keys(this._flags).length > 0;
|
|
102
|
+
// }
|
|
103
|
+
//
|
|
104
|
+
// /**
|
|
105
|
+
// * Return true if is waiting for a specific flag.
|
|
106
|
+
// * If [ref] is null, it returns true if it's waiting for any reference of the flag.
|
|
107
|
+
// * If [ref] is not null, it returns true if it's waiting for that specific reference of the flag.
|
|
108
|
+
// */
|
|
109
|
+
// isWaitingFor(flag: any, ref: any = null): boolean {
|
|
110
|
+
// const refs = this._flags[flag];
|
|
111
|
+
//
|
|
112
|
+
// if (ref === null) {
|
|
113
|
+
// return !!refs && refs.size > 0;
|
|
114
|
+
// } else {
|
|
115
|
+
// return !!refs && refs.has(ref);
|
|
116
|
+
// }
|
|
117
|
+
// }
|
|
118
|
+
//
|
|
119
|
+
// /**
|
|
120
|
+
// * Return true if is waiting for ANY flag of the specific type.
|
|
121
|
+
// *
|
|
122
|
+
// * This is useful when you want to wait for an Action to finish. For example:
|
|
123
|
+
// *
|
|
124
|
+
// * ```
|
|
125
|
+
// * class MyAction extends KissAction<AppState> {
|
|
126
|
+
// * Future<AppState?> reduce() async {
|
|
127
|
+
// * await doSomething();
|
|
128
|
+
// * return null;
|
|
129
|
+
// * }
|
|
130
|
+
// *
|
|
131
|
+
// * void before() => dispatch(WaitAction.add(this));
|
|
132
|
+
// * void after() => dispatch(WaitAction.remove(this));
|
|
133
|
+
// * }
|
|
134
|
+
// *
|
|
135
|
+
// * // Then, in some widget or connector:
|
|
136
|
+
// * if (wait.isWaitingForType<MyAction>()) { ... }
|
|
137
|
+
// * ```
|
|
138
|
+
// */
|
|
139
|
+
// isWaitingForType<T>(type: { new(...args: any[]): T }): boolean {
|
|
140
|
+
// return Object.keys(this._flags).some((flag) => this._flags[flag] instanceof type);
|
|
141
|
+
// }
|
|
142
|
+
//
|
|
143
|
+
// private _deepCopy(): FlagsMap {
|
|
144
|
+
// const newFlags: FlagsMap = {};
|
|
145
|
+
//
|
|
146
|
+
// Object.entries(this._flags).forEach(([flag, refs]) => {
|
|
147
|
+
// newFlags[flag] = new Set(refs);
|
|
148
|
+
// });
|
|
149
|
+
//
|
|
150
|
+
// return newFlags;
|
|
151
|
+
// }
|
|
152
|
+
//
|
|
153
|
+
// process(operation: WaitOperation, flag: any, ref?: any): Wait {
|
|
154
|
+
// if (operation === WaitOperation.add)
|
|
155
|
+
// return this.add(flag, ref);
|
|
156
|
+
// else if (operation === WaitOperation.remove)
|
|
157
|
+
// return this.remove(flag, ref);
|
|
158
|
+
// else if (operation === WaitOperation.clear)
|
|
159
|
+
// return this.clear(flag);
|
|
160
|
+
// else
|
|
161
|
+
// throw new Error(`Invalid operation: ${operation}`);
|
|
162
|
+
// }
|
|
163
|
+
//
|
|
164
|
+
// toString(): string {
|
|
165
|
+
// return `Wait(${JSON.stringify(this._flags)})`;
|
|
166
|
+
// }
|
|
167
|
+
// }
|
|
168
|
+
//
|
|
169
|
+
// /**
|
|
170
|
+
// * Interface for the flags storage structure
|
|
171
|
+
// */
|
|
172
|
+
// interface FlagsMap {
|
|
173
|
+
// [key: string]: Set<any>;
|
|
174
|
+
// }
|
|
175
|
+
//
|
|
176
|
+
// export enum WaitOperation { add = 'add', remove = 'remove', clear = 'clear' }
|
|
177
|
+
//
|
|
178
|
+
// import { KissAction } from './KissAction.mjs';
|
|
179
|
+
// import { Wait, WaitOperation } from './Wait.mjs';
|
|
180
|
+
//
|
|
181
|
+
// /**
|
|
182
|
+
// * [WaitAction] and [Wait] work together to help you create boolean flags that
|
|
183
|
+
// * indicate some process is currently running. For this to work your store state
|
|
184
|
+
// * must have a `Wait` field named `wait`, and the state must have a `copy` or
|
|
185
|
+
// * `copyWith` method that copies this field as a named parameter. For example:
|
|
186
|
+
// *
|
|
187
|
+
// * ```
|
|
188
|
+
// * class AppState {
|
|
189
|
+
// * wait: Wait;
|
|
190
|
+
// * copy({wait :Wait}) :AppState => AppState({wait: wait});
|
|
191
|
+
// * }
|
|
192
|
+
// * ```
|
|
193
|
+
// */
|
|
194
|
+
// export class WaitAction<St> extends KissAction<St> {
|
|
195
|
+
// reduce(): St | Promise<St | null> | null {
|
|
196
|
+
// let wait: Wait = (this.state as any).wait ?? new Wait();
|
|
197
|
+
// return (this.state as any).copy(
|
|
198
|
+
// { wait: wait.process(this.operation, this.flag, this.ref) }
|
|
199
|
+
// );
|
|
200
|
+
// }
|
|
201
|
+
//
|
|
202
|
+
// readonly operation: WaitOperation;
|
|
203
|
+
// readonly flag: any;
|
|
204
|
+
// readonly ref: any;
|
|
205
|
+
// readonly delayMillis: number | undefined;
|
|
206
|
+
//
|
|
207
|
+
// private constructor({ operation, flag, ref, delayMillis }: {
|
|
208
|
+
// operation: WaitOperation,
|
|
209
|
+
// flag: any,
|
|
210
|
+
// ref: any,
|
|
211
|
+
// delayMillis: number | undefined,
|
|
212
|
+
// }) {
|
|
213
|
+
// super();
|
|
214
|
+
// this.operation = operation;
|
|
215
|
+
// this.flag = flag;
|
|
216
|
+
// this.ref = ref;
|
|
217
|
+
// this.delayMillis = delayMillis;
|
|
218
|
+
// }
|
|
219
|
+
//
|
|
220
|
+
// /// Adds a [flag] that indicates some process is currently running.
|
|
221
|
+
// /// Optionally, you can also have a flag-reference called [ref].
|
|
222
|
+
// ///
|
|
223
|
+
// /// Note: [flag] and [ref] must be immutable objects.
|
|
224
|
+
// ///
|
|
225
|
+
// /// ```
|
|
226
|
+
// /// // Add a wait state, using this as the flag.
|
|
227
|
+
// /// dispatch(WaitAction.add(this));
|
|
228
|
+
// ///
|
|
229
|
+
// /// // Add a wait state, using this as the flag, and 123 as a reference.
|
|
230
|
+
// /// dispatch(WaitAction.add(this, ref: 123));
|
|
231
|
+
// /// ```
|
|
232
|
+
// /// Note: When the process finishes running, you will have to remove
|
|
233
|
+
// /// the [flag] by using the [remove] or [clear] methods.
|
|
234
|
+
// ///
|
|
235
|
+
// /// If you pass a [delay], the flag will be added only after that
|
|
236
|
+
// /// duration has passed, after the [add] method is called.
|
|
237
|
+
// ///
|
|
238
|
+
// static add<St>(flag: any, ref?: any, delayMillis?: number): WaitAction<St> {
|
|
239
|
+
// return new WaitAction({
|
|
240
|
+
// operation: WaitOperation.add,
|
|
241
|
+
// flag: flag,
|
|
242
|
+
// ref: ref,
|
|
243
|
+
// delayMillis: delayMillis
|
|
244
|
+
// });
|
|
245
|
+
// }
|
|
246
|
+
//
|
|
247
|
+
//
|
|
248
|
+
// /// Removes a [flag] previously added with the [add] method.
|
|
249
|
+
// /// Removing the flag indicating some process finished running.
|
|
250
|
+
// ///
|
|
251
|
+
// /// If you added the flag with a reference [ref], you must also pass the
|
|
252
|
+
// /// same reference here to remove it. Alternatively, if you want to
|
|
253
|
+
// /// remove all references to that flag, use the [clear] method instead.
|
|
254
|
+
// ///
|
|
255
|
+
// /// ```
|
|
256
|
+
// /// // Add and remove a wait state, using this as the flag.
|
|
257
|
+
// /// dispatch(WaitAction.add(this));
|
|
258
|
+
// /// dispatch(WaitAction.remove(this));
|
|
259
|
+
// ///
|
|
260
|
+
// /// // Adds and remove a wait state, using this as the flag, and 123 as a reference.
|
|
261
|
+
// /// dispatch(WaitAction.add(this, ref: 123));
|
|
262
|
+
// /// dispatch(WaitAction.remove(this, ref: 123));
|
|
263
|
+
// /// ```
|
|
264
|
+
// ///
|
|
265
|
+
// /// If you pass a [delay], the flag will be removed only after that
|
|
266
|
+
// /// duration has passed, after the [add] method is called. Example:
|
|
267
|
+
// ///
|
|
268
|
+
// /// ```
|
|
269
|
+
// /// // Add a wait state that will be automatically removed after 3 seconds.
|
|
270
|
+
// /// dispatch(WaitAction.add(this));
|
|
271
|
+
// /// dispatch(WaitAction.remove(this, delay: Duration(seconds: 3)));
|
|
272
|
+
// /// ```
|
|
273
|
+
// ///
|
|
274
|
+
// static remove<St>(flag: any, ref?: any, delayMillis?: number): WaitAction<St> {
|
|
275
|
+
// return new WaitAction({
|
|
276
|
+
// operation: WaitOperation.remove,
|
|
277
|
+
// flag: flag,
|
|
278
|
+
// ref: ref,
|
|
279
|
+
// delayMillis: delayMillis
|
|
280
|
+
// });
|
|
281
|
+
// }
|
|
282
|
+
//
|
|
283
|
+
// /// Clears (removes) the [flag], with all its references.
|
|
284
|
+
// /// Removing the flag indicating some process finished running.
|
|
285
|
+
// ///
|
|
286
|
+
// /// ```
|
|
287
|
+
// /// dispatch(WaitAction.add(this, flag: 123));
|
|
288
|
+
// /// dispatch(WaitAction.add(this, flag: "xyz"));
|
|
289
|
+
// /// dispatch(WaitAction.clear(this);
|
|
290
|
+
// /// ```
|
|
291
|
+
// static clear<St>(flag: any, ref?: any, delayMillis?: number): WaitAction<St> {
|
|
292
|
+
// return new WaitAction({
|
|
293
|
+
// operation: WaitOperation.clear,
|
|
294
|
+
// flag: flag,
|
|
295
|
+
// ref: ref,
|
|
296
|
+
// delayMillis: delayMillis
|
|
297
|
+
// });
|
|
298
|
+
// }
|
|
299
|
+
//
|
|
300
|
+
//
|
|
301
|
+
// toString(): string {
|
|
302
|
+
// return `WaitAction.${this.operation}` +
|
|
303
|
+
// `(flag: ${this.flag.toString()}, ` +
|
|
304
|
+
// `ref: ${this.ref.toString()})`;
|
|
305
|
+
// }
|
|
306
|
+
// }
|
|
307
|
+
//
|
|
308
|
+
//
|
|
309
|
+
//
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { PersistAction, PersistException, Persistor, PersistorDummy, PersistorPrinterDecorator, } from './Persistor';
|
|
2
|
-
import { ClassPersistor } from './ClassPersistor';
|
|
3
|
-
import { ProcessPersistence } from './ProcessPersistence';
|
|
4
|
-
import { ActionStatus,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
1
|
+
import { PersistAction, PersistException, Persistor, PersistorDummy, PersistorPrinterDecorator, } from './Persistor.mjs';
|
|
2
|
+
import { ClassPersistor } from './ClassPersistor.mjs';
|
|
3
|
+
import { ProcessPersistence } from './ProcessPersistence.mjs';
|
|
4
|
+
import { ActionStatus, OptimisticCommand, OptimisticSync, OptimisticSyncWithPush, ServerPush, KissAction, MergeServerStateAction, Poll, UserExceptionAction, UpdateStateAction, } from './KissAction.mjs';
|
|
5
|
+
import { LoadPages, Pages } from './LoadPages.mjs';
|
|
6
|
+
import { Store, createStore } from './Store.mjs';
|
|
7
|
+
import { StoreProvider, StoreSlice } from './StoreProvider.mjs';
|
|
8
|
+
import { useAllState, useIsFocused, useIsOnline, useClearExceptionFor, useConfiguration, useDispatch, useDispatchAll, useDispatchAndWait, useDispatchAndWaitAll, useDispatcher, useDispatchSync, useDispatchWhen, useEnvironment, useEvent, useExceptionFor, useIsFailed, useIsStoreReady, useIsWaiting, useLayoutEvent, useObject, useSelect, useSelector, useStore, useStoreEffect, useSuspense, } from './Hooks.mjs';
|
|
9
|
+
import { AbortDispatchException, StoreException, TimeoutException } from './StoreException.mjs';
|
|
10
|
+
import { Evt, EvtState } from './Evt.mjs';
|
|
11
|
+
import { UserException } from './UserException.mjs';
|
|
12
|
+
export { Persistor, PersistorPrinterDecorator, PersistorDummy, PersistException, PersistAction, UpdateStateAction, ClassPersistor, ProcessPersistence, KissAction, MergeServerStateAction, UserExceptionAction, ActionStatus, Store, createStore, useStore, useStoreEffect, useAllState, useSelect, useSelector, useObject, StoreProvider, StoreSlice, useIsStoreReady, useIsWaiting, useIsFailed, useExceptionFor, useClearExceptionFor, useSuspense, useIsFocused, useIsOnline, useEnvironment, useConfiguration, Evt, EvtState, useEvent, useLayoutEvent, useDispatch, useDispatchAll, useDispatchAndWait, useDispatchAndWaitAll, useDispatchSync, useDispatchWhen, useDispatcher, StoreException, AbortDispatchException, TimeoutException, UserException, OptimisticCommand, OptimisticSync, OptimisticSyncWithPush, ServerPush, Poll, LoadPages, Pages, };
|