mol_wire_lib 1.0.1739 → 1.0.1741
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/node.d.ts +244 -1
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +243 -10
- package/node.js.map +1 -1
- package/node.mjs +243 -10
- package/node.test.js +371 -14
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +198 -0
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +191 -9
- package/web.js.map +1 -1
- package/web.mjs +191 -9
- package/web.test.js +124 -1
- package/web.test.js.map +1 -1
package/web.js
CHANGED
|
@@ -32,6 +32,7 @@ $.$$ = $
|
|
|
32
32
|
"use strict";
|
|
33
33
|
var $;
|
|
34
34
|
(function ($) {
|
|
35
|
+
/** Generates unique identifier. */
|
|
35
36
|
function $mol_guid(length = 8, exists = () => false) {
|
|
36
37
|
for (;;) {
|
|
37
38
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -57,11 +58,16 @@ var $;
|
|
|
57
58
|
"use strict";
|
|
58
59
|
var $;
|
|
59
60
|
(function ($) {
|
|
61
|
+
/** Special status statuses. */
|
|
60
62
|
let $mol_wire_cursor;
|
|
61
63
|
(function ($mol_wire_cursor) {
|
|
64
|
+
/** Update required. */
|
|
62
65
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
66
|
+
/** Some of (transitive) pub update required. */
|
|
63
67
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
68
|
+
/** Actual state but may be dropped. */
|
|
64
69
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
70
|
+
/** State will never be changed. */
|
|
65
71
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
66
72
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
67
73
|
})($ || ($ = {}));
|
|
@@ -70,6 +76,9 @@ var $;
|
|
|
70
76
|
"use strict";
|
|
71
77
|
var $;
|
|
72
78
|
(function ($) {
|
|
79
|
+
/**
|
|
80
|
+
* Collects subscribers in compact array. 28B
|
|
81
|
+
*/
|
|
73
82
|
class $mol_wire_pub extends Object {
|
|
74
83
|
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
75
84
|
super();
|
|
@@ -77,10 +86,17 @@ var $;
|
|
|
77
86
|
}
|
|
78
87
|
[Symbol.toStringTag];
|
|
79
88
|
data = [];
|
|
89
|
+
// Derived objects should be Arrays.
|
|
80
90
|
static get [Symbol.species]() {
|
|
81
91
|
return Array;
|
|
82
92
|
}
|
|
83
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Index of first subscriber.
|
|
95
|
+
*/
|
|
96
|
+
sub_from = 0; // 4B
|
|
97
|
+
/**
|
|
98
|
+
* All current subscribers.
|
|
99
|
+
*/
|
|
84
100
|
get sub_list() {
|
|
85
101
|
const res = [];
|
|
86
102
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -88,14 +104,23 @@ var $;
|
|
|
88
104
|
}
|
|
89
105
|
return res;
|
|
90
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Has any subscribers or not.
|
|
109
|
+
*/
|
|
91
110
|
get sub_empty() {
|
|
92
111
|
return this.sub_from === this.data.length;
|
|
93
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
115
|
+
*/
|
|
94
116
|
sub_on(sub, pub_pos) {
|
|
95
117
|
const pos = this.data.length;
|
|
96
118
|
this.data.push(sub, pub_pos);
|
|
97
119
|
return pos;
|
|
98
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
123
|
+
*/
|
|
99
124
|
sub_off(sub_pos) {
|
|
100
125
|
if (!(sub_pos < this.data.length)) {
|
|
101
126
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -108,21 +133,39 @@ var $;
|
|
|
108
133
|
if (end === this.sub_from)
|
|
109
134
|
this.reap();
|
|
110
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Called when last sub was unsubscribed.
|
|
138
|
+
**/
|
|
111
139
|
reap() { }
|
|
140
|
+
/**
|
|
141
|
+
* Autowire this publisher with current subscriber.
|
|
142
|
+
**/
|
|
112
143
|
promote() {
|
|
113
144
|
$mol_wire_auto()?.track_next(this);
|
|
114
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Enforce actualization. Should not throw errors.
|
|
148
|
+
*/
|
|
115
149
|
fresh() { }
|
|
150
|
+
/**
|
|
151
|
+
* Allow to put data to caches in the subtree.
|
|
152
|
+
*/
|
|
116
153
|
complete() { }
|
|
117
154
|
get incompleted() {
|
|
118
155
|
return false;
|
|
119
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Notify subscribers about self changes.
|
|
159
|
+
*/
|
|
120
160
|
emit(quant = $mol_wire_cursor.stale) {
|
|
121
161
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
122
162
|
;
|
|
123
163
|
this.data[i].absorb(quant, this.data[i + 1]);
|
|
124
164
|
}
|
|
125
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
168
|
+
*/
|
|
126
169
|
peer_move(from_pos, to_pos) {
|
|
127
170
|
const peer = this.data[from_pos];
|
|
128
171
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -130,6 +173,9 @@ var $;
|
|
|
130
173
|
this.data[to_pos + 1] = self_pos;
|
|
131
174
|
peer.peer_repos(self_pos, to_pos);
|
|
132
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Updates self position in the peer.
|
|
178
|
+
*/
|
|
133
179
|
peer_repos(peer_pos, self_pos) {
|
|
134
180
|
this.data[peer_pos + 1] = self_pos;
|
|
135
181
|
}
|
|
@@ -145,10 +191,16 @@ var $;
|
|
|
145
191
|
var $;
|
|
146
192
|
(function ($) {
|
|
147
193
|
$.$mol_wire_auto_sub = null;
|
|
194
|
+
/**
|
|
195
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
196
|
+
*/
|
|
148
197
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
149
198
|
return $.$mol_wire_auto_sub = next;
|
|
150
199
|
}
|
|
151
200
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
201
|
+
/**
|
|
202
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
203
|
+
*/
|
|
152
204
|
$.$mol_wire_affected = [];
|
|
153
205
|
})($ || ($ = {}));
|
|
154
206
|
|
|
@@ -157,7 +209,7 @@ var $;
|
|
|
157
209
|
var $;
|
|
158
210
|
(function ($) {
|
|
159
211
|
function $mol_fail_hidden(error) {
|
|
160
|
-
throw error;
|
|
212
|
+
throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
|
|
161
213
|
}
|
|
162
214
|
$.$mol_fail_hidden = $mol_fail_hidden;
|
|
163
215
|
})($ || ($ = {}));
|
|
@@ -166,6 +218,7 @@ var $;
|
|
|
166
218
|
"use strict";
|
|
167
219
|
var $;
|
|
168
220
|
(function ($) {
|
|
221
|
+
// https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
|
|
169
222
|
$['devtoolsFormatters'] ||= [];
|
|
170
223
|
function $mol_dev_format_register(config) {
|
|
171
224
|
$['devtoolsFormatters'].push(config);
|
|
@@ -217,6 +270,7 @@ var $;
|
|
|
217
270
|
return false;
|
|
218
271
|
if (!val)
|
|
219
272
|
return false;
|
|
273
|
+
// if( Error.isError( val ) ) true
|
|
220
274
|
if (val[$.$mol_dev_format_body])
|
|
221
275
|
return true;
|
|
222
276
|
return false;
|
|
@@ -234,12 +288,16 @@ var $;
|
|
|
234
288
|
return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
|
|
235
289
|
}
|
|
236
290
|
}
|
|
291
|
+
// if( Error.isError( val ) ) {
|
|
292
|
+
// return $mol_dev_format_native( val )
|
|
293
|
+
// }
|
|
237
294
|
return null;
|
|
238
295
|
},
|
|
239
296
|
});
|
|
240
297
|
function $mol_dev_format_native(obj) {
|
|
241
298
|
if (typeof obj === 'undefined')
|
|
242
299
|
return $.$mol_dev_format_shade('undefined');
|
|
300
|
+
// if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
|
|
243
301
|
return [
|
|
244
302
|
'object',
|
|
245
303
|
{
|
|
@@ -297,6 +355,9 @@ var $;
|
|
|
297
355
|
'margin-left': '13px'
|
|
298
356
|
});
|
|
299
357
|
class Stack extends Array {
|
|
358
|
+
// [ Symbol.toPrimitive ]() {
|
|
359
|
+
// return this.toString()
|
|
360
|
+
// }
|
|
300
361
|
toString() {
|
|
301
362
|
return this.join('\n');
|
|
302
363
|
}
|
|
@@ -319,6 +380,7 @@ var $;
|
|
|
319
380
|
this.method = call.getMethodName() ?? '';
|
|
320
381
|
if (this.method === this.function)
|
|
321
382
|
this.method = '';
|
|
383
|
+
// const func = c.getFunction()
|
|
322
384
|
this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
|
|
323
385
|
this.eval = call.getEvalOrigin() ?? '';
|
|
324
386
|
this.source = call.getScriptNameOrSourceURL() ?? '';
|
|
@@ -365,9 +427,16 @@ var $;
|
|
|
365
427
|
"use strict";
|
|
366
428
|
var $;
|
|
367
429
|
(function ($) {
|
|
430
|
+
/**
|
|
431
|
+
* Publisher that can auto collect other publishers. 32B
|
|
432
|
+
*
|
|
433
|
+
* P1 P2 P3 P4 S1 S2 S3
|
|
434
|
+
* ^ ^
|
|
435
|
+
* pubs_from subs_from
|
|
436
|
+
*/
|
|
368
437
|
class $mol_wire_pub_sub extends $mol_wire_pub {
|
|
369
|
-
pub_from = 0;
|
|
370
|
-
cursor = $mol_wire_cursor.stale;
|
|
438
|
+
pub_from = 0; // 4B
|
|
439
|
+
cursor = $mol_wire_cursor.stale; // 4B
|
|
371
440
|
get temp() {
|
|
372
441
|
return false;
|
|
373
442
|
}
|
|
@@ -485,10 +554,27 @@ var $;
|
|
|
485
554
|
return;
|
|
486
555
|
this.cursor = quant;
|
|
487
556
|
this.emit($mol_wire_cursor.doubt);
|
|
557
|
+
// if( pos >= 0 && pos < this.sub_from - 2 ) {
|
|
558
|
+
// const pub = this.data[ pos ] as $mol_wire_pub
|
|
559
|
+
// if( pub instanceof $mol_wire_task ) return
|
|
560
|
+
// for(
|
|
561
|
+
// let cursor = this.pub_from;
|
|
562
|
+
// cursor < this.sub_from;
|
|
563
|
+
// cursor += 2
|
|
564
|
+
// ) {
|
|
565
|
+
// const pub = this.data[ cursor ] as $mol_wire_pub
|
|
566
|
+
// if( pub instanceof $mol_wire_task ) {
|
|
567
|
+
// pub.destructor()
|
|
568
|
+
// }
|
|
569
|
+
// }
|
|
570
|
+
// }
|
|
488
571
|
}
|
|
489
572
|
[$mol_dev_format_head]() {
|
|
490
573
|
return $mol_dev_format_native(this);
|
|
491
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* Is subscribed to any publisher or not.
|
|
577
|
+
*/
|
|
492
578
|
get pub_empty() {
|
|
493
579
|
return this.sub_from === this.pub_from;
|
|
494
580
|
}
|
|
@@ -512,6 +598,11 @@ var $;
|
|
|
512
598
|
var $;
|
|
513
599
|
(function ($) {
|
|
514
600
|
const instances = new WeakSet();
|
|
601
|
+
/**
|
|
602
|
+
* Proxy that delegates all to lazy returned target.
|
|
603
|
+
*
|
|
604
|
+
* $mol_delegate( Array.prototype , ()=> fetch_array() )
|
|
605
|
+
*/
|
|
515
606
|
function $mol_delegate(proto, target) {
|
|
516
607
|
const proxy = new Proxy(proto, {
|
|
517
608
|
get: (_, field) => {
|
|
@@ -687,6 +778,9 @@ var $;
|
|
|
687
778
|
[Symbol.dispose]() {
|
|
688
779
|
this.destructor();
|
|
689
780
|
}
|
|
781
|
+
//[ Symbol.toPrimitive ]( hint: string ) {
|
|
782
|
+
// return hint === 'number' ? this.valueOf() : this.toString()
|
|
783
|
+
//}
|
|
690
784
|
toString() {
|
|
691
785
|
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
692
786
|
}
|
|
@@ -742,6 +836,13 @@ var $;
|
|
|
742
836
|
var $;
|
|
743
837
|
(function ($) {
|
|
744
838
|
const wrappers = new WeakMap();
|
|
839
|
+
/**
|
|
840
|
+
* Suspendable task with support both sync/async api.
|
|
841
|
+
*
|
|
842
|
+
* A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
|
|
843
|
+
* ^ ^ ^
|
|
844
|
+
* args_from pubs_from subs_from
|
|
845
|
+
**/
|
|
745
846
|
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
|
746
847
|
task;
|
|
747
848
|
host;
|
|
@@ -762,6 +863,7 @@ var $;
|
|
|
762
863
|
});
|
|
763
864
|
}
|
|
764
865
|
static sync() {
|
|
866
|
+
// Sync whole fiber graph
|
|
765
867
|
while (this.planning.size) {
|
|
766
868
|
for (const fiber of this.planning) {
|
|
767
869
|
this.planning.delete(fiber);
|
|
@@ -772,6 +874,7 @@ var $;
|
|
|
772
874
|
fiber.fresh();
|
|
773
875
|
}
|
|
774
876
|
}
|
|
877
|
+
// Collect garbage
|
|
775
878
|
while (this.reaping.size) {
|
|
776
879
|
const fibers = this.reaping;
|
|
777
880
|
this.reaping = new Set;
|
|
@@ -923,6 +1026,10 @@ var $;
|
|
|
923
1026
|
this.cursor = $mol_wire_cursor.stale;
|
|
924
1027
|
this.fresh();
|
|
925
1028
|
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
|
|
1031
|
+
* Should be called inside SuspenseAPI consumer (ie fiber).
|
|
1032
|
+
*/
|
|
926
1033
|
sync() {
|
|
927
1034
|
if (!$mol_wire_fiber.warm) {
|
|
928
1035
|
return this.result();
|
|
@@ -937,6 +1044,10 @@ var $;
|
|
|
937
1044
|
}
|
|
938
1045
|
return this.cache;
|
|
939
1046
|
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Asynchronous execution.
|
|
1049
|
+
* It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
|
|
1050
|
+
*/
|
|
940
1051
|
async async_raw() {
|
|
941
1052
|
while (true) {
|
|
942
1053
|
this.fresh();
|
|
@@ -949,6 +1060,7 @@ var $;
|
|
|
949
1060
|
if (!$mol_promise_like(this.cache))
|
|
950
1061
|
return this.cache;
|
|
951
1062
|
if (this.cursor === $mol_wire_cursor.final) {
|
|
1063
|
+
// never ends on destructed fiber
|
|
952
1064
|
await new Promise(() => { });
|
|
953
1065
|
}
|
|
954
1066
|
}
|
|
@@ -996,6 +1108,10 @@ var $;
|
|
|
996
1108
|
var $;
|
|
997
1109
|
(function ($) {
|
|
998
1110
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
1111
|
+
/**
|
|
1112
|
+
* Deeply compares two values. Returns true if equal.
|
|
1113
|
+
* Define `Symbol.toPrimitive` to customize.
|
|
1114
|
+
*/
|
|
999
1115
|
function $mol_compare_deep(left, right) {
|
|
1000
1116
|
if (Object.is(left, right))
|
|
1001
1117
|
return true;
|
|
@@ -1135,6 +1251,7 @@ var $;
|
|
|
1135
1251
|
"use strict";
|
|
1136
1252
|
var $;
|
|
1137
1253
|
(function ($) {
|
|
1254
|
+
/** Log begin of collapsed group only when some logged inside, returns func to close group */
|
|
1138
1255
|
function $mol_log3_area_lazy(event) {
|
|
1139
1256
|
const self = this.$;
|
|
1140
1257
|
const stack = self.$mol_log3_stack;
|
|
@@ -1191,6 +1308,7 @@ var $;
|
|
|
1191
1308
|
"use strict";
|
|
1192
1309
|
var $;
|
|
1193
1310
|
(function ($) {
|
|
1311
|
+
/** One-shot fiber */
|
|
1194
1312
|
class $mol_wire_task extends $mol_wire_fiber {
|
|
1195
1313
|
static getter(task) {
|
|
1196
1314
|
return function $mol_wire_task_get(host, args) {
|
|
@@ -1216,6 +1334,7 @@ var $;
|
|
|
1216
1334
|
}
|
|
1217
1335
|
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
|
1218
1336
|
const next = new $mol_wire_task(key, task, host, args);
|
|
1337
|
+
// Disabled because non-idempotency is required for try-catch
|
|
1219
1338
|
if (existen?.temp) {
|
|
1220
1339
|
$$.$mol_log3_warn({
|
|
1221
1340
|
place: '$mol_wire_task',
|
|
@@ -1248,7 +1367,7 @@ var $;
|
|
|
1248
1367
|
try {
|
|
1249
1368
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
1250
1369
|
}
|
|
1251
|
-
catch {
|
|
1370
|
+
catch { // Promises throw in strict mode
|
|
1252
1371
|
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
1253
1372
|
}
|
|
1254
1373
|
}
|
|
@@ -1274,6 +1393,7 @@ var $;
|
|
|
1274
1393
|
var $;
|
|
1275
1394
|
(function ($) {
|
|
1276
1395
|
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
1396
|
+
/** Returns string key for any value. */
|
|
1277
1397
|
function $mol_key(value) {
|
|
1278
1398
|
primitives: {
|
|
1279
1399
|
if (typeof value === 'bigint')
|
|
@@ -1281,9 +1401,9 @@ var $;
|
|
|
1281
1401
|
if (typeof value === 'symbol')
|
|
1282
1402
|
return `Symbol(${value.description})`;
|
|
1283
1403
|
if (!value)
|
|
1284
|
-
return JSON.stringify(value);
|
|
1404
|
+
return JSON.stringify(value); // 0, null, ""
|
|
1285
1405
|
if (typeof value !== 'object' && typeof value !== 'function')
|
|
1286
|
-
return JSON.stringify(value);
|
|
1406
|
+
return JSON.stringify(value); // boolean, number, string
|
|
1287
1407
|
}
|
|
1288
1408
|
caching: {
|
|
1289
1409
|
let key = $mol_key_store.get(value);
|
|
@@ -1366,6 +1486,9 @@ var $;
|
|
|
1366
1486
|
"use strict";
|
|
1367
1487
|
var $;
|
|
1368
1488
|
(function ($) {
|
|
1489
|
+
/**
|
|
1490
|
+
* Decorates method to fiber to ensure it is executed only once inside other fiber.
|
|
1491
|
+
*/
|
|
1369
1492
|
function $mol_wire_method(host, field, descr) {
|
|
1370
1493
|
if (!descr)
|
|
1371
1494
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -1435,6 +1558,7 @@ var $;
|
|
|
1435
1558
|
let error;
|
|
1436
1559
|
let result;
|
|
1437
1560
|
let handler;
|
|
1561
|
+
/// Debugger will stop at exceptions but exception will be returned normally
|
|
1438
1562
|
function $mol_try_web(handler2) {
|
|
1439
1563
|
handler = handler2;
|
|
1440
1564
|
error = undefined;
|
|
@@ -1475,6 +1599,7 @@ var $;
|
|
|
1475
1599
|
"use strict";
|
|
1476
1600
|
var $;
|
|
1477
1601
|
(function ($) {
|
|
1602
|
+
/** Long-living fiber. */
|
|
1478
1603
|
class $mol_wire_atom extends $mol_wire_fiber {
|
|
1479
1604
|
static solo(host, task) {
|
|
1480
1605
|
const field = task.name + '()';
|
|
@@ -1525,7 +1650,11 @@ var $;
|
|
|
1525
1650
|
}
|
|
1526
1651
|
$mol_wire_atom.watching.add(this);
|
|
1527
1652
|
}
|
|
1653
|
+
/**
|
|
1654
|
+
* Update atom value through another temp fiber.
|
|
1655
|
+
*/
|
|
1528
1656
|
resync(args) {
|
|
1657
|
+
// enforce pulling tasks abort
|
|
1529
1658
|
for (let cursor = this.pub_from; cursor < this.sub_from; cursor += 2) {
|
|
1530
1659
|
const pub = this.data[cursor];
|
|
1531
1660
|
if (pub && pub instanceof $mol_wire_task) {
|
|
@@ -1586,7 +1715,7 @@ var $;
|
|
|
1586
1715
|
try {
|
|
1587
1716
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
1588
1717
|
}
|
|
1589
|
-
catch {
|
|
1718
|
+
catch { // Promises throw in strict mode
|
|
1590
1719
|
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
1591
1720
|
}
|
|
1592
1721
|
}
|
|
@@ -1614,6 +1743,7 @@ var $;
|
|
|
1614
1743
|
"use strict";
|
|
1615
1744
|
var $;
|
|
1616
1745
|
(function ($) {
|
|
1746
|
+
/** Run code without state changes */
|
|
1617
1747
|
function $mol_wire_probe(task, def) {
|
|
1618
1748
|
const warm = $mol_wire_fiber.warm;
|
|
1619
1749
|
try {
|
|
@@ -1634,6 +1764,9 @@ var $;
|
|
|
1634
1764
|
"use strict";
|
|
1635
1765
|
var $;
|
|
1636
1766
|
(function ($) {
|
|
1767
|
+
/**
|
|
1768
|
+
* Disable reaping of current subscriber
|
|
1769
|
+
*/
|
|
1637
1770
|
function $mol_wire_solid() {
|
|
1638
1771
|
let current = $mol_wire_auto();
|
|
1639
1772
|
if (current.temp)
|
|
@@ -1652,6 +1785,10 @@ var $;
|
|
|
1652
1785
|
"use strict";
|
|
1653
1786
|
var $;
|
|
1654
1787
|
(function ($) {
|
|
1788
|
+
/**
|
|
1789
|
+
* Real-time refresh current atom.
|
|
1790
|
+
* Don't use if possible. May reduce performance.
|
|
1791
|
+
*/
|
|
1655
1792
|
function $mol_wire_watch() {
|
|
1656
1793
|
const atom = $mol_wire_auto();
|
|
1657
1794
|
if (atom instanceof $mol_wire_atom) {
|
|
@@ -1696,6 +1833,10 @@ var $;
|
|
|
1696
1833
|
props[field] = get_val;
|
|
1697
1834
|
return get_val;
|
|
1698
1835
|
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
|
|
1838
|
+
* @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
|
|
1839
|
+
*/
|
|
1699
1840
|
function $mol_wire_sync(obj) {
|
|
1700
1841
|
return new Proxy(obj, {
|
|
1701
1842
|
get(obj, field) {
|
|
@@ -1730,6 +1871,7 @@ var $;
|
|
|
1730
1871
|
"use strict";
|
|
1731
1872
|
var $;
|
|
1732
1873
|
(function ($) {
|
|
1874
|
+
/** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
|
|
1733
1875
|
function $mol_wire_async(obj) {
|
|
1734
1876
|
let fiber;
|
|
1735
1877
|
const temp = $mol_wire_task.getter(obj);
|
|
@@ -1760,6 +1902,7 @@ var $;
|
|
|
1760
1902
|
"use strict";
|
|
1761
1903
|
var $;
|
|
1762
1904
|
(function ($) {
|
|
1905
|
+
/** Starts subtasks concurrently instead of serial. */
|
|
1763
1906
|
function $mol_wire_race(...tasks) {
|
|
1764
1907
|
const results = tasks.map(task => {
|
|
1765
1908
|
try {
|
|
@@ -1784,6 +1927,7 @@ var $;
|
|
|
1784
1927
|
"use strict";
|
|
1785
1928
|
var $;
|
|
1786
1929
|
(function ($) {
|
|
1930
|
+
/** Decorates solo object channel to [mol_wire_atom](../atom/atom.ts). */
|
|
1787
1931
|
function $mol_wire_solo(host, field, descr) {
|
|
1788
1932
|
if (!descr)
|
|
1789
1933
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -1822,6 +1966,7 @@ var $;
|
|
|
1822
1966
|
"use strict";
|
|
1823
1967
|
var $;
|
|
1824
1968
|
(function ($) {
|
|
1969
|
+
/** Reactive memoizing multiplexed property decorator. */
|
|
1825
1970
|
function $mol_wire_plex(host, field, descr) {
|
|
1826
1971
|
if (!descr)
|
|
1827
1972
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -1860,6 +2005,11 @@ var $;
|
|
|
1860
2005
|
"use strict";
|
|
1861
2006
|
var $;
|
|
1862
2007
|
(function ($) {
|
|
2008
|
+
/**
|
|
2009
|
+
* Returns closure that returns constant value.
|
|
2010
|
+
* @example
|
|
2011
|
+
* const rnd = $mol_const( Math.random() )
|
|
2012
|
+
*/
|
|
1863
2013
|
function $mol_const(value) {
|
|
1864
2014
|
const getter = (() => value);
|
|
1865
2015
|
getter['()'] = value;
|
|
@@ -1874,6 +2024,7 @@ var $;
|
|
|
1874
2024
|
"use strict";
|
|
1875
2025
|
var $;
|
|
1876
2026
|
(function ($) {
|
|
2027
|
+
/** Incompatible with instance fields with initializators */
|
|
1877
2028
|
function $mol_wire_field(host, field, descr) {
|
|
1878
2029
|
if (!descr)
|
|
1879
2030
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -1927,7 +2078,25 @@ var $;
|
|
|
1927
2078
|
"use strict";
|
|
1928
2079
|
var $;
|
|
1929
2080
|
(function ($) {
|
|
2081
|
+
/**
|
|
2082
|
+
* Reactive memoizing solo property decorator from [mol_wire](../wire/README.md)
|
|
2083
|
+
* @example
|
|
2084
|
+
* '@' $mol_mem
|
|
2085
|
+
* name(next?: string) {
|
|
2086
|
+
* return next ?? 'default'
|
|
2087
|
+
* }
|
|
2088
|
+
* @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
|
|
2089
|
+
*/
|
|
1930
2090
|
$.$mol_mem = $mol_wire_solo;
|
|
2091
|
+
/**
|
|
2092
|
+
* Reactive memoizing multiplexed property decorator [mol_wire](../wire/README.md)
|
|
2093
|
+
* @example
|
|
2094
|
+
* '@' $mol_mem_key
|
|
2095
|
+
* name(id: number, next?: string) {
|
|
2096
|
+
* return next ?? 'default'
|
|
2097
|
+
* }
|
|
2098
|
+
* @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
|
|
2099
|
+
*/
|
|
1931
2100
|
$.$mol_mem_key = $mol_wire_plex;
|
|
1932
2101
|
})($ || ($ = {}));
|
|
1933
2102
|
|
|
@@ -1956,6 +2125,7 @@ var $;
|
|
|
1956
2125
|
"use strict";
|
|
1957
2126
|
var $;
|
|
1958
2127
|
(function ($) {
|
|
2128
|
+
/** State of time moment */
|
|
1959
2129
|
class $mol_state_time extends $mol_object {
|
|
1960
2130
|
static task(precision, reset) {
|
|
1961
2131
|
if (precision) {
|
|
@@ -1983,6 +2153,7 @@ var $;
|
|
|
1983
2153
|
"use strict";
|
|
1984
2154
|
var $;
|
|
1985
2155
|
(function ($) {
|
|
2156
|
+
/** Transition atom value */
|
|
1986
2157
|
function $mol_wire_easing(next) {
|
|
1987
2158
|
const atom = $mol_wire_auto();
|
|
1988
2159
|
if (!(atom instanceof $mol_wire_atom))
|
|
@@ -2052,8 +2223,10 @@ var $;
|
|
|
2052
2223
|
"use strict";
|
|
2053
2224
|
var $;
|
|
2054
2225
|
(function ($) {
|
|
2226
|
+
/** Reactive Set */
|
|
2055
2227
|
class $mol_wire_set extends Set {
|
|
2056
2228
|
pub = new $mol_wire_pub;
|
|
2229
|
+
// Accessors
|
|
2057
2230
|
has(value) {
|
|
2058
2231
|
this.pub.promote();
|
|
2059
2232
|
return super.has(value);
|
|
@@ -2082,6 +2255,7 @@ var $;
|
|
|
2082
2255
|
this.pub.promote();
|
|
2083
2256
|
return super.size;
|
|
2084
2257
|
}
|
|
2258
|
+
// Mutators
|
|
2085
2259
|
add(value) {
|
|
2086
2260
|
if (super.has(value))
|
|
2087
2261
|
return this;
|
|
@@ -2101,6 +2275,7 @@ var $;
|
|
|
2101
2275
|
super.clear();
|
|
2102
2276
|
this.pub.emit();
|
|
2103
2277
|
}
|
|
2278
|
+
// Extensions
|
|
2104
2279
|
item(val, next) {
|
|
2105
2280
|
if (next === undefined)
|
|
2106
2281
|
return this.has(val);
|
|
@@ -2133,6 +2308,7 @@ var $;
|
|
|
2133
2308
|
if (type !== 'object' && type !== 'function')
|
|
2134
2309
|
return target;
|
|
2135
2310
|
return new Proxy(target, {
|
|
2311
|
+
// Readers
|
|
2136
2312
|
get(target, property) {
|
|
2137
2313
|
$mol_wire_proxy_pub(id, target).promote();
|
|
2138
2314
|
const suffix = '.' + (typeof property === 'symbol' ? property.description : property);
|
|
@@ -2158,6 +2334,7 @@ var $;
|
|
|
2158
2334
|
$mol_wire_proxy_pub(id, target).promote();
|
|
2159
2335
|
return Reflect.isExtensible(target);
|
|
2160
2336
|
},
|
|
2337
|
+
// Writers
|
|
2161
2338
|
set(target, property, next) {
|
|
2162
2339
|
const pub = pubs.get(target);
|
|
2163
2340
|
if (pub) {
|
|
@@ -2193,8 +2370,10 @@ var $;
|
|
|
2193
2370
|
"use strict";
|
|
2194
2371
|
var $;
|
|
2195
2372
|
(function ($) {
|
|
2373
|
+
/** reactive Dictionary */
|
|
2196
2374
|
class $mol_wire_dict extends Map {
|
|
2197
2375
|
pub = new $mol_wire_pub;
|
|
2376
|
+
// Accessors
|
|
2198
2377
|
has(key) {
|
|
2199
2378
|
this.pub.promote();
|
|
2200
2379
|
return super.has(key);
|
|
@@ -2227,11 +2406,12 @@ var $;
|
|
|
2227
2406
|
this.pub.promote();
|
|
2228
2407
|
return super.size;
|
|
2229
2408
|
}
|
|
2409
|
+
// Mutators
|
|
2230
2410
|
set(key, value) {
|
|
2231
2411
|
if (super.get(key) === value)
|
|
2232
2412
|
return this;
|
|
2233
2413
|
super.set(key, value);
|
|
2234
|
-
this.pub?.emit();
|
|
2414
|
+
this.pub?.emit(); // undefined in constructor
|
|
2235
2415
|
return this;
|
|
2236
2416
|
}
|
|
2237
2417
|
delete(key) {
|
|
@@ -2246,6 +2426,7 @@ var $;
|
|
|
2246
2426
|
super.clear();
|
|
2247
2427
|
this.pub.emit();
|
|
2248
2428
|
}
|
|
2429
|
+
// Extensions
|
|
2249
2430
|
item(key, next) {
|
|
2250
2431
|
if (next === undefined)
|
|
2251
2432
|
return this.get(key) ?? null;
|
|
@@ -2303,6 +2484,7 @@ var $;
|
|
|
2303
2484
|
"use strict";
|
|
2304
2485
|
var $;
|
|
2305
2486
|
(function ($) {
|
|
2487
|
+
/** Watch and logs reactive states. Logger automatically added to test bundle which is adding to `test.html`. */
|
|
2306
2488
|
class $mol_wire_log extends $mol_object2 {
|
|
2307
2489
|
static watch(task) {
|
|
2308
2490
|
return task;
|