ctrl-fx 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/chunk-DZAR6PTR.js +3966 -0
- package/dist/chunk-KNHJPAIU.js +1800 -0
- package/dist/chunk-NSWOTCDU.js +916 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/chunk-XICUXW4T.js +252 -0
- package/dist/db/index.d.ts +234 -0
- package/dist/db/index.js +53 -0
- package/dist/dom/index.d.ts +2 -0
- package/dist/dom/index.js +30 -0
- package/dist/effects.d.ts +2 -0
- package/dist/effects.js +111 -0
- package/dist/index-fpCmXVEu.d.ts +1391 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/router.d.ts +39 -0
- package/dist/router.js +66 -0
- package/dist/testing.d.ts +254 -0
- package/dist/testing.js +40 -0
- package/dist/webcomponent.d.ts +18 -0
- package/dist/webcomponent.js +51 -0
- package/package.json +4 -3
|
@@ -0,0 +1,1800 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "./chunk-PKBMQBKP.js";
|
|
4
|
+
|
|
5
|
+
// src/utils/result.ts
|
|
6
|
+
function map(f) {
|
|
7
|
+
return (result) => {
|
|
8
|
+
switch (result._tag) {
|
|
9
|
+
case "failure": {
|
|
10
|
+
return failure(result.error);
|
|
11
|
+
}
|
|
12
|
+
case "success": {
|
|
13
|
+
return success(f(result.value));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function andThen(f) {
|
|
19
|
+
return (result) => {
|
|
20
|
+
switch (result._tag) {
|
|
21
|
+
case "failure": {
|
|
22
|
+
return failure(result.error);
|
|
23
|
+
}
|
|
24
|
+
case "success": {
|
|
25
|
+
return f(result.value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function success(value) {
|
|
31
|
+
return {
|
|
32
|
+
_tag: "success",
|
|
33
|
+
value,
|
|
34
|
+
map(f) {
|
|
35
|
+
return map(f)(this);
|
|
36
|
+
},
|
|
37
|
+
andThen(f) {
|
|
38
|
+
return andThen(f)(this);
|
|
39
|
+
},
|
|
40
|
+
errorMap(f) {
|
|
41
|
+
return errorMap(f)(this);
|
|
42
|
+
},
|
|
43
|
+
merge() {
|
|
44
|
+
return value;
|
|
45
|
+
},
|
|
46
|
+
recover(_f) {
|
|
47
|
+
return success(value);
|
|
48
|
+
},
|
|
49
|
+
fold(onSuccess, _onError) {
|
|
50
|
+
return onSuccess(value);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function failure(error) {
|
|
55
|
+
return {
|
|
56
|
+
_tag: "failure",
|
|
57
|
+
error,
|
|
58
|
+
map(f) {
|
|
59
|
+
return map(f)(this);
|
|
60
|
+
},
|
|
61
|
+
andThen(f) {
|
|
62
|
+
return andThen(f)(this);
|
|
63
|
+
},
|
|
64
|
+
errorMap(f) {
|
|
65
|
+
return errorMap(f)(this);
|
|
66
|
+
},
|
|
67
|
+
merge() {
|
|
68
|
+
return error;
|
|
69
|
+
},
|
|
70
|
+
recover(f) {
|
|
71
|
+
return f(error);
|
|
72
|
+
},
|
|
73
|
+
fold(_onSuccess, onError) {
|
|
74
|
+
return onError(error);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function errorMap(f) {
|
|
79
|
+
return (result) => {
|
|
80
|
+
switch (result._tag) {
|
|
81
|
+
case "failure": {
|
|
82
|
+
return failure(f(result.error));
|
|
83
|
+
}
|
|
84
|
+
case "success": {
|
|
85
|
+
return success(result.value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/net/index.ts
|
|
92
|
+
var Json = class {
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
+
constructor(wrapped) {
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
+
__publicField(this, "wrapped");
|
|
97
|
+
this.wrapped = wrapped;
|
|
98
|
+
}
|
|
99
|
+
decodeUnsafe() {
|
|
100
|
+
return this.wrapped;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var ResponseBody = class {
|
|
104
|
+
constructor(data) {
|
|
105
|
+
__publicField(this, "data");
|
|
106
|
+
this.data = data;
|
|
107
|
+
}
|
|
108
|
+
asString() {
|
|
109
|
+
return new TextDecoder().decode(this.data);
|
|
110
|
+
}
|
|
111
|
+
asBlob() {
|
|
112
|
+
return new Blob([this.data]);
|
|
113
|
+
}
|
|
114
|
+
asJson() {
|
|
115
|
+
try {
|
|
116
|
+
return success(new Json(JSON.parse(this.asString())));
|
|
117
|
+
} catch (err) {
|
|
118
|
+
if (err instanceof SyntaxError) {
|
|
119
|
+
return failure({ _type: "DecodingError", message: err.message });
|
|
120
|
+
} else {
|
|
121
|
+
return failure({
|
|
122
|
+
_type: "DecodingError",
|
|
123
|
+
message: `Unexpected decoding error: ${err}`
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function getJson(uri) {
|
|
130
|
+
return makeHttpRequest({
|
|
131
|
+
uri,
|
|
132
|
+
method: "GET",
|
|
133
|
+
headers: {}
|
|
134
|
+
}).map(
|
|
135
|
+
(result) => result.andThen((rsp) => {
|
|
136
|
+
return rsp.body.asJson();
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/utils/index.ts
|
|
142
|
+
var todo = () => {
|
|
143
|
+
throw new Error("Unimplemented");
|
|
144
|
+
};
|
|
145
|
+
function exhaustivenessCheck(value) {
|
|
146
|
+
throw new Error(`Unhandled: ${value}`);
|
|
147
|
+
}
|
|
148
|
+
function eq(value1, value2) {
|
|
149
|
+
if (typeof value1 !== typeof value2) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
if (value1 === null) {
|
|
153
|
+
return value2 === null;
|
|
154
|
+
}
|
|
155
|
+
if (value2 === null) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (value1 === void 0) {
|
|
159
|
+
return value2 === void 0;
|
|
160
|
+
}
|
|
161
|
+
if (value2 === void 0) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
if (typeof value1 === "function") {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
if (typeof value1 !== "object") {
|
|
168
|
+
return value1 === value2;
|
|
169
|
+
}
|
|
170
|
+
if (Array.isArray(value1)) {
|
|
171
|
+
if (!Array.isArray(value2)) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (value1.length != value2.length) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
for (let i = 0; i < value1.length; i++) {
|
|
178
|
+
if (!eq(value1[i], value2[i])) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
} else if (Array.isArray(value2)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
if (typeof value1 === "object") {
|
|
187
|
+
const keys1 = Object.keys(value1);
|
|
188
|
+
const keys2 = Object.keys(value2);
|
|
189
|
+
if (keys1.length !== keys2.length) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
for (const key of keys1) {
|
|
193
|
+
if (!Object.prototype.hasOwnProperty.call(value2, key)) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
if (!eq(value1[key], value2[key])) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
return `${value1}` === `${value2}`;
|
|
203
|
+
}
|
|
204
|
+
function stringToInt(s) {
|
|
205
|
+
const result = Number.parseInt(s);
|
|
206
|
+
if (Number.isNaN(result)) {
|
|
207
|
+
return void 0;
|
|
208
|
+
} else {
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function filterNot(value, f) {
|
|
213
|
+
if (value !== void 0) {
|
|
214
|
+
return f(value) ? void 0 : value;
|
|
215
|
+
} else {
|
|
216
|
+
return void 0;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/net/path.ts
|
|
221
|
+
var emptyPath = {
|
|
222
|
+
elems: [],
|
|
223
|
+
format() {
|
|
224
|
+
return "";
|
|
225
|
+
},
|
|
226
|
+
matches(that) {
|
|
227
|
+
return that.elems.length === 0;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
function parsePath(s) {
|
|
231
|
+
return {
|
|
232
|
+
elems: s.split("/"),
|
|
233
|
+
format() {
|
|
234
|
+
return this.elems.join("/");
|
|
235
|
+
},
|
|
236
|
+
matches(that) {
|
|
237
|
+
if (this.elems.length !== that.elems.length) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
for (let i = 0; i < this.elems.length; i++) {
|
|
241
|
+
if (this.elems[i].toLocaleLowerCase() !== that.elems[i].toLocaleLowerCase()) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/net/fragment.ts
|
|
251
|
+
function parseFragment(str) {
|
|
252
|
+
const normalizedInput = (str.startsWith("#") ? str.substring(1) : str).trim();
|
|
253
|
+
if (normalizedInput.length === 0) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const questionMark = normalizedInput.indexOf("?");
|
|
257
|
+
if (questionMark <= -1) {
|
|
258
|
+
return {
|
|
259
|
+
path: parsePath(normalizedInput),
|
|
260
|
+
queryParams: [],
|
|
261
|
+
format: normalizedInput
|
|
262
|
+
};
|
|
263
|
+
} else {
|
|
264
|
+
return todo();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/net/queryparam.ts
|
|
269
|
+
function parseQueryParam(str) {
|
|
270
|
+
const eqIndx = str.indexOf("=");
|
|
271
|
+
if (eqIndx < 0) {
|
|
272
|
+
return {
|
|
273
|
+
name: str,
|
|
274
|
+
format: str
|
|
275
|
+
};
|
|
276
|
+
} else {
|
|
277
|
+
const name = str.substring(0, eqIndx);
|
|
278
|
+
const value = str.substring(eqIndx + 1);
|
|
279
|
+
return {
|
|
280
|
+
name,
|
|
281
|
+
value,
|
|
282
|
+
format: str
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function parseAllQueryParams(str) {
|
|
287
|
+
const normalizedInput = str.startsWith("?") ? str.substring(1) : str;
|
|
288
|
+
const qps = normalizedInput.split("&").filter((s) => s.length > 0);
|
|
289
|
+
return qps.map(parseQueryParam);
|
|
290
|
+
}
|
|
291
|
+
function formatQueryString(queryParams) {
|
|
292
|
+
if (queryParams.length === 0) {
|
|
293
|
+
return "";
|
|
294
|
+
} else {
|
|
295
|
+
return "?" + queryParams.map((qp) => qp.format).join("&");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/net/location.ts
|
|
300
|
+
function formatLocation(loc) {
|
|
301
|
+
return `${loc.path.format()}${formatQueryString(loc.queryParams)}${loc.fragment != null ? "#" + loc.fragment.format : ""}`;
|
|
302
|
+
}
|
|
303
|
+
function parseInternalLocation(s) {
|
|
304
|
+
const fragStart = s.indexOf("#");
|
|
305
|
+
let pathAndParams, fragment;
|
|
306
|
+
if (fragStart < 0) {
|
|
307
|
+
pathAndParams = s;
|
|
308
|
+
fragment = void 0;
|
|
309
|
+
} else {
|
|
310
|
+
pathAndParams = s.substring(0, fragStart);
|
|
311
|
+
fragment = parseFragment(s.substring(fragStart + 1));
|
|
312
|
+
}
|
|
313
|
+
let path, queryParams;
|
|
314
|
+
const paramsStart = pathAndParams.indexOf("?");
|
|
315
|
+
if (paramsStart < 0) {
|
|
316
|
+
path = parsePath(pathAndParams);
|
|
317
|
+
queryParams = [];
|
|
318
|
+
} else {
|
|
319
|
+
path = parsePath(pathAndParams.substring(0, paramsStart));
|
|
320
|
+
queryParams = parseAllQueryParams(pathAndParams.substring(paramsStart + 1));
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
path,
|
|
324
|
+
queryParams,
|
|
325
|
+
fragment
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function internalLocationFromLocation(location) {
|
|
329
|
+
return {
|
|
330
|
+
path: location.path,
|
|
331
|
+
queryParams: location.queryParams,
|
|
332
|
+
fragment: location.fragment
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
var emptyLocation = parseInternalLocation("");
|
|
336
|
+
|
|
337
|
+
// src/effects.ts
|
|
338
|
+
function taskId(id) {
|
|
339
|
+
return id;
|
|
340
|
+
}
|
|
341
|
+
function customEffect(f, test) {
|
|
342
|
+
return (args) => ({
|
|
343
|
+
_type: "Suspend",
|
|
344
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
345
|
+
operation: { _type: "CustomEffect", input: { args, f, test } },
|
|
346
|
+
flatMap(fn) {
|
|
347
|
+
return flatMap(this, fn);
|
|
348
|
+
},
|
|
349
|
+
and(effect) {
|
|
350
|
+
return flatMap(this, (_) => effect);
|
|
351
|
+
},
|
|
352
|
+
map(fn) {
|
|
353
|
+
return flatMap(this, (out) => pure(fn(out)));
|
|
354
|
+
},
|
|
355
|
+
as(b) {
|
|
356
|
+
return flatMap(this, (_) => pure(b));
|
|
357
|
+
},
|
|
358
|
+
void() {
|
|
359
|
+
return this.map((_out) => {
|
|
360
|
+
});
|
|
361
|
+
},
|
|
362
|
+
apply(fn) {
|
|
363
|
+
return fn(this);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
function flatMap(effect, next) {
|
|
368
|
+
return {
|
|
369
|
+
_type: "FlatMap",
|
|
370
|
+
effect,
|
|
371
|
+
next,
|
|
372
|
+
flatMap(f) {
|
|
373
|
+
return flatMap(this, f);
|
|
374
|
+
},
|
|
375
|
+
and(effect2) {
|
|
376
|
+
return flatMap(this, (_) => effect2);
|
|
377
|
+
},
|
|
378
|
+
map(f) {
|
|
379
|
+
return this.flatMap((b) => pure(f(b)));
|
|
380
|
+
},
|
|
381
|
+
as(c) {
|
|
382
|
+
return this.flatMap((_) => pure(c));
|
|
383
|
+
},
|
|
384
|
+
void() {
|
|
385
|
+
return this.map((_b) => {
|
|
386
|
+
});
|
|
387
|
+
},
|
|
388
|
+
apply(f) {
|
|
389
|
+
return f(this);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function pure(value) {
|
|
394
|
+
return {
|
|
395
|
+
_type: "Return",
|
|
396
|
+
value,
|
|
397
|
+
flatMap(f) {
|
|
398
|
+
return flatMap(this, f);
|
|
399
|
+
},
|
|
400
|
+
and(effect) {
|
|
401
|
+
return flatMap(this, (_) => effect);
|
|
402
|
+
},
|
|
403
|
+
map(f) {
|
|
404
|
+
return flatMap(this, (a) => pure(f(a)));
|
|
405
|
+
},
|
|
406
|
+
as(b) {
|
|
407
|
+
return flatMap(this, (_) => pure(b));
|
|
408
|
+
},
|
|
409
|
+
void() {
|
|
410
|
+
return this.map((_b) => {
|
|
411
|
+
});
|
|
412
|
+
},
|
|
413
|
+
apply(f) {
|
|
414
|
+
return f(this);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function alert(message) {
|
|
419
|
+
return {
|
|
420
|
+
_type: "Suspend",
|
|
421
|
+
operation: {
|
|
422
|
+
_type: "Alert",
|
|
423
|
+
input: message
|
|
424
|
+
},
|
|
425
|
+
flatMap(f) {
|
|
426
|
+
return flatMap(this, f);
|
|
427
|
+
},
|
|
428
|
+
and(effect) {
|
|
429
|
+
return flatMap(this, (_) => effect);
|
|
430
|
+
},
|
|
431
|
+
map(f) {
|
|
432
|
+
return flatMap(this, () => pure(f()));
|
|
433
|
+
},
|
|
434
|
+
as(b) {
|
|
435
|
+
return flatMap(this, () => pure(b));
|
|
436
|
+
},
|
|
437
|
+
void() {
|
|
438
|
+
return this.map((_b) => {
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
apply(f) {
|
|
442
|
+
return f(this);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function confirm(message) {
|
|
447
|
+
return {
|
|
448
|
+
_type: "Suspend",
|
|
449
|
+
operation: { _type: "Confirm", input: message },
|
|
450
|
+
flatMap(f) {
|
|
451
|
+
return flatMap(this, f);
|
|
452
|
+
},
|
|
453
|
+
and(effect) {
|
|
454
|
+
return flatMap(this, (_) => effect);
|
|
455
|
+
},
|
|
456
|
+
map(f) {
|
|
457
|
+
return flatMap(this, (b) => pure(f(b)));
|
|
458
|
+
},
|
|
459
|
+
as(b) {
|
|
460
|
+
return flatMap(this, () => pure(b));
|
|
461
|
+
},
|
|
462
|
+
void() {
|
|
463
|
+
return this.map((_b) => {
|
|
464
|
+
});
|
|
465
|
+
},
|
|
466
|
+
apply(f) {
|
|
467
|
+
return f(this);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
function prompt(message, defaultValue) {
|
|
472
|
+
return {
|
|
473
|
+
_type: "Suspend",
|
|
474
|
+
operation: { _type: "Prompt", input: { message, default: defaultValue } },
|
|
475
|
+
flatMap(f) {
|
|
476
|
+
return flatMap(this, f);
|
|
477
|
+
},
|
|
478
|
+
and(effect) {
|
|
479
|
+
return flatMap(this, (_) => effect);
|
|
480
|
+
},
|
|
481
|
+
map(f) {
|
|
482
|
+
return flatMap(this, (s) => pure(f(s)));
|
|
483
|
+
},
|
|
484
|
+
as(b) {
|
|
485
|
+
return flatMap(this, () => pure(b));
|
|
486
|
+
},
|
|
487
|
+
void() {
|
|
488
|
+
return this.map((_b) => {
|
|
489
|
+
});
|
|
490
|
+
},
|
|
491
|
+
apply(f) {
|
|
492
|
+
return f(this);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function clearAppBadge() {
|
|
497
|
+
return {
|
|
498
|
+
_type: "Suspend",
|
|
499
|
+
operation: { _type: "ClearAppBadge", input: void 0 },
|
|
500
|
+
flatMap(f) {
|
|
501
|
+
return flatMap(this, f);
|
|
502
|
+
},
|
|
503
|
+
and(effect) {
|
|
504
|
+
return flatMap(this, (_) => effect);
|
|
505
|
+
},
|
|
506
|
+
map(f) {
|
|
507
|
+
return flatMap(this, () => pure(f()));
|
|
508
|
+
},
|
|
509
|
+
as(b) {
|
|
510
|
+
return flatMap(this, () => pure(b));
|
|
511
|
+
},
|
|
512
|
+
void() {
|
|
513
|
+
return this.map((_b) => {
|
|
514
|
+
});
|
|
515
|
+
},
|
|
516
|
+
apply(f) {
|
|
517
|
+
return f(this);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
function readClipboard() {
|
|
522
|
+
return {
|
|
523
|
+
_type: "Suspend",
|
|
524
|
+
operation: { _type: "ReadClipboard", input: void 0 },
|
|
525
|
+
flatMap(f) {
|
|
526
|
+
return flatMap(this, f);
|
|
527
|
+
},
|
|
528
|
+
and(effect) {
|
|
529
|
+
return flatMap(this, (_) => effect);
|
|
530
|
+
},
|
|
531
|
+
map(f) {
|
|
532
|
+
return flatMap(this, (result) => pure(f(result)));
|
|
533
|
+
},
|
|
534
|
+
as(b) {
|
|
535
|
+
return flatMap(this, () => pure(b));
|
|
536
|
+
},
|
|
537
|
+
void() {
|
|
538
|
+
return this.map((_b) => {
|
|
539
|
+
});
|
|
540
|
+
},
|
|
541
|
+
apply(f) {
|
|
542
|
+
return f(this);
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
function writeClipboard(text) {
|
|
547
|
+
return {
|
|
548
|
+
_type: "Suspend",
|
|
549
|
+
operation: { _type: "WriteClipboard", input: text },
|
|
550
|
+
flatMap(f) {
|
|
551
|
+
return flatMap(this, f);
|
|
552
|
+
},
|
|
553
|
+
and(effect) {
|
|
554
|
+
return flatMap(this, (_) => effect);
|
|
555
|
+
},
|
|
556
|
+
map(f) {
|
|
557
|
+
return flatMap(this, (result) => pure(f(result)));
|
|
558
|
+
},
|
|
559
|
+
as(b) {
|
|
560
|
+
return flatMap(this, () => pure(b));
|
|
561
|
+
},
|
|
562
|
+
void() {
|
|
563
|
+
return this.map((_b) => {
|
|
564
|
+
});
|
|
565
|
+
},
|
|
566
|
+
apply(f) {
|
|
567
|
+
return f(this);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
function setDocumentTitle(title) {
|
|
572
|
+
return {
|
|
573
|
+
_type: "Suspend",
|
|
574
|
+
operation: { _type: "SetDocumentTitle", input: title },
|
|
575
|
+
flatMap(f) {
|
|
576
|
+
return flatMap(this, f);
|
|
577
|
+
},
|
|
578
|
+
and(effect) {
|
|
579
|
+
return flatMap(this, (_) => effect);
|
|
580
|
+
},
|
|
581
|
+
map(f) {
|
|
582
|
+
return flatMap(this, () => pure(f()));
|
|
583
|
+
},
|
|
584
|
+
as(b) {
|
|
585
|
+
return flatMap(this, () => pure(b));
|
|
586
|
+
},
|
|
587
|
+
void() {
|
|
588
|
+
return this.map((_b) => {
|
|
589
|
+
});
|
|
590
|
+
},
|
|
591
|
+
apply(f) {
|
|
592
|
+
return f(this);
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function setAppBadge(count) {
|
|
597
|
+
return {
|
|
598
|
+
_type: "Suspend",
|
|
599
|
+
operation: { _type: "SetAppBadge", input: count },
|
|
600
|
+
flatMap(f) {
|
|
601
|
+
return flatMap(this, f);
|
|
602
|
+
},
|
|
603
|
+
and(effect) {
|
|
604
|
+
return flatMap(this, (_) => effect);
|
|
605
|
+
},
|
|
606
|
+
map(f) {
|
|
607
|
+
return flatMap(this, () => pure(f()));
|
|
608
|
+
},
|
|
609
|
+
as(b) {
|
|
610
|
+
return flatMap(this, () => pure(b));
|
|
611
|
+
},
|
|
612
|
+
void() {
|
|
613
|
+
return this.map((_b) => {
|
|
614
|
+
});
|
|
615
|
+
},
|
|
616
|
+
apply(f) {
|
|
617
|
+
return f(this);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function async(effect, delayInMillis = 0) {
|
|
622
|
+
return {
|
|
623
|
+
_type: "Suspend",
|
|
624
|
+
operation: {
|
|
625
|
+
_type: "Async",
|
|
626
|
+
input: { effect, delayInMillis }
|
|
627
|
+
},
|
|
628
|
+
flatMap(f) {
|
|
629
|
+
return flatMap(this, f);
|
|
630
|
+
},
|
|
631
|
+
and(effect2) {
|
|
632
|
+
return flatMap(this, (_) => effect2);
|
|
633
|
+
},
|
|
634
|
+
map(f) {
|
|
635
|
+
return flatMap(this, (_) => pure(f()));
|
|
636
|
+
},
|
|
637
|
+
as(b) {
|
|
638
|
+
return flatMap(this, (_) => pure(b));
|
|
639
|
+
},
|
|
640
|
+
void() {
|
|
641
|
+
return this.map((_b) => {
|
|
642
|
+
});
|
|
643
|
+
},
|
|
644
|
+
apply(f) {
|
|
645
|
+
return f(this);
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
function cancelTask(taskId2) {
|
|
650
|
+
return {
|
|
651
|
+
_type: "Suspend",
|
|
652
|
+
operation: {
|
|
653
|
+
_type: "CancelTask",
|
|
654
|
+
input: taskId2
|
|
655
|
+
},
|
|
656
|
+
flatMap(f) {
|
|
657
|
+
return flatMap(this, f);
|
|
658
|
+
},
|
|
659
|
+
and(effect) {
|
|
660
|
+
return flatMap(this, (_) => effect);
|
|
661
|
+
},
|
|
662
|
+
map(f) {
|
|
663
|
+
return flatMap(this, () => pure(f()));
|
|
664
|
+
},
|
|
665
|
+
as(b) {
|
|
666
|
+
return flatMap(this, () => pure(b));
|
|
667
|
+
},
|
|
668
|
+
void() {
|
|
669
|
+
return this.map((_b) => {
|
|
670
|
+
});
|
|
671
|
+
},
|
|
672
|
+
apply(f) {
|
|
673
|
+
return f(this);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function fireEvent(event) {
|
|
678
|
+
return {
|
|
679
|
+
_type: "Suspend",
|
|
680
|
+
operation: {
|
|
681
|
+
_type: "FireEvent",
|
|
682
|
+
input: event
|
|
683
|
+
},
|
|
684
|
+
flatMap(f) {
|
|
685
|
+
return flatMap(this, f);
|
|
686
|
+
},
|
|
687
|
+
and(effect) {
|
|
688
|
+
return flatMap(this, (_) => effect);
|
|
689
|
+
},
|
|
690
|
+
map(f) {
|
|
691
|
+
return flatMap(this, () => pure(f()));
|
|
692
|
+
},
|
|
693
|
+
as(b) {
|
|
694
|
+
return flatMap(this, () => pure(b));
|
|
695
|
+
},
|
|
696
|
+
void() {
|
|
697
|
+
return this.map((_b) => {
|
|
698
|
+
});
|
|
699
|
+
},
|
|
700
|
+
apply(f) {
|
|
701
|
+
return f(this);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function generateUuid() {
|
|
706
|
+
return {
|
|
707
|
+
_type: "Suspend",
|
|
708
|
+
operation: {
|
|
709
|
+
_type: "GenerateUuid",
|
|
710
|
+
input: void 0
|
|
711
|
+
},
|
|
712
|
+
flatMap(f) {
|
|
713
|
+
return flatMap(this, f);
|
|
714
|
+
},
|
|
715
|
+
and(effect) {
|
|
716
|
+
return flatMap(this, (_) => effect);
|
|
717
|
+
},
|
|
718
|
+
map(f) {
|
|
719
|
+
return flatMap(this, (uuid) => pure(f(uuid)));
|
|
720
|
+
},
|
|
721
|
+
as(b) {
|
|
722
|
+
return flatMap(this, () => pure(b));
|
|
723
|
+
},
|
|
724
|
+
void() {
|
|
725
|
+
return this.map((_b) => {
|
|
726
|
+
});
|
|
727
|
+
},
|
|
728
|
+
apply(f) {
|
|
729
|
+
return f(this);
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
function getTime() {
|
|
734
|
+
return {
|
|
735
|
+
_type: "Suspend",
|
|
736
|
+
operation: {
|
|
737
|
+
_type: "GetTime",
|
|
738
|
+
input: void 0
|
|
739
|
+
},
|
|
740
|
+
flatMap(f) {
|
|
741
|
+
return flatMap(this, f);
|
|
742
|
+
},
|
|
743
|
+
and(effect) {
|
|
744
|
+
return flatMap(this, (_) => effect);
|
|
745
|
+
},
|
|
746
|
+
map(f) {
|
|
747
|
+
return flatMap(this, (date) => pure(f(date)));
|
|
748
|
+
},
|
|
749
|
+
as(b) {
|
|
750
|
+
return flatMap(this, () => pure(b));
|
|
751
|
+
},
|
|
752
|
+
void() {
|
|
753
|
+
return this.map((_b) => {
|
|
754
|
+
});
|
|
755
|
+
},
|
|
756
|
+
apply(f) {
|
|
757
|
+
return f(this);
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
function getRandom() {
|
|
762
|
+
return {
|
|
763
|
+
_type: "Suspend",
|
|
764
|
+
operation: {
|
|
765
|
+
_type: "GetRandom",
|
|
766
|
+
input: void 0
|
|
767
|
+
},
|
|
768
|
+
flatMap(f) {
|
|
769
|
+
return flatMap(this, f);
|
|
770
|
+
},
|
|
771
|
+
and(effect) {
|
|
772
|
+
return flatMap(this, (_) => effect);
|
|
773
|
+
},
|
|
774
|
+
map(f) {
|
|
775
|
+
return flatMap(this, (n) => pure(f(n)));
|
|
776
|
+
},
|
|
777
|
+
as(b) {
|
|
778
|
+
return flatMap(this, () => pure(b));
|
|
779
|
+
},
|
|
780
|
+
void() {
|
|
781
|
+
return this.map((_b) => {
|
|
782
|
+
});
|
|
783
|
+
},
|
|
784
|
+
apply(f) {
|
|
785
|
+
return f(this);
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
function log(message) {
|
|
790
|
+
return {
|
|
791
|
+
_type: "Suspend",
|
|
792
|
+
operation: {
|
|
793
|
+
_type: "Log",
|
|
794
|
+
input: message
|
|
795
|
+
},
|
|
796
|
+
flatMap(f) {
|
|
797
|
+
return flatMap(this, f);
|
|
798
|
+
},
|
|
799
|
+
and(effect) {
|
|
800
|
+
return flatMap(this, (_) => effect);
|
|
801
|
+
},
|
|
802
|
+
map(f) {
|
|
803
|
+
return flatMap(this, () => pure(f()));
|
|
804
|
+
},
|
|
805
|
+
as(b) {
|
|
806
|
+
return flatMap(this, () => pure(b));
|
|
807
|
+
},
|
|
808
|
+
void() {
|
|
809
|
+
return this.map((_b) => {
|
|
810
|
+
});
|
|
811
|
+
},
|
|
812
|
+
apply(f) {
|
|
813
|
+
return f(this);
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
function makeHttpRequest(request) {
|
|
818
|
+
return {
|
|
819
|
+
_type: "Suspend",
|
|
820
|
+
operation: {
|
|
821
|
+
_type: "MakeHttpRequest",
|
|
822
|
+
input: request
|
|
823
|
+
},
|
|
824
|
+
flatMap(f) {
|
|
825
|
+
return flatMap(this, f);
|
|
826
|
+
},
|
|
827
|
+
and(effect) {
|
|
828
|
+
return flatMap(this, (_) => effect);
|
|
829
|
+
},
|
|
830
|
+
map(f) {
|
|
831
|
+
return flatMap(this, (result) => pure(f(result)));
|
|
832
|
+
},
|
|
833
|
+
as(b) {
|
|
834
|
+
return flatMap(this, () => pure(b));
|
|
835
|
+
},
|
|
836
|
+
void() {
|
|
837
|
+
return this.map((_b) => {
|
|
838
|
+
});
|
|
839
|
+
},
|
|
840
|
+
apply(f) {
|
|
841
|
+
return f(this);
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
function getLocation() {
|
|
846
|
+
return {
|
|
847
|
+
_type: "Suspend",
|
|
848
|
+
operation: { _type: "GetLocation", input: void 0 },
|
|
849
|
+
flatMap(f) {
|
|
850
|
+
return flatMap(this, f);
|
|
851
|
+
},
|
|
852
|
+
and(effect) {
|
|
853
|
+
return flatMap(this, (_) => effect);
|
|
854
|
+
},
|
|
855
|
+
map(f) {
|
|
856
|
+
return flatMap(this, (loc) => pure(f(loc)));
|
|
857
|
+
},
|
|
858
|
+
as(b) {
|
|
859
|
+
return flatMap(this, () => pure(b));
|
|
860
|
+
},
|
|
861
|
+
void() {
|
|
862
|
+
return this.map((_b) => {
|
|
863
|
+
});
|
|
864
|
+
},
|
|
865
|
+
apply(f) {
|
|
866
|
+
return f(this);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
function getNotificationPermission() {
|
|
871
|
+
return {
|
|
872
|
+
_type: "Suspend",
|
|
873
|
+
operation: { _type: "GetNotificationPermission", input: void 0 },
|
|
874
|
+
flatMap(f) {
|
|
875
|
+
return flatMap(this, f);
|
|
876
|
+
},
|
|
877
|
+
and(effect) {
|
|
878
|
+
return flatMap(this, (_) => effect);
|
|
879
|
+
},
|
|
880
|
+
map(f) {
|
|
881
|
+
return flatMap(this, (p) => pure(f(p)));
|
|
882
|
+
},
|
|
883
|
+
as(b) {
|
|
884
|
+
return flatMap(this, () => pure(b));
|
|
885
|
+
},
|
|
886
|
+
void() {
|
|
887
|
+
return this.map((_b) => {
|
|
888
|
+
});
|
|
889
|
+
},
|
|
890
|
+
apply(f) {
|
|
891
|
+
return f(this);
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
function requestNotificationPermission() {
|
|
896
|
+
return {
|
|
897
|
+
_type: "Suspend",
|
|
898
|
+
operation: { _type: "RequestNotificationPermission", input: void 0 },
|
|
899
|
+
flatMap(f) {
|
|
900
|
+
return flatMap(this, f);
|
|
901
|
+
},
|
|
902
|
+
and(effect) {
|
|
903
|
+
return flatMap(this, (_) => effect);
|
|
904
|
+
},
|
|
905
|
+
map(f) {
|
|
906
|
+
return flatMap(this, (p) => pure(f(p)));
|
|
907
|
+
},
|
|
908
|
+
as(b) {
|
|
909
|
+
return flatMap(this, () => pure(b));
|
|
910
|
+
},
|
|
911
|
+
void() {
|
|
912
|
+
return this.map((_b) => {
|
|
913
|
+
});
|
|
914
|
+
},
|
|
915
|
+
apply(f) {
|
|
916
|
+
return f(this);
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
function getState() {
|
|
921
|
+
return {
|
|
922
|
+
_type: "Suspend",
|
|
923
|
+
operation: {
|
|
924
|
+
_type: "GetState",
|
|
925
|
+
input: void 0
|
|
926
|
+
},
|
|
927
|
+
flatMap(f) {
|
|
928
|
+
return flatMap(this, f);
|
|
929
|
+
},
|
|
930
|
+
and(effect) {
|
|
931
|
+
return flatMap(this, (_) => effect);
|
|
932
|
+
},
|
|
933
|
+
map(f) {
|
|
934
|
+
return flatMap(this, (state) => pure(f(state)));
|
|
935
|
+
},
|
|
936
|
+
as(b) {
|
|
937
|
+
return flatMap(this, () => pure(b));
|
|
938
|
+
},
|
|
939
|
+
void() {
|
|
940
|
+
return this.map((_b) => {
|
|
941
|
+
});
|
|
942
|
+
},
|
|
943
|
+
apply(f) {
|
|
944
|
+
return f(this);
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
function product(effectA, effectB) {
|
|
949
|
+
return {
|
|
950
|
+
_type: "Suspend",
|
|
951
|
+
operation: {
|
|
952
|
+
_type: "Product",
|
|
953
|
+
input: [effectA, effectB]
|
|
954
|
+
},
|
|
955
|
+
flatMap(f) {
|
|
956
|
+
return flatMap(this, f);
|
|
957
|
+
},
|
|
958
|
+
and(effect) {
|
|
959
|
+
return flatMap(this, (_) => effect);
|
|
960
|
+
},
|
|
961
|
+
map(f) {
|
|
962
|
+
return flatMap(this, (aAndB) => pure(f(aAndB)));
|
|
963
|
+
},
|
|
964
|
+
as(c) {
|
|
965
|
+
return flatMap(this, (_) => pure(c));
|
|
966
|
+
},
|
|
967
|
+
void() {
|
|
968
|
+
return this.map((_b) => {
|
|
969
|
+
});
|
|
970
|
+
},
|
|
971
|
+
apply(f) {
|
|
972
|
+
return f(this);
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
function scheduleTask(task, initialDelayInMillis, repeatIntervalInMillis, taskId2) {
|
|
977
|
+
return {
|
|
978
|
+
_type: "Suspend",
|
|
979
|
+
operation: {
|
|
980
|
+
_type: "ScheduleTask",
|
|
981
|
+
input: {
|
|
982
|
+
task,
|
|
983
|
+
initialDelayInMillis,
|
|
984
|
+
repeatIntervalInMillis,
|
|
985
|
+
taskId: taskId2
|
|
986
|
+
}
|
|
987
|
+
},
|
|
988
|
+
flatMap(f) {
|
|
989
|
+
return flatMap(this, f);
|
|
990
|
+
},
|
|
991
|
+
and(effect) {
|
|
992
|
+
return flatMap(this, (_) => effect);
|
|
993
|
+
},
|
|
994
|
+
map(f) {
|
|
995
|
+
return flatMap(this, (taskId3) => pure(f(taskId3)));
|
|
996
|
+
},
|
|
997
|
+
as(b) {
|
|
998
|
+
return flatMap(this, () => pure(b));
|
|
999
|
+
},
|
|
1000
|
+
void() {
|
|
1001
|
+
return this.map((_b) => {
|
|
1002
|
+
});
|
|
1003
|
+
},
|
|
1004
|
+
apply(f) {
|
|
1005
|
+
return f(this);
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
function setTimeout(delayInMilliseconds) {
|
|
1010
|
+
return {
|
|
1011
|
+
_type: "Suspend",
|
|
1012
|
+
operation: {
|
|
1013
|
+
_type: "SetTimeout",
|
|
1014
|
+
input: delayInMilliseconds
|
|
1015
|
+
},
|
|
1016
|
+
flatMap(f) {
|
|
1017
|
+
return flatMap(this, f);
|
|
1018
|
+
},
|
|
1019
|
+
and(effect) {
|
|
1020
|
+
return flatMap(this, (_) => effect);
|
|
1021
|
+
},
|
|
1022
|
+
map(f) {
|
|
1023
|
+
return flatMap(this, () => pure(f()));
|
|
1024
|
+
},
|
|
1025
|
+
as(b) {
|
|
1026
|
+
return flatMap(this, () => pure(b));
|
|
1027
|
+
},
|
|
1028
|
+
void() {
|
|
1029
|
+
return this.map((_b) => {
|
|
1030
|
+
});
|
|
1031
|
+
},
|
|
1032
|
+
apply(f) {
|
|
1033
|
+
return f(this);
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
function updateState(f) {
|
|
1038
|
+
return {
|
|
1039
|
+
_type: "Suspend",
|
|
1040
|
+
operation: {
|
|
1041
|
+
_type: "UpdateState",
|
|
1042
|
+
input: f
|
|
1043
|
+
},
|
|
1044
|
+
flatMap(f2) {
|
|
1045
|
+
return flatMap(this, f2);
|
|
1046
|
+
},
|
|
1047
|
+
and(effect) {
|
|
1048
|
+
return flatMap(this, (_) => effect);
|
|
1049
|
+
},
|
|
1050
|
+
map(f2) {
|
|
1051
|
+
return flatMap(this, () => pure(f2()));
|
|
1052
|
+
},
|
|
1053
|
+
as(b) {
|
|
1054
|
+
return flatMap(this, () => pure(b));
|
|
1055
|
+
},
|
|
1056
|
+
void() {
|
|
1057
|
+
return this.map((_b) => {
|
|
1058
|
+
});
|
|
1059
|
+
},
|
|
1060
|
+
apply(f2) {
|
|
1061
|
+
return f2(this);
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
function openDatabase(db, version, setup) {
|
|
1066
|
+
return {
|
|
1067
|
+
_type: "Suspend",
|
|
1068
|
+
operation: { _type: "OpenDatabase", input: { db, version, setup } },
|
|
1069
|
+
flatMap(f) {
|
|
1070
|
+
return flatMap(this, f);
|
|
1071
|
+
},
|
|
1072
|
+
and(effect) {
|
|
1073
|
+
return flatMap(this, (_) => effect);
|
|
1074
|
+
},
|
|
1075
|
+
map(f) {
|
|
1076
|
+
return flatMap(this, (result) => pure(f(result)));
|
|
1077
|
+
},
|
|
1078
|
+
as(b) {
|
|
1079
|
+
return flatMap(this, (_) => pure(b));
|
|
1080
|
+
},
|
|
1081
|
+
void() {
|
|
1082
|
+
return this.map((_b) => {
|
|
1083
|
+
});
|
|
1084
|
+
},
|
|
1085
|
+
apply(f) {
|
|
1086
|
+
return f(this);
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
function runDbTransaction(db, objectStores, mode, effect) {
|
|
1091
|
+
return {
|
|
1092
|
+
_type: "Suspend",
|
|
1093
|
+
operation: {
|
|
1094
|
+
_type: "RunDbTransaction",
|
|
1095
|
+
input: { db, objectStores, mode, effect }
|
|
1096
|
+
},
|
|
1097
|
+
flatMap(f) {
|
|
1098
|
+
return flatMap(this, f);
|
|
1099
|
+
},
|
|
1100
|
+
and(effect2) {
|
|
1101
|
+
return flatMap(this, (_) => effect2);
|
|
1102
|
+
},
|
|
1103
|
+
map(f) {
|
|
1104
|
+
return flatMap(this, (result) => pure(f(result)));
|
|
1105
|
+
},
|
|
1106
|
+
as(b) {
|
|
1107
|
+
return flatMap(this, (_) => pure(b));
|
|
1108
|
+
},
|
|
1109
|
+
void() {
|
|
1110
|
+
return this.map((_b) => {
|
|
1111
|
+
});
|
|
1112
|
+
},
|
|
1113
|
+
apply(f) {
|
|
1114
|
+
return f(this);
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
function storageEffect(storage, key, value, tag) {
|
|
1119
|
+
const input = tag === "SetStorageItem" ? { storage, key, value } : tag === "ClearStorage" ? { storage } : { storage, key };
|
|
1120
|
+
return {
|
|
1121
|
+
_type: "Suspend",
|
|
1122
|
+
operation: { _type: tag, input },
|
|
1123
|
+
flatMap(f) {
|
|
1124
|
+
return flatMap(this, f);
|
|
1125
|
+
},
|
|
1126
|
+
and(e) {
|
|
1127
|
+
return flatMap(this, (_) => e);
|
|
1128
|
+
},
|
|
1129
|
+
map(f) {
|
|
1130
|
+
return flatMap(this, (a) => pure(f(a)));
|
|
1131
|
+
},
|
|
1132
|
+
as(b) {
|
|
1133
|
+
return flatMap(this, (_) => pure(b));
|
|
1134
|
+
},
|
|
1135
|
+
void() {
|
|
1136
|
+
return this.map((_b) => {
|
|
1137
|
+
});
|
|
1138
|
+
},
|
|
1139
|
+
apply(f) {
|
|
1140
|
+
return f(this);
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
function go(delta) {
|
|
1145
|
+
return {
|
|
1146
|
+
_type: "Suspend",
|
|
1147
|
+
operation: { _type: "Go", input: delta },
|
|
1148
|
+
flatMap(f) {
|
|
1149
|
+
return flatMap(this, f);
|
|
1150
|
+
},
|
|
1151
|
+
and(effect) {
|
|
1152
|
+
return flatMap(this, (_) => effect);
|
|
1153
|
+
},
|
|
1154
|
+
map(f) {
|
|
1155
|
+
return flatMap(this, () => pure(f()));
|
|
1156
|
+
},
|
|
1157
|
+
as(b) {
|
|
1158
|
+
return flatMap(this, () => pure(b));
|
|
1159
|
+
},
|
|
1160
|
+
void() {
|
|
1161
|
+
return this.map((_b) => {
|
|
1162
|
+
});
|
|
1163
|
+
},
|
|
1164
|
+
apply(f) {
|
|
1165
|
+
return f(this);
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
function pushState(location) {
|
|
1170
|
+
const loc = typeof location === "string" ? parseInternalLocation(location) : location;
|
|
1171
|
+
return {
|
|
1172
|
+
_type: "Suspend",
|
|
1173
|
+
operation: { _type: "PushState", input: loc },
|
|
1174
|
+
flatMap(f) {
|
|
1175
|
+
return flatMap(this, f);
|
|
1176
|
+
},
|
|
1177
|
+
and(effect) {
|
|
1178
|
+
return flatMap(this, (_) => effect);
|
|
1179
|
+
},
|
|
1180
|
+
map(f) {
|
|
1181
|
+
return flatMap(this, () => pure(f()));
|
|
1182
|
+
},
|
|
1183
|
+
as(b) {
|
|
1184
|
+
return flatMap(this, () => pure(b));
|
|
1185
|
+
},
|
|
1186
|
+
void() {
|
|
1187
|
+
return this.map((_b) => {
|
|
1188
|
+
});
|
|
1189
|
+
},
|
|
1190
|
+
apply(f) {
|
|
1191
|
+
return f(this);
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
function replaceState(location) {
|
|
1196
|
+
const loc = typeof location === "string" ? parseInternalLocation(location) : location;
|
|
1197
|
+
return {
|
|
1198
|
+
_type: "Suspend",
|
|
1199
|
+
operation: { _type: "ReplaceState", input: loc },
|
|
1200
|
+
flatMap(f) {
|
|
1201
|
+
return flatMap(this, f);
|
|
1202
|
+
},
|
|
1203
|
+
and(effect) {
|
|
1204
|
+
return flatMap(this, (_) => effect);
|
|
1205
|
+
},
|
|
1206
|
+
map(f) {
|
|
1207
|
+
return flatMap(this, () => pure(f()));
|
|
1208
|
+
},
|
|
1209
|
+
as(b) {
|
|
1210
|
+
return flatMap(this, () => pure(b));
|
|
1211
|
+
},
|
|
1212
|
+
void() {
|
|
1213
|
+
return this.map((_b) => {
|
|
1214
|
+
});
|
|
1215
|
+
},
|
|
1216
|
+
apply(f) {
|
|
1217
|
+
return f(this);
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
function getLocalStorageItem(key) {
|
|
1222
|
+
return storageEffect("local", key, void 0, "GetStorageItem");
|
|
1223
|
+
}
|
|
1224
|
+
function setLocalStorageItem(key, value) {
|
|
1225
|
+
return storageEffect("local", key, value, "SetStorageItem");
|
|
1226
|
+
}
|
|
1227
|
+
function removeLocalStorageItem(key) {
|
|
1228
|
+
return storageEffect("local", key, void 0, "RemoveStorageItem");
|
|
1229
|
+
}
|
|
1230
|
+
function clearLocalStorage() {
|
|
1231
|
+
return storageEffect("local", "", void 0, "ClearStorage");
|
|
1232
|
+
}
|
|
1233
|
+
function getSessionStorageItem(key) {
|
|
1234
|
+
return storageEffect("session", key, void 0, "GetStorageItem");
|
|
1235
|
+
}
|
|
1236
|
+
function setSessionStorageItem(key, value) {
|
|
1237
|
+
return storageEffect("session", key, value, "SetStorageItem");
|
|
1238
|
+
}
|
|
1239
|
+
function removeSessionStorageItem(key) {
|
|
1240
|
+
return storageEffect("session", key, void 0, "RemoveStorageItem");
|
|
1241
|
+
}
|
|
1242
|
+
function clearSessionStorage() {
|
|
1243
|
+
return storageEffect("session", "", void 0, "ClearStorage");
|
|
1244
|
+
}
|
|
1245
|
+
function mapEvent(effect, f) {
|
|
1246
|
+
switch (effect._type) {
|
|
1247
|
+
case "Return": {
|
|
1248
|
+
return pure(effect.value);
|
|
1249
|
+
}
|
|
1250
|
+
case "FlatMap": {
|
|
1251
|
+
return flatMap(mapEvent(effect.effect, f), (x) => {
|
|
1252
|
+
return mapEvent(effect.next(x), f);
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
case "Suspend": {
|
|
1256
|
+
switch (effect.operation._type) {
|
|
1257
|
+
case "Alert":
|
|
1258
|
+
case "CancelTask":
|
|
1259
|
+
case "ClearAppBadge":
|
|
1260
|
+
case "ClearStorage":
|
|
1261
|
+
case "Confirm":
|
|
1262
|
+
case "CustomEffect":
|
|
1263
|
+
case "Download":
|
|
1264
|
+
case "GenerateUuid":
|
|
1265
|
+
case "GetLocation":
|
|
1266
|
+
case "GetNotificationPermission":
|
|
1267
|
+
case "RequestNotificationPermission":
|
|
1268
|
+
case "GetState":
|
|
1269
|
+
case "GetStorageItem":
|
|
1270
|
+
case "GetTime":
|
|
1271
|
+
case "GetRandom":
|
|
1272
|
+
case "Log":
|
|
1273
|
+
case "PostBroadcastMessage":
|
|
1274
|
+
case "Prompt":
|
|
1275
|
+
case "MakeHttpRequest":
|
|
1276
|
+
case "Go":
|
|
1277
|
+
case "OpenDatabase":
|
|
1278
|
+
case "PushState":
|
|
1279
|
+
case "ReplaceState":
|
|
1280
|
+
case "RemoveStorageItem":
|
|
1281
|
+
case "ReadClipboard":
|
|
1282
|
+
case "RunDbTransaction":
|
|
1283
|
+
case "ScrollElement":
|
|
1284
|
+
case "ScrollWindow":
|
|
1285
|
+
case "SetAppBadge":
|
|
1286
|
+
case "SetDocumentTitle":
|
|
1287
|
+
case "SetStorageItem":
|
|
1288
|
+
case "SetTimeout":
|
|
1289
|
+
case "UpdateState":
|
|
1290
|
+
case "WriteClipboard": {
|
|
1291
|
+
return effect;
|
|
1292
|
+
}
|
|
1293
|
+
case "SubscribeToBroadcastChannel": {
|
|
1294
|
+
return subscribeToBroadcastChannel(
|
|
1295
|
+
effect.operation.input.channel,
|
|
1296
|
+
(msg) => mapEvent(effect.operation.input.handler(msg), f),
|
|
1297
|
+
effect.operation.input.taskId
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
case "ScheduleTask": {
|
|
1301
|
+
return scheduleTask(
|
|
1302
|
+
mapEvent(effect.operation.input.task, f),
|
|
1303
|
+
effect.operation.input.initialDelayInMillis,
|
|
1304
|
+
effect.operation.input.repeatIntervalInMillis,
|
|
1305
|
+
effect.operation.input.taskId
|
|
1306
|
+
);
|
|
1307
|
+
}
|
|
1308
|
+
case "Async": {
|
|
1309
|
+
return async(mapEvent(effect.operation.input.effect, f), effect.operation.input.delayInMillis);
|
|
1310
|
+
}
|
|
1311
|
+
case "Product": {
|
|
1312
|
+
return product(
|
|
1313
|
+
mapEvent(effect.operation.input[0], f),
|
|
1314
|
+
mapEvent(effect.operation.input[1], f)
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1317
|
+
case "FireEvent":
|
|
1318
|
+
return fireEvent(f(effect.operation.input));
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
function mapState(effect, lens) {
|
|
1324
|
+
switch (effect._type) {
|
|
1325
|
+
case "Return": {
|
|
1326
|
+
return pure(effect.value);
|
|
1327
|
+
}
|
|
1328
|
+
case "FlatMap": {
|
|
1329
|
+
return flatMap(mapState(effect.effect, lens), (x) => {
|
|
1330
|
+
return mapState(effect.next(x), lens);
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
case "Suspend": {
|
|
1334
|
+
switch (effect.operation._type) {
|
|
1335
|
+
case "Alert":
|
|
1336
|
+
case "CancelTask":
|
|
1337
|
+
case "ClearAppBadge":
|
|
1338
|
+
case "ClearStorage":
|
|
1339
|
+
case "Confirm":
|
|
1340
|
+
case "CustomEffect":
|
|
1341
|
+
case "Download":
|
|
1342
|
+
case "FireEvent":
|
|
1343
|
+
case "GenerateUuid":
|
|
1344
|
+
case "GetLocation":
|
|
1345
|
+
case "GetNotificationPermission":
|
|
1346
|
+
case "RequestNotificationPermission":
|
|
1347
|
+
case "PostBroadcastMessage":
|
|
1348
|
+
case "Prompt":
|
|
1349
|
+
case "GetStorageItem":
|
|
1350
|
+
case "GetTime":
|
|
1351
|
+
case "GetRandom":
|
|
1352
|
+
case "Log":
|
|
1353
|
+
case "MakeHttpRequest":
|
|
1354
|
+
case "Go":
|
|
1355
|
+
case "OpenDatabase":
|
|
1356
|
+
case "PushState":
|
|
1357
|
+
case "ReplaceState":
|
|
1358
|
+
case "RemoveStorageItem":
|
|
1359
|
+
case "ReadClipboard":
|
|
1360
|
+
case "RunDbTransaction":
|
|
1361
|
+
case "ScrollElement":
|
|
1362
|
+
case "ScrollWindow":
|
|
1363
|
+
case "SetAppBadge":
|
|
1364
|
+
case "SetDocumentTitle":
|
|
1365
|
+
case "SetStorageItem":
|
|
1366
|
+
case "SetTimeout":
|
|
1367
|
+
case "WriteClipboard": {
|
|
1368
|
+
return effect;
|
|
1369
|
+
}
|
|
1370
|
+
case "SubscribeToBroadcastChannel": {
|
|
1371
|
+
return subscribeToBroadcastChannel(
|
|
1372
|
+
effect.operation.input.channel,
|
|
1373
|
+
(msg) => mapState(effect.operation.input.handler(msg), lens),
|
|
1374
|
+
effect.operation.input.taskId
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1377
|
+
case "Async": {
|
|
1378
|
+
return async(mapState(effect.operation.input.effect, lens), effect.operation.input.delayInMillis);
|
|
1379
|
+
}
|
|
1380
|
+
case "ScheduleTask": {
|
|
1381
|
+
return scheduleTask(
|
|
1382
|
+
mapState(effect.operation.input.task, lens),
|
|
1383
|
+
effect.operation.input.initialDelayInMillis,
|
|
1384
|
+
effect.operation.input.repeatIntervalInMillis,
|
|
1385
|
+
effect.operation.input.taskId
|
|
1386
|
+
);
|
|
1387
|
+
}
|
|
1388
|
+
case "Product": {
|
|
1389
|
+
return product(
|
|
1390
|
+
mapState(effect.operation.input[0], lens),
|
|
1391
|
+
mapState(effect.operation.input[1], lens)
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
case "UpdateState": {
|
|
1395
|
+
return updateState((stateB) => {
|
|
1396
|
+
const stateAUpdate = effect.operation.input;
|
|
1397
|
+
const stateA = lens.get(stateB);
|
|
1398
|
+
const updatedStateA = stateAUpdate(stateA);
|
|
1399
|
+
return lens.set(stateB, updatedStateA);
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
case "GetState":
|
|
1403
|
+
return getState().map((b) => {
|
|
1404
|
+
return lens.get(b);
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
function isEffect(value) {
|
|
1411
|
+
if (value === null || value === void 0) {
|
|
1412
|
+
return false;
|
|
1413
|
+
}
|
|
1414
|
+
if (typeof value !== "object") {
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
if (value["_type"] === "Return") {
|
|
1418
|
+
return Object.prototype.hasOwnProperty.call(value, "value");
|
|
1419
|
+
} else if (value["_type"] === "Suspend") {
|
|
1420
|
+
return Object.prototype.hasOwnProperty.call(value, "operation");
|
|
1421
|
+
} else if (value["_type"] === "FlatMap") {
|
|
1422
|
+
return Object.prototype.hasOwnProperty.call(value, "effect");
|
|
1423
|
+
} else {
|
|
1424
|
+
return false;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
function scrollWindow(options) {
|
|
1428
|
+
return {
|
|
1429
|
+
_type: "Suspend",
|
|
1430
|
+
operation: { _type: "ScrollWindow", input: options },
|
|
1431
|
+
flatMap(f) {
|
|
1432
|
+
return flatMap(this, f);
|
|
1433
|
+
},
|
|
1434
|
+
and(effect) {
|
|
1435
|
+
return flatMap(this, (_) => effect);
|
|
1436
|
+
},
|
|
1437
|
+
map(f) {
|
|
1438
|
+
return flatMap(this, () => pure(f()));
|
|
1439
|
+
},
|
|
1440
|
+
as(b) {
|
|
1441
|
+
return flatMap(this, () => pure(b));
|
|
1442
|
+
},
|
|
1443
|
+
void() {
|
|
1444
|
+
return this.map((_b) => {
|
|
1445
|
+
});
|
|
1446
|
+
},
|
|
1447
|
+
apply(f) {
|
|
1448
|
+
return f(this);
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
function scrollElement(selector, options) {
|
|
1453
|
+
return {
|
|
1454
|
+
_type: "Suspend",
|
|
1455
|
+
operation: { _type: "ScrollElement", input: { selector, options } },
|
|
1456
|
+
flatMap(f) {
|
|
1457
|
+
return flatMap(this, f);
|
|
1458
|
+
},
|
|
1459
|
+
and(effect) {
|
|
1460
|
+
return flatMap(this, (_) => effect);
|
|
1461
|
+
},
|
|
1462
|
+
map(f) {
|
|
1463
|
+
return flatMap(this, (result) => pure(f(result)));
|
|
1464
|
+
},
|
|
1465
|
+
as(b) {
|
|
1466
|
+
return flatMap(this, () => pure(b));
|
|
1467
|
+
},
|
|
1468
|
+
void() {
|
|
1469
|
+
return this.map((_b) => {
|
|
1470
|
+
});
|
|
1471
|
+
},
|
|
1472
|
+
apply(f) {
|
|
1473
|
+
return f(this);
|
|
1474
|
+
}
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1477
|
+
function download(filename, content, contentType = "text/plain") {
|
|
1478
|
+
return {
|
|
1479
|
+
_type: "Suspend",
|
|
1480
|
+
operation: { _type: "Download", input: { filename, content, contentType } },
|
|
1481
|
+
flatMap(f) {
|
|
1482
|
+
return flatMap(this, f);
|
|
1483
|
+
},
|
|
1484
|
+
and(effect) {
|
|
1485
|
+
return flatMap(this, (_) => effect);
|
|
1486
|
+
},
|
|
1487
|
+
map(f) {
|
|
1488
|
+
return flatMap(this, () => pure(f()));
|
|
1489
|
+
},
|
|
1490
|
+
as(b) {
|
|
1491
|
+
return flatMap(this, () => pure(b));
|
|
1492
|
+
},
|
|
1493
|
+
void() {
|
|
1494
|
+
return this.map((_b) => {
|
|
1495
|
+
});
|
|
1496
|
+
},
|
|
1497
|
+
apply(f) {
|
|
1498
|
+
return f(this);
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
function postBroadcastMessage(channel, message) {
|
|
1503
|
+
return {
|
|
1504
|
+
_type: "Suspend",
|
|
1505
|
+
operation: { _type: "PostBroadcastMessage", input: { channel, message } },
|
|
1506
|
+
flatMap(f) {
|
|
1507
|
+
return flatMap(this, f);
|
|
1508
|
+
},
|
|
1509
|
+
and(effect) {
|
|
1510
|
+
return flatMap(this, (_) => effect);
|
|
1511
|
+
},
|
|
1512
|
+
map(f) {
|
|
1513
|
+
return flatMap(this, () => pure(f()));
|
|
1514
|
+
},
|
|
1515
|
+
as(b) {
|
|
1516
|
+
return flatMap(this, () => pure(b));
|
|
1517
|
+
},
|
|
1518
|
+
void() {
|
|
1519
|
+
return this.map((_b) => {
|
|
1520
|
+
});
|
|
1521
|
+
},
|
|
1522
|
+
apply(f) {
|
|
1523
|
+
return f(this);
|
|
1524
|
+
}
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
function subscribeToBroadcastChannel(channel, handler, taskId2 = void 0) {
|
|
1528
|
+
return {
|
|
1529
|
+
_type: "Suspend",
|
|
1530
|
+
operation: {
|
|
1531
|
+
_type: "SubscribeToBroadcastChannel",
|
|
1532
|
+
input: { channel, handler, taskId: taskId2 }
|
|
1533
|
+
},
|
|
1534
|
+
flatMap(f) {
|
|
1535
|
+
return flatMap(this, f);
|
|
1536
|
+
},
|
|
1537
|
+
and(effect) {
|
|
1538
|
+
return flatMap(this, (_) => effect);
|
|
1539
|
+
},
|
|
1540
|
+
map(f) {
|
|
1541
|
+
return flatMap(this, (id) => pure(f(id)));
|
|
1542
|
+
},
|
|
1543
|
+
as(b) {
|
|
1544
|
+
return flatMap(this, () => pure(b));
|
|
1545
|
+
},
|
|
1546
|
+
void() {
|
|
1547
|
+
return this.map((_id) => {
|
|
1548
|
+
});
|
|
1549
|
+
},
|
|
1550
|
+
apply(f) {
|
|
1551
|
+
return f(this);
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
function noop() {
|
|
1556
|
+
return pure(void 0);
|
|
1557
|
+
}
|
|
1558
|
+
function makeEffects() {
|
|
1559
|
+
return {
|
|
1560
|
+
alert,
|
|
1561
|
+
confirm,
|
|
1562
|
+
prompt,
|
|
1563
|
+
cancelTask,
|
|
1564
|
+
getLocation,
|
|
1565
|
+
getNotificationPermission,
|
|
1566
|
+
requestNotificationPermission,
|
|
1567
|
+
clearAppBadge,
|
|
1568
|
+
readClipboard,
|
|
1569
|
+
setAppBadge,
|
|
1570
|
+
setDocumentTitle,
|
|
1571
|
+
writeClipboard,
|
|
1572
|
+
fireEvent,
|
|
1573
|
+
getState,
|
|
1574
|
+
getTime,
|
|
1575
|
+
getRandom,
|
|
1576
|
+
log,
|
|
1577
|
+
makeHttpRequest,
|
|
1578
|
+
scheduleTask,
|
|
1579
|
+
setTimeout,
|
|
1580
|
+
updateState,
|
|
1581
|
+
pure(a) {
|
|
1582
|
+
return pure(a);
|
|
1583
|
+
},
|
|
1584
|
+
noop,
|
|
1585
|
+
generateUuid,
|
|
1586
|
+
getJson,
|
|
1587
|
+
go,
|
|
1588
|
+
scrollWindow,
|
|
1589
|
+
scrollElement,
|
|
1590
|
+
download,
|
|
1591
|
+
postBroadcastMessage,
|
|
1592
|
+
subscribeToBroadcastChannel,
|
|
1593
|
+
pushState,
|
|
1594
|
+
replaceState,
|
|
1595
|
+
getLocalStorageItem,
|
|
1596
|
+
setLocalStorageItem,
|
|
1597
|
+
removeLocalStorageItem,
|
|
1598
|
+
clearLocalStorage,
|
|
1599
|
+
getSessionStorageItem,
|
|
1600
|
+
setSessionStorageItem,
|
|
1601
|
+
removeSessionStorageItem,
|
|
1602
|
+
clearSessionStorage,
|
|
1603
|
+
resultT(effect) {
|
|
1604
|
+
return resultT(effect);
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
function traverse(as, f) {
|
|
1609
|
+
const effects = as.map(f);
|
|
1610
|
+
if (effects.length === 0) {
|
|
1611
|
+
return pure([]);
|
|
1612
|
+
}
|
|
1613
|
+
return effects.reduce(
|
|
1614
|
+
(acc, effect) => {
|
|
1615
|
+
return product(acc, effect).map((bsAndB) => {
|
|
1616
|
+
return [...bsAndB[0], bsAndB[1]];
|
|
1617
|
+
});
|
|
1618
|
+
},
|
|
1619
|
+
pure([])
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
var ResultTransformer = class _ResultTransformer {
|
|
1623
|
+
constructor(value) {
|
|
1624
|
+
/** The underlying wrapped effect. */
|
|
1625
|
+
__publicField(this, "value");
|
|
1626
|
+
this.value = value;
|
|
1627
|
+
}
|
|
1628
|
+
/** Transforms the success value. */
|
|
1629
|
+
map(f) {
|
|
1630
|
+
return new _ResultTransformer(
|
|
1631
|
+
this.value.map((res) => {
|
|
1632
|
+
return res.map(f);
|
|
1633
|
+
})
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
/** Replaces the success value with `b`. */
|
|
1637
|
+
as(b) {
|
|
1638
|
+
return new _ResultTransformer(
|
|
1639
|
+
this.value.map((res) => {
|
|
1640
|
+
return res.map((_) => b);
|
|
1641
|
+
})
|
|
1642
|
+
);
|
|
1643
|
+
}
|
|
1644
|
+
/** Discards the success value. */
|
|
1645
|
+
void() {
|
|
1646
|
+
return new _ResultTransformer(
|
|
1647
|
+
this.value.map((res) => {
|
|
1648
|
+
return res.map((_) => {
|
|
1649
|
+
});
|
|
1650
|
+
})
|
|
1651
|
+
);
|
|
1652
|
+
}
|
|
1653
|
+
/** Discards the error value. */
|
|
1654
|
+
errorVoid() {
|
|
1655
|
+
return this.errorMap((_) => {
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
/** Chains on success, short-circuits on failure. */
|
|
1659
|
+
flatMap(f) {
|
|
1660
|
+
return new _ResultTransformer(
|
|
1661
|
+
this.value.flatMap((res) => {
|
|
1662
|
+
switch (res._tag) {
|
|
1663
|
+
case "failure":
|
|
1664
|
+
return pure(failure(res.error));
|
|
1665
|
+
case "success":
|
|
1666
|
+
return f(res.value);
|
|
1667
|
+
}
|
|
1668
|
+
})
|
|
1669
|
+
);
|
|
1670
|
+
}
|
|
1671
|
+
/** Like `flatMap` but `f` returns an unwrapped Effect rather than an Effect of Result. */
|
|
1672
|
+
semiFlatMap(f) {
|
|
1673
|
+
return new _ResultTransformer(
|
|
1674
|
+
this.value.flatMap((res) => {
|
|
1675
|
+
switch (res._tag) {
|
|
1676
|
+
case "failure":
|
|
1677
|
+
return pure(failure(res.error));
|
|
1678
|
+
case "success":
|
|
1679
|
+
return f(res.value).map((b) => success(b));
|
|
1680
|
+
}
|
|
1681
|
+
})
|
|
1682
|
+
);
|
|
1683
|
+
}
|
|
1684
|
+
/** Sequences on success, short-circuits on failure. */
|
|
1685
|
+
and(effect) {
|
|
1686
|
+
return new _ResultTransformer(
|
|
1687
|
+
this.value.flatMap((res) => {
|
|
1688
|
+
switch (res._tag) {
|
|
1689
|
+
case "failure":
|
|
1690
|
+
return pure(failure(res.error));
|
|
1691
|
+
case "success":
|
|
1692
|
+
return effect;
|
|
1693
|
+
}
|
|
1694
|
+
})
|
|
1695
|
+
);
|
|
1696
|
+
}
|
|
1697
|
+
/** Unwraps the Result, returning either the success value or the error. */
|
|
1698
|
+
merge() {
|
|
1699
|
+
return this.value.map((res) => res.merge());
|
|
1700
|
+
}
|
|
1701
|
+
/** Logs the error to the console without changing the Result. */
|
|
1702
|
+
logError() {
|
|
1703
|
+
return this.errorFlatMap((e) => log(e).map((_) => e));
|
|
1704
|
+
}
|
|
1705
|
+
/** Logs the error and converts it to void. */
|
|
1706
|
+
logAndDropError() {
|
|
1707
|
+
return this.logError().errorVoid();
|
|
1708
|
+
}
|
|
1709
|
+
/** Transforms the error value. */
|
|
1710
|
+
errorMap(f) {
|
|
1711
|
+
return new _ResultTransformer(this.value.map((res) => res.errorMap(f)));
|
|
1712
|
+
}
|
|
1713
|
+
/** Chains on failure, short-circuits on success. */
|
|
1714
|
+
errorFlatMap(f) {
|
|
1715
|
+
return new _ResultTransformer(
|
|
1716
|
+
this.value.flatMap((res) => {
|
|
1717
|
+
switch (res._tag) {
|
|
1718
|
+
case "failure":
|
|
1719
|
+
return f(res.error).map((e) => failure(e));
|
|
1720
|
+
case "success":
|
|
1721
|
+
return pure(success(res.value));
|
|
1722
|
+
}
|
|
1723
|
+
})
|
|
1724
|
+
);
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
function resultT(effect) {
|
|
1728
|
+
return new ResultTransformer(effect);
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
export {
|
|
1732
|
+
success,
|
|
1733
|
+
failure,
|
|
1734
|
+
ResponseBody,
|
|
1735
|
+
exhaustivenessCheck,
|
|
1736
|
+
eq,
|
|
1737
|
+
stringToInt,
|
|
1738
|
+
filterNot,
|
|
1739
|
+
emptyPath,
|
|
1740
|
+
parsePath,
|
|
1741
|
+
parseFragment,
|
|
1742
|
+
parseAllQueryParams,
|
|
1743
|
+
formatLocation,
|
|
1744
|
+
parseInternalLocation,
|
|
1745
|
+
internalLocationFromLocation,
|
|
1746
|
+
emptyLocation,
|
|
1747
|
+
taskId,
|
|
1748
|
+
customEffect,
|
|
1749
|
+
pure,
|
|
1750
|
+
alert,
|
|
1751
|
+
confirm,
|
|
1752
|
+
prompt,
|
|
1753
|
+
clearAppBadge,
|
|
1754
|
+
readClipboard,
|
|
1755
|
+
writeClipboard,
|
|
1756
|
+
setDocumentTitle,
|
|
1757
|
+
setAppBadge,
|
|
1758
|
+
async,
|
|
1759
|
+
cancelTask,
|
|
1760
|
+
fireEvent,
|
|
1761
|
+
generateUuid,
|
|
1762
|
+
getTime,
|
|
1763
|
+
getRandom,
|
|
1764
|
+
log,
|
|
1765
|
+
makeHttpRequest,
|
|
1766
|
+
getLocation,
|
|
1767
|
+
getNotificationPermission,
|
|
1768
|
+
requestNotificationPermission,
|
|
1769
|
+
getState,
|
|
1770
|
+
product,
|
|
1771
|
+
scheduleTask,
|
|
1772
|
+
setTimeout,
|
|
1773
|
+
updateState,
|
|
1774
|
+
openDatabase,
|
|
1775
|
+
runDbTransaction,
|
|
1776
|
+
go,
|
|
1777
|
+
pushState,
|
|
1778
|
+
replaceState,
|
|
1779
|
+
getLocalStorageItem,
|
|
1780
|
+
setLocalStorageItem,
|
|
1781
|
+
removeLocalStorageItem,
|
|
1782
|
+
clearLocalStorage,
|
|
1783
|
+
getSessionStorageItem,
|
|
1784
|
+
setSessionStorageItem,
|
|
1785
|
+
removeSessionStorageItem,
|
|
1786
|
+
clearSessionStorage,
|
|
1787
|
+
mapEvent,
|
|
1788
|
+
mapState,
|
|
1789
|
+
isEffect,
|
|
1790
|
+
scrollWindow,
|
|
1791
|
+
scrollElement,
|
|
1792
|
+
download,
|
|
1793
|
+
postBroadcastMessage,
|
|
1794
|
+
subscribeToBroadcastChannel,
|
|
1795
|
+
noop,
|
|
1796
|
+
makeEffects,
|
|
1797
|
+
traverse,
|
|
1798
|
+
ResultTransformer,
|
|
1799
|
+
resultT
|
|
1800
|
+
};
|