kiss-for-react 1.1.0 → 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 +54 -30
- package/lib/cjs/UnmodifiableSetView.js +0 -53
- package/lib/cjs/types/UnmodifiableSetView.d.ts +0 -24
- package/lib/cjs/types/UnmodifiableSetView.d.ts.map +0 -1
- package/lib/esm/ClassPersistor.js +0 -112
- package/lib/esm/Esserializer/constant.js +0 -81
- package/lib/esm/Esserializer/deserializer.js +0 -307
- package/lib/esm/Esserializer/general.js +0 -34
- package/lib/esm/Esserializer/index.js +0 -39
- package/lib/esm/Esserializer/serializer.js +0 -130
- package/lib/esm/Hooks.js +0 -955
- package/lib/esm/KissAction.js +0 -1459
- package/lib/esm/Persistor.js +0 -113
- package/lib/esm/ProcessPersistence.js +0 -262
- package/lib/esm/Store.js +0 -1606
- package/lib/esm/StoreException.js +0 -69
- package/lib/esm/UnmodifiableSetView.js +0 -50
- package/lib/esm/types/UnmodifiableSetView.d.ts +0 -24
- package/lib/esm/types/UnmodifiableSetView.d.ts.map +0 -1
- package/lib/esm/utils.js +0 -3
package/lib/cjs/UserException.js
CHANGED
|
@@ -1,218 +1,212 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserException = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* This exception is meant to represent a user input error, and not a bug or
|
|
6
|
-
* a system error. It must not be logged as an error, but instead shown to the
|
|
7
|
-
* user. When dispatched inside a reducer, a dialog will be shown to the user,
|
|
8
|
-
* with the given message.
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* // Throws an exception with the given message.
|
|
14
|
-
* throw new UserException('The item already exists');
|
|
15
|
-
*
|
|
16
|
-
* // Throws an exception with the given message and title.
|
|
17
|
-
* throw new UserException('The item already exists', { title: 'Could not add' });
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* You can also define a hardCause for the exception:
|
|
21
|
-
* ```ts
|
|
22
|
-
* // Throws an exception with the given message.
|
|
23
|
-
* throw new UserException('The item already exists', {hardCause: someError}
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* The user exception is immutable. But you can use some methods to create a modified copy:
|
|
27
|
-
* - withTitle
|
|
28
|
-
* - withMessage
|
|
29
|
-
* - withHardCause
|
|
30
|
-
* - withDialog
|
|
31
|
-
* - withErrorText
|
|
32
|
-
* - addProps
|
|
33
|
-
* - addCallbacks
|
|
34
|
-
*/
|
|
35
|
-
class UserException extends Error {
|
|
36
|
-
constructor(message, { title, hardCause, ifOpenDialog, errorText, onOk, onCancel, props } = {}) {
|
|
37
|
-
super(message);
|
|
38
|
-
this.name = 'UserException';
|
|
39
|
-
this.title = title ?? '';
|
|
40
|
-
this.hardCause = hardCause;
|
|
41
|
-
this.ifOpenDialog = ifOpenDialog ?? true;
|
|
42
|
-
this.errorText = errorText || null;
|
|
43
|
-
this.onOk = onOk;
|
|
44
|
-
this.onCancel = onCancel;
|
|
45
|
-
this._props = props || {};
|
|
46
|
-
// Maintains proper stack trace for where our error was thrown (only available on V8).
|
|
47
|
-
if (Error.captureStackTrace) {
|
|
48
|
-
Error.captureStackTrace(this, UserException);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns a copy of the props object.
|
|
53
|
-
* You can add properties to the user exception by using `addProps`.
|
|
54
|
-
*/
|
|
55
|
-
get props() {
|
|
56
|
-
return { ...this._props };
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
Adds a title to the exception.
|
|
60
|
-
|
|
61
|
-
Usage:
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
// Throws an exception with the given message and title.
|
|
65
|
-
throw new UserException('The item already exists').withTitle('Could not add');
|
|
66
|
-
```
|
|
67
|
-
*/
|
|
68
|
-
withTitle(title) {
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* in the UI
|
|
115
|
-
*
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
onCancel: _onCancel,
|
|
214
|
-
props: this._props
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
exports.UserException = UserException;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserException = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This exception is meant to represent a user input error, and not a bug or
|
|
6
|
+
* a system error. It must not be logged as an error, but instead shown to the
|
|
7
|
+
* user. When dispatched inside a reducer, a dialog will be shown to the user,
|
|
8
|
+
* with the given message.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Throws an exception with the given message.
|
|
14
|
+
* throw new UserException('The item already exists');
|
|
15
|
+
*
|
|
16
|
+
* // Throws an exception with the given message and title.
|
|
17
|
+
* throw new UserException('The item already exists', { title: 'Could not add' });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* You can also define a hardCause for the exception:
|
|
21
|
+
* ```ts
|
|
22
|
+
* // Throws an exception with the given message.
|
|
23
|
+
* throw new UserException('The item already exists', {hardCause: someError});
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* The user exception is immutable. But you can use some methods to create a modified copy:
|
|
27
|
+
* - withTitle
|
|
28
|
+
* - withMessage
|
|
29
|
+
* - withHardCause
|
|
30
|
+
* - withDialog
|
|
31
|
+
* - withErrorText
|
|
32
|
+
* - addProps
|
|
33
|
+
* - addCallbacks
|
|
34
|
+
*/
|
|
35
|
+
class UserException extends Error {
|
|
36
|
+
constructor(message, { title, hardCause, ifOpenDialog, errorText, onOk, onCancel, props } = {}) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = 'UserException';
|
|
39
|
+
this.title = title ?? '';
|
|
40
|
+
this.hardCause = hardCause;
|
|
41
|
+
this.ifOpenDialog = ifOpenDialog ?? true;
|
|
42
|
+
this.errorText = errorText || null;
|
|
43
|
+
this.onOk = onOk;
|
|
44
|
+
this.onCancel = onCancel;
|
|
45
|
+
this._props = props || {};
|
|
46
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8).
|
|
47
|
+
if (Error.captureStackTrace) {
|
|
48
|
+
Error.captureStackTrace(this, UserException);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns a copy of the props object.
|
|
53
|
+
* You can add properties to the user exception by using `addProps`.
|
|
54
|
+
*/
|
|
55
|
+
get props() {
|
|
56
|
+
return { ...this._props };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
Adds a title to the exception.
|
|
60
|
+
|
|
61
|
+
Usage:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// Throws an exception with the given message and title.
|
|
65
|
+
throw new UserException('The item already exists').withTitle('Could not add');
|
|
66
|
+
```
|
|
67
|
+
*/
|
|
68
|
+
withTitle(title) {
|
|
69
|
+
return this.copy({ title });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
Adds a message to the exception.
|
|
73
|
+
|
|
74
|
+
Usage:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// Throws an exception with the given message and title.
|
|
78
|
+
throw new UserException('The item already exists').withTitle('Could not add');
|
|
79
|
+
```
|
|
80
|
+
*/
|
|
81
|
+
withMessage(message) {
|
|
82
|
+
return this.copy({ message });
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Adds a hardCause to the exception.
|
|
86
|
+
*
|
|
87
|
+
* Usage:
|
|
88
|
+
*
|
|
89
|
+
* ```ts
|
|
90
|
+
* throw new UserException('The item already exists').withHardCause(someError);
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
withHardCause(hardCause) {
|
|
94
|
+
return this.copy({ hardCause });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* If `true`, throwing the exception will show a dialog or similar UI.
|
|
98
|
+
* If `false` you can still show the error in a different way, usually showing `errorText`
|
|
99
|
+
* in the UI element that is responsible for the error.
|
|
100
|
+
*
|
|
101
|
+
* Usage:
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* throw new UserException('The item already exists').withDialog(false);
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
withDialog(ifOpenDialog) {
|
|
109
|
+
return this.copy({ ifOpenDialog });
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* This exception should NOT open a dialog.
|
|
113
|
+
* Still, the error may be shown in a different way, usually showing [errorText]
|
|
114
|
+
* somewhere in the UI.
|
|
115
|
+
* This is the same as doing: `.withDialog(false)`.
|
|
116
|
+
*/
|
|
117
|
+
get noDialog() {
|
|
118
|
+
return this.withDialog(false);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Adds some text to be displayed in the UI element that is responsible for the error.
|
|
122
|
+
* For example, a text field could show this as red text, below it.
|
|
123
|
+
*
|
|
124
|
+
* When building your widgets, you can get the `errorText` from the failed action:
|
|
125
|
+
* `errorText = store.exceptionFor(MyAction)?.errorText`.
|
|
126
|
+
*
|
|
127
|
+
* Usage:
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* throw new UserException('The item already exists').withDialog(false);
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
withErrorText(errorText) {
|
|
135
|
+
return this.copy({ errorText });
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Adds `moreProps` to the properties of the `UserException`.
|
|
139
|
+
* If the exception already had `props`, the new `moreProps` will be merged with those.
|
|
140
|
+
*/
|
|
141
|
+
addProps(moreProps) {
|
|
142
|
+
if (!moreProps)
|
|
143
|
+
return this;
|
|
144
|
+
return this.copy({ props: { ...this._props, ...moreProps } });
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Adds callbacks to the `UserException`.
|
|
148
|
+
*
|
|
149
|
+
* This method is used to add `onOk` and `onCancel` callbacks to the `UserException`.
|
|
150
|
+
*
|
|
151
|
+
* The `onOk` callback will be called when the user taps OK in the error dialog.
|
|
152
|
+
* The `onCancel` callback will be called when the user taps CANCEL in the error dialog.
|
|
153
|
+
*
|
|
154
|
+
* If the exception already had callbacks, the new callbacks will be merged with the old ones,
|
|
155
|
+
* and the old callbacks will be called before the new ones.
|
|
156
|
+
*/
|
|
157
|
+
addCallbacks(onOk, onCancel) {
|
|
158
|
+
let _onOk;
|
|
159
|
+
let _onCancel;
|
|
160
|
+
if (this.onOk === undefined)
|
|
161
|
+
_onOk = onOk;
|
|
162
|
+
else
|
|
163
|
+
_onOk = () => {
|
|
164
|
+
this.onOk?.();
|
|
165
|
+
onOk?.();
|
|
166
|
+
};
|
|
167
|
+
if (this.onCancel === undefined)
|
|
168
|
+
_onCancel = onCancel;
|
|
169
|
+
else
|
|
170
|
+
_onCancel = () => {
|
|
171
|
+
this.onCancel?.();
|
|
172
|
+
onCancel?.();
|
|
173
|
+
};
|
|
174
|
+
return this.copy({ onOk: _onOk, onCancel: _onCancel });
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Returns a new exception with the same fields as this one,
|
|
178
|
+
* except for the ones given in `changes`.
|
|
179
|
+
*
|
|
180
|
+
* The copy has the same prototype as this exception, so it keeps its subclass, and the
|
|
181
|
+
* fields of the subclass. The constructor of the subclass is not called, since it may
|
|
182
|
+
* take different parameters.
|
|
183
|
+
*/
|
|
184
|
+
copy(changes) {
|
|
185
|
+
const has = (key) => Object.prototype.hasOwnProperty.call(changes, key);
|
|
186
|
+
const copy = Object.create(Object.getPrototypeOf(this));
|
|
187
|
+
Object.defineProperties(copy, Object.getOwnPropertyDescriptors(this));
|
|
188
|
+
// Same defaults as the constructor.
|
|
189
|
+
if (has('message'))
|
|
190
|
+
copy.message = changes.message;
|
|
191
|
+
if (has('title'))
|
|
192
|
+
copy.title = changes.title ?? '';
|
|
193
|
+
if (has('hardCause'))
|
|
194
|
+
copy.hardCause = changes.hardCause;
|
|
195
|
+
if (has('ifOpenDialog'))
|
|
196
|
+
copy.ifOpenDialog = changes.ifOpenDialog ?? true;
|
|
197
|
+
if (has('errorText'))
|
|
198
|
+
copy.errorText = changes.errorText || null;
|
|
199
|
+
if (has('onOk'))
|
|
200
|
+
copy.onOk = changes.onOk;
|
|
201
|
+
if (has('onCancel'))
|
|
202
|
+
copy.onCancel = changes.onCancel;
|
|
203
|
+
if (has('props'))
|
|
204
|
+
copy._props = changes.props || {};
|
|
205
|
+
// The copy gets its own stack trace, from where it was made, like a new exception would.
|
|
206
|
+
if (Error.captureStackTrace) {
|
|
207
|
+
Error.captureStackTrace(copy, this.copy);
|
|
208
|
+
}
|
|
209
|
+
return copy;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.UserException = UserException;
|