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,69 @@
1
+ /**
2
+ All exceptions thrown by Kiss are of type StoreException.
3
+ */
4
+ export class StoreException extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'StoreException';
8
+ // Maintains proper stack trace for where our error was thrown (only available on V8).
9
+ if (Error.captureStackTrace) {
10
+ Error.captureStackTrace(this, StoreException);
11
+ }
12
+ }
13
+ }
14
+ export class TimeoutException extends Error {
15
+ /**
16
+ * The global default timeout for the wait functions (like `waitCondition` etc.) is 10 minutes.
17
+ * This value is not final and can be modified.
18
+ * To disable the timeout, modify this to a large value, like 300000000000 (almost 10 years).
19
+ */
20
+ static defaultTimeoutMillis = 60 * 1000 * 10;
21
+ constructor(message) {
22
+ super(message);
23
+ this.name = 'TimeoutException';
24
+ // Maintains proper stack trace for where our error was thrown (only available on V8).
25
+ if (Error.captureStackTrace) {
26
+ Error.captureStackTrace(this, StoreException);
27
+ }
28
+ }
29
+ }
30
+ export class ExceptionUtils {
31
+ /**
32
+ Cuts the stack trace at the given string, to avoid showing internal Kiss lines,
33
+ which are not interesting to the user.
34
+
35
+ IMPORTANT: This should only be called during development. V8 only computes it if someone
36
+ actually reads the property, which improves performance dramatically for handable errors.
37
+ When you use this, you'll pay the cost even if your caller doesn't need the stack.
38
+
39
+ The given text will be found at the start of the line, like this: ` at ${text} `
40
+ */
41
+ static sanitizedStackTrace(error, text) {
42
+ const stack = error.stack;
43
+ if (stack === undefined)
44
+ return error;
45
+ const stackLines = stack.split('\n');
46
+ let newStackStartIndex = -1;
47
+ // Be aware that `constructor.name` cannot be used with bundlers that mangle
48
+ // class or function names, because the error class name in the minified code
49
+ // might be shortened.
50
+ const errorLine = ` at ${text} `;
51
+ // Find the index where the exception was dispatched.
52
+ for (let i = 0; i < stackLines.length - 1; i++) {
53
+ if (stackLines[i].startsWith(errorLine)) {
54
+ newStackStartIndex = i + 1;
55
+ break;
56
+ }
57
+ }
58
+ if (newStackStartIndex !== -1) {
59
+ // Reconstruct the stack trace from the desired start point
60
+ // Also, include the error name and message as the first line
61
+ const newStack = [
62
+ `${error.name}: ${error.message}`,
63
+ ...stackLines.slice(newStackStartIndex)
64
+ ].join('\n');
65
+ error.stack = newStack;
66
+ }
67
+ return error;
68
+ }
69
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * An unmodifiable set.
3
+ *
4
+ * An [UnmodifiableSetView] contains a [Set], and prevents that set from being changed through the view.
5
+ * Methods that could change the set, such as [add] and [remove], throw an [UnsupportedError].
6
+ * Permitted operations defer to the wrapped set.
7
+ */
8
+ export class UnmodifiableSetView {
9
+ _set;
10
+ constructor(set) {
11
+ this._set = set;
12
+ }
13
+ has(value) {
14
+ return this._set.has(value);
15
+ }
16
+ get size() {
17
+ return this._set.size;
18
+ }
19
+ forEach(callbackfn, thisArg) {
20
+ return this._set.forEach(callbackfn, thisArg);
21
+ }
22
+ [Symbol.iterator]() {
23
+ return this._set[Symbol.iterator]();
24
+ }
25
+ entries() {
26
+ return this._set.entries();
27
+ }
28
+ values() {
29
+ return this._set.values();
30
+ }
31
+ keys() {
32
+ return this._set.keys();
33
+ }
34
+ add(value) {
35
+ throw new Error('Cannot modify the set. Create a copy in necessary.');
36
+ }
37
+ clear() {
38
+ throw new Error('Cannot modify the set. Create a copy in necessary.');
39
+ }
40
+ delete(value) {
41
+ throw new Error('Cannot modify the set. Create a copy in necessary.');
42
+ }
43
+ get [Symbol.toStringTag]() {
44
+ return this._set[Symbol.toStringTag];
45
+ }
46
+ toString() {
47
+ return Array.from(this).toString();
48
+ }
49
+ ;
50
+ }
@@ -0,0 +1,246 @@
1
+ /**
2
+ * This exception is meant to represent a user input error, and not a bug or
3
+ * a system error. It must not be logged as an error, but instead shown to the
4
+ * user. When dispatched inside a reducer, a dialog will be shown to the user,
5
+ * with the given message.
6
+ *
7
+ * Usage:
8
+ *
9
+ * ```ts
10
+ * // Throws an exception with the given message.
11
+ * throw new UserException('The item already exists');
12
+ *
13
+ * // Throws an exception with the given message and title.
14
+ * throw new UserException('The item already exists', { title: 'Could not add' });
15
+ * ```
16
+ *
17
+ * You can also define a hardCause for the exception:
18
+ * ```ts
19
+ * // Throws an exception with the given message.
20
+ * throw new UserException('The item already exists', {hardCause: someError}});
21
+ * ```
22
+ *
23
+ * The user exception is immutable. But you can use some methods to create a modified copy:
24
+ * - withTitle
25
+ * - withMessage
26
+ * - withHardCause
27
+ * - withDialog
28
+ * - withErrorText
29
+ * - addProps
30
+ * - addCallbacks
31
+ */
32
+ export class UserException extends Error {
33
+ /**
34
+ * The title of the dialog that shows the message.
35
+ */
36
+ title;
37
+ /**
38
+ * The original error that caused the user exception. For example, when validating
39
+ * some user input, if you get a ValidationError, that's the hardCause.
40
+ * Then: `throw new UserException('Invalid number').withHardCause(validationError)`.
41
+ */
42
+ hardCause;
43
+ /**
44
+ * If `true`, throwing the exception will show a dialog or similar UI.
45
+ * If `false` you can still show the error in a different way, usually showing `errorText`
46
+ * in the UI element that is responsible for the error.
47
+ */
48
+ ifOpenDialog;
49
+ /**
50
+ * Some text to be displayed in the UI element that is responsible for the error.
51
+ * For example, a text field could show this as red text, below it.
52
+ * When building your widgets, you can get the `errorText` from the failed action:
53
+ * `errorText = store.exceptionFor(MyAction).errorText`.
54
+ */
55
+ errorText;
56
+ /**
57
+ * Callback to be called after the user views the error, and taps OK in the dialog.
58
+ */
59
+ onOk;
60
+ /**
61
+ * Callback to be called after the user views the error, and taps CANCEL in the dialog.
62
+ */
63
+ onCancel;
64
+ _props;
65
+ constructor(message, { title, hardCause, ifOpenDialog, errorText, onOk, onCancel, props } = {}) {
66
+ super(message);
67
+ this.name = 'UserException';
68
+ this.title = title ?? '';
69
+ this.hardCause = hardCause;
70
+ this.ifOpenDialog = ifOpenDialog ?? true;
71
+ this.errorText = errorText || null;
72
+ this.onOk = onOk;
73
+ this.onCancel = onCancel;
74
+ this._props = props || {};
75
+ // Maintains proper stack trace for where our error was thrown (only available on V8).
76
+ if (Error.captureStackTrace) {
77
+ Error.captureStackTrace(this, UserException);
78
+ }
79
+ }
80
+ /**
81
+ * Returns a copy of the props object.
82
+ * You can add properties to the user exception by using `addProps`.
83
+ */
84
+ get props() {
85
+ return { ...this._props };
86
+ }
87
+ /**
88
+ Adds a title to the exception.
89
+
90
+ Usage:
91
+
92
+ ```ts
93
+ // Throws an exception with the given message and title.
94
+ throw new UserException('The item already exists').withTitle('Could not add');
95
+ ```
96
+ */
97
+ withTitle(title) {
98
+ return new UserException(this.message, {
99
+ title: title,
100
+ hardCause: this.hardCause,
101
+ ifOpenDialog: this.ifOpenDialog,
102
+ errorText: this.errorText
103
+ });
104
+ }
105
+ /**
106
+ Adds a message to the exception.
107
+
108
+ Usage:
109
+
110
+ ```ts
111
+ // Throws an exception with the given message and title.
112
+ throw new UserException('The item already exists').withTitle('Could not add');
113
+ ```
114
+ */
115
+ withMessage(message) {
116
+ return new UserException(message, {
117
+ title: this.title,
118
+ hardCause: this.hardCause,
119
+ ifOpenDialog: this.ifOpenDialog,
120
+ errorText: this.errorText
121
+ });
122
+ }
123
+ /**
124
+ * Adds a hardCause to the exception.
125
+ *
126
+ * Usage:
127
+ *
128
+ * ```ts
129
+ * throw new UserException('The item already exists').withCause(someError);
130
+ * ```
131
+ */
132
+ withHardCause(hardCause) {
133
+ return new UserException(this.message, {
134
+ title: this.title,
135
+ hardCause: hardCause,
136
+ ifOpenDialog: this.ifOpenDialog,
137
+ errorText: this.errorText
138
+ });
139
+ }
140
+ /**
141
+ * If `true`, throwing the exception will show a dialog or similar UI.
142
+ * If `false` you can still show the error in a different way, usually showing `errorText`
143
+ * in the UI element that is responsible for the error.
144
+ *
145
+ * Usage:
146
+ *
147
+ * ```ts
148
+ * throw new UserException('The item already exists').withDialog(false);
149
+ * ```
150
+ *
151
+ */
152
+ withDialog(ifOpenDialog) {
153
+ return new UserException(this.message, {
154
+ title: this.title,
155
+ hardCause: this.hardCause,
156
+ ifOpenDialog: ifOpenDialog,
157
+ errorText: this.errorText
158
+ });
159
+ }
160
+ /**
161
+ * This exception should NOT open a dialog.
162
+ * Still, the error may be shown in a different way, usually showing [errorText]
163
+ * somewhere in the UI.
164
+ * This is the same as doing: `.withDialog(false)`.
165
+ */
166
+ get noDialog() {
167
+ return this.withDialog(false);
168
+ }
169
+ /**
170
+ * Adds some text to be displayed in the UI element that is responsible for the error.
171
+ * For example, a text field could show this as red text, below it.
172
+ *
173
+ * When building your widgets, you can get the `errorText` from the failed action:
174
+ * `errorText = store.exceptionFor(MyAction).errorText`.
175
+ *
176
+ * Usage:
177
+ *
178
+ * ```ts
179
+ * throw new UserException('The item already exists').withDialog(false);
180
+ * ```
181
+ *
182
+ */
183
+ withErrorText(errorText) {
184
+ return new UserException(this.message, {
185
+ title: this.title,
186
+ hardCause: this.hardCause,
187
+ ifOpenDialog: this.ifOpenDialog,
188
+ errorText: errorText,
189
+ });
190
+ }
191
+ /**
192
+ * Adds `moreProps` to the properties of the `UserException`.
193
+ * If the exception already had `props`, the new `moreProps` will be merged with those.
194
+ */
195
+ addProps(moreProps) {
196
+ if (!moreProps)
197
+ return this;
198
+ return new UserException(this.message, {
199
+ title: this.title,
200
+ hardCause: this.hardCause,
201
+ ifOpenDialog: this.ifOpenDialog,
202
+ errorText: this.errorText,
203
+ onOk: this.onOk,
204
+ onCancel: this.onCancel,
205
+ props: { ...this._props, ...moreProps }
206
+ });
207
+ }
208
+ /**
209
+ * Adds callbacks to the `UserException`.
210
+ *
211
+ * This method is used to add `onOk` and `onCancel` callbacks to the `UserException`.
212
+ *
213
+ * The `onOk` callback will be called when the user taps OK in the error dialog.
214
+ * The `onCancel` callback will be called when the user taps CANCEL in the error dialog.
215
+ *
216
+ * If the exception already had callbacks, the new callbacks will be merged with the old ones,
217
+ * and the old callbacks will be called before the new ones.
218
+ */
219
+ addCallbacks(onOk, onCancel) {
220
+ let _onOk;
221
+ let _onCancel;
222
+ if (this.onOk === undefined)
223
+ _onOk = onOk;
224
+ else
225
+ _onOk = () => {
226
+ this.onOk?.();
227
+ onOk?.();
228
+ };
229
+ if (this.onCancel === undefined)
230
+ _onCancel = onCancel;
231
+ else
232
+ _onCancel = () => {
233
+ this.onCancel?.();
234
+ onCancel?.();
235
+ };
236
+ return new UserException(this.message, {
237
+ title: this.title,
238
+ hardCause: this.hardCause,
239
+ ifOpenDialog: this.ifOpenDialog,
240
+ errorText: this.errorText,
241
+ onOk: _onOk,
242
+ onCancel: _onCancel,
243
+ props: this._props
244
+ });
245
+ }
246
+ }
@@ -0,0 +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
+ //
@@ -0,0 +1,9 @@
1
+ import { PersistAction, PersistException, Persistor, PersistorDummy, PersistorPrinterDecorator, } from './Persistor';
2
+ import { ClassPersistor } from './ClassPersistor';
3
+ import { ProcessPersistence } from './ProcessPersistence';
4
+ import { ActionStatus, OptimisticUpdate, KissAction, UserExceptionAction, UpdateStateAction, } from './KissAction';
5
+ import { Store, createStore, StoreProvider } from './Store';
6
+ import { useAllState, useClearExceptionFor, useDispatch, useDispatchAll, useDispatchAndWait, useDispatchAndWaitAll, useDispatcher, useDispatchSync, useExceptionFor, useIsFailed, useIsWaiting, useSelect, useSelector, useStore, } from './Hooks';
7
+ import { StoreException } from './StoreException';
8
+ import { UserException } from './UserException';
9
+ export { Persistor, PersistorPrinterDecorator, PersistorDummy, PersistException, PersistAction, UpdateStateAction, ClassPersistor, ProcessPersistence, KissAction, UserExceptionAction, ActionStatus, Store, createStore, useStore, useAllState, useSelect, useSelector, StoreProvider, useIsWaiting, useIsFailed, useExceptionFor, useClearExceptionFor, useDispatch, useDispatchAll, useDispatchAndWait, useDispatchAndWaitAll, useDispatchSync, useDispatcher, StoreException, UserException, OptimisticUpdate, };