mol_wire_dom 0.0.1721 → 0.0.1723
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 +195 -1
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +198 -12
- package/node.js.map +1 -1
- package/node.mjs +198 -12
- package/node.test.js +345 -13
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +145 -0
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +138 -8
- package/web.js.map +1 -1
- package/web.mjs +138 -8
- package/web.test.js +151 -1
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -23,6 +23,7 @@ $.$$ = $
|
|
|
23
23
|
"use strict";
|
|
24
24
|
var $;
|
|
25
25
|
(function ($) {
|
|
26
|
+
/** Generates unique identifier. */
|
|
26
27
|
function $mol_guid(length = 8, exists = () => false) {
|
|
27
28
|
for (;;) {
|
|
28
29
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -48,11 +49,16 @@ var $;
|
|
|
48
49
|
"use strict";
|
|
49
50
|
var $;
|
|
50
51
|
(function ($) {
|
|
52
|
+
/** Special status statuses. */
|
|
51
53
|
let $mol_wire_cursor;
|
|
52
54
|
(function ($mol_wire_cursor) {
|
|
55
|
+
/** Update required. */
|
|
53
56
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
57
|
+
/** Some of (transitive) pub update required. */
|
|
54
58
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
59
|
+
/** Actual state but may be dropped. */
|
|
55
60
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
61
|
+
/** State will never be changed. */
|
|
56
62
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
57
63
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
58
64
|
})($ || ($ = {}));
|
|
@@ -61,6 +67,9 @@ var $;
|
|
|
61
67
|
"use strict";
|
|
62
68
|
var $;
|
|
63
69
|
(function ($) {
|
|
70
|
+
/**
|
|
71
|
+
* Collects subscribers in compact array. 28B
|
|
72
|
+
*/
|
|
64
73
|
class $mol_wire_pub extends Object {
|
|
65
74
|
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
66
75
|
super();
|
|
@@ -68,10 +77,17 @@ var $;
|
|
|
68
77
|
}
|
|
69
78
|
[Symbol.toStringTag];
|
|
70
79
|
data = [];
|
|
80
|
+
// Derived objects should be Arrays.
|
|
71
81
|
static get [Symbol.species]() {
|
|
72
82
|
return Array;
|
|
73
83
|
}
|
|
74
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Index of first subscriber.
|
|
86
|
+
*/
|
|
87
|
+
sub_from = 0; // 4B
|
|
88
|
+
/**
|
|
89
|
+
* All current subscribers.
|
|
90
|
+
*/
|
|
75
91
|
get sub_list() {
|
|
76
92
|
const res = [];
|
|
77
93
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -79,14 +95,23 @@ var $;
|
|
|
79
95
|
}
|
|
80
96
|
return res;
|
|
81
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Has any subscribers or not.
|
|
100
|
+
*/
|
|
82
101
|
get sub_empty() {
|
|
83
102
|
return this.sub_from === this.data.length;
|
|
84
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
106
|
+
*/
|
|
85
107
|
sub_on(sub, pub_pos) {
|
|
86
108
|
const pos = this.data.length;
|
|
87
109
|
this.data.push(sub, pub_pos);
|
|
88
110
|
return pos;
|
|
89
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
114
|
+
*/
|
|
90
115
|
sub_off(sub_pos) {
|
|
91
116
|
if (!(sub_pos < this.data.length)) {
|
|
92
117
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -99,21 +124,39 @@ var $;
|
|
|
99
124
|
if (end === this.sub_from)
|
|
100
125
|
this.reap();
|
|
101
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Called when last sub was unsubscribed.
|
|
129
|
+
**/
|
|
102
130
|
reap() { }
|
|
131
|
+
/**
|
|
132
|
+
* Autowire this publisher with current subscriber.
|
|
133
|
+
**/
|
|
103
134
|
promote() {
|
|
104
135
|
$mol_wire_auto()?.track_next(this);
|
|
105
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Enforce actualization. Should not throw errors.
|
|
139
|
+
*/
|
|
106
140
|
fresh() { }
|
|
141
|
+
/**
|
|
142
|
+
* Allow to put data to caches in the subtree.
|
|
143
|
+
*/
|
|
107
144
|
complete() { }
|
|
108
145
|
get incompleted() {
|
|
109
146
|
return false;
|
|
110
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Notify subscribers about self changes.
|
|
150
|
+
*/
|
|
111
151
|
emit(quant = $mol_wire_cursor.stale) {
|
|
112
152
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
113
153
|
;
|
|
114
154
|
this.data[i].absorb(quant, this.data[i + 1]);
|
|
115
155
|
}
|
|
116
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
159
|
+
*/
|
|
117
160
|
peer_move(from_pos, to_pos) {
|
|
118
161
|
const peer = this.data[from_pos];
|
|
119
162
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -121,6 +164,9 @@ var $;
|
|
|
121
164
|
this.data[to_pos + 1] = self_pos;
|
|
122
165
|
peer.peer_repos(self_pos, to_pos);
|
|
123
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Updates self position in the peer.
|
|
169
|
+
*/
|
|
124
170
|
peer_repos(peer_pos, self_pos) {
|
|
125
171
|
this.data[peer_pos + 1] = self_pos;
|
|
126
172
|
}
|
|
@@ -136,10 +182,16 @@ var $;
|
|
|
136
182
|
var $;
|
|
137
183
|
(function ($) {
|
|
138
184
|
$.$mol_wire_auto_sub = null;
|
|
185
|
+
/**
|
|
186
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
187
|
+
*/
|
|
139
188
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
140
189
|
return $.$mol_wire_auto_sub = next;
|
|
141
190
|
}
|
|
142
191
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
192
|
+
/**
|
|
193
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
194
|
+
*/
|
|
143
195
|
$.$mol_wire_affected = [];
|
|
144
196
|
})($ || ($ = {}));
|
|
145
197
|
|
|
@@ -148,7 +200,7 @@ var $;
|
|
|
148
200
|
var $;
|
|
149
201
|
(function ($) {
|
|
150
202
|
function $mol_fail_hidden(error) {
|
|
151
|
-
throw error;
|
|
203
|
+
throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
|
|
152
204
|
}
|
|
153
205
|
$.$mol_fail_hidden = $mol_fail_hidden;
|
|
154
206
|
})($ || ($ = {}));
|
|
@@ -157,6 +209,7 @@ var $;
|
|
|
157
209
|
"use strict";
|
|
158
210
|
var $;
|
|
159
211
|
(function ($) {
|
|
212
|
+
// https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
|
|
160
213
|
$['devtoolsFormatters'] ||= [];
|
|
161
214
|
function $mol_dev_format_register(config) {
|
|
162
215
|
$['devtoolsFormatters'].push(config);
|
|
@@ -208,6 +261,7 @@ var $;
|
|
|
208
261
|
return false;
|
|
209
262
|
if (!val)
|
|
210
263
|
return false;
|
|
264
|
+
// if( Error.isError( val ) ) true
|
|
211
265
|
if (val[$.$mol_dev_format_body])
|
|
212
266
|
return true;
|
|
213
267
|
return false;
|
|
@@ -225,12 +279,16 @@ var $;
|
|
|
225
279
|
return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
|
|
226
280
|
}
|
|
227
281
|
}
|
|
282
|
+
// if( Error.isError( val ) ) {
|
|
283
|
+
// return $mol_dev_format_native( val )
|
|
284
|
+
// }
|
|
228
285
|
return null;
|
|
229
286
|
},
|
|
230
287
|
});
|
|
231
288
|
function $mol_dev_format_native(obj) {
|
|
232
289
|
if (typeof obj === 'undefined')
|
|
233
290
|
return $.$mol_dev_format_shade('undefined');
|
|
291
|
+
// if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
|
|
234
292
|
return [
|
|
235
293
|
'object',
|
|
236
294
|
{
|
|
@@ -288,6 +346,9 @@ var $;
|
|
|
288
346
|
'margin-left': '13px'
|
|
289
347
|
});
|
|
290
348
|
class Stack extends Array {
|
|
349
|
+
// [ Symbol.toPrimitive ]() {
|
|
350
|
+
// return this.toString()
|
|
351
|
+
// }
|
|
291
352
|
toString() {
|
|
292
353
|
return this.join('\n');
|
|
293
354
|
}
|
|
@@ -310,6 +371,7 @@ var $;
|
|
|
310
371
|
this.method = call.getMethodName() ?? '';
|
|
311
372
|
if (this.method === this.function)
|
|
312
373
|
this.method = '';
|
|
374
|
+
// const func = c.getFunction()
|
|
313
375
|
this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
|
|
314
376
|
this.eval = call.getEvalOrigin() ?? '';
|
|
315
377
|
this.source = call.getScriptNameOrSourceURL() ?? '';
|
|
@@ -356,9 +418,16 @@ var $;
|
|
|
356
418
|
"use strict";
|
|
357
419
|
var $;
|
|
358
420
|
(function ($) {
|
|
421
|
+
/**
|
|
422
|
+
* Publisher that can auto collect other publishers. 32B
|
|
423
|
+
*
|
|
424
|
+
* P1 P2 P3 P4 S1 S2 S3
|
|
425
|
+
* ^ ^
|
|
426
|
+
* pubs_from subs_from
|
|
427
|
+
*/
|
|
359
428
|
class $mol_wire_pub_sub extends $mol_wire_pub {
|
|
360
|
-
pub_from = 0;
|
|
361
|
-
cursor = $mol_wire_cursor.stale;
|
|
429
|
+
pub_from = 0; // 4B
|
|
430
|
+
cursor = $mol_wire_cursor.stale; // 4B
|
|
362
431
|
get temp() {
|
|
363
432
|
return false;
|
|
364
433
|
}
|
|
@@ -476,10 +545,27 @@ var $;
|
|
|
476
545
|
return;
|
|
477
546
|
this.cursor = quant;
|
|
478
547
|
this.emit($mol_wire_cursor.doubt);
|
|
548
|
+
// if( pos >= 0 && pos < this.sub_from - 2 ) {
|
|
549
|
+
// const pub = this.data[ pos ] as $mol_wire_pub
|
|
550
|
+
// if( pub instanceof $mol_wire_task ) return
|
|
551
|
+
// for(
|
|
552
|
+
// let cursor = this.pub_from;
|
|
553
|
+
// cursor < this.sub_from;
|
|
554
|
+
// cursor += 2
|
|
555
|
+
// ) {
|
|
556
|
+
// const pub = this.data[ cursor ] as $mol_wire_pub
|
|
557
|
+
// if( pub instanceof $mol_wire_task ) {
|
|
558
|
+
// pub.destructor()
|
|
559
|
+
// }
|
|
560
|
+
// }
|
|
561
|
+
// }
|
|
479
562
|
}
|
|
480
563
|
[$mol_dev_format_head]() {
|
|
481
564
|
return $mol_dev_format_native(this);
|
|
482
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Is subscribed to any publisher or not.
|
|
568
|
+
*/
|
|
483
569
|
get pub_empty() {
|
|
484
570
|
return this.sub_from === this.pub_from;
|
|
485
571
|
}
|
|
@@ -503,6 +589,11 @@ var $;
|
|
|
503
589
|
var $;
|
|
504
590
|
(function ($) {
|
|
505
591
|
const instances = new WeakSet();
|
|
592
|
+
/**
|
|
593
|
+
* Proxy that delegates all to lazy returned target.
|
|
594
|
+
*
|
|
595
|
+
* $mol_delegate( Array.prototype , ()=> fetch_array() )
|
|
596
|
+
*/
|
|
506
597
|
function $mol_delegate(proto, target) {
|
|
507
598
|
const proxy = new Proxy(proto, {
|
|
508
599
|
get: (_, field) => {
|
|
@@ -678,6 +769,9 @@ var $;
|
|
|
678
769
|
[Symbol.dispose]() {
|
|
679
770
|
this.destructor();
|
|
680
771
|
}
|
|
772
|
+
//[ Symbol.toPrimitive ]( hint: string ) {
|
|
773
|
+
// return hint === 'number' ? this.valueOf() : this.toString()
|
|
774
|
+
//}
|
|
681
775
|
toString() {
|
|
682
776
|
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
683
777
|
}
|
|
@@ -733,6 +827,13 @@ var $;
|
|
|
733
827
|
var $;
|
|
734
828
|
(function ($) {
|
|
735
829
|
const wrappers = new WeakMap();
|
|
830
|
+
/**
|
|
831
|
+
* Suspendable task with support both sync/async api.
|
|
832
|
+
*
|
|
833
|
+
* A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
|
|
834
|
+
* ^ ^ ^
|
|
835
|
+
* args_from pubs_from subs_from
|
|
836
|
+
**/
|
|
736
837
|
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
|
737
838
|
task;
|
|
738
839
|
host;
|
|
@@ -753,6 +854,7 @@ var $;
|
|
|
753
854
|
});
|
|
754
855
|
}
|
|
755
856
|
static sync() {
|
|
857
|
+
// Sync whole fiber graph
|
|
756
858
|
while (this.planning.size) {
|
|
757
859
|
for (const fiber of this.planning) {
|
|
758
860
|
this.planning.delete(fiber);
|
|
@@ -763,6 +865,7 @@ var $;
|
|
|
763
865
|
fiber.fresh();
|
|
764
866
|
}
|
|
765
867
|
}
|
|
868
|
+
// Collect garbage
|
|
766
869
|
while (this.reaping.size) {
|
|
767
870
|
const fibers = this.reaping;
|
|
768
871
|
this.reaping = new Set;
|
|
@@ -914,6 +1017,10 @@ var $;
|
|
|
914
1017
|
this.cursor = $mol_wire_cursor.stale;
|
|
915
1018
|
this.fresh();
|
|
916
1019
|
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
|
|
1022
|
+
* Should be called inside SuspenseAPI consumer (ie fiber).
|
|
1023
|
+
*/
|
|
917
1024
|
sync() {
|
|
918
1025
|
if (!$mol_wire_fiber.warm) {
|
|
919
1026
|
return this.result();
|
|
@@ -928,6 +1035,10 @@ var $;
|
|
|
928
1035
|
}
|
|
929
1036
|
return this.cache;
|
|
930
1037
|
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Asynchronous execution.
|
|
1040
|
+
* It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
|
|
1041
|
+
*/
|
|
931
1042
|
async async_raw() {
|
|
932
1043
|
while (true) {
|
|
933
1044
|
this.fresh();
|
|
@@ -940,6 +1051,7 @@ var $;
|
|
|
940
1051
|
if (!$mol_promise_like(this.cache))
|
|
941
1052
|
return this.cache;
|
|
942
1053
|
if (this.cursor === $mol_wire_cursor.final) {
|
|
1054
|
+
// never ends on destructed fiber
|
|
943
1055
|
await new Promise(() => { });
|
|
944
1056
|
}
|
|
945
1057
|
}
|
|
@@ -987,6 +1099,7 @@ var $;
|
|
|
987
1099
|
var $;
|
|
988
1100
|
(function ($) {
|
|
989
1101
|
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
1102
|
+
/** Returns string key for any value. */
|
|
990
1103
|
function $mol_key(value) {
|
|
991
1104
|
primitives: {
|
|
992
1105
|
if (typeof value === 'bigint')
|
|
@@ -994,9 +1107,9 @@ var $;
|
|
|
994
1107
|
if (typeof value === 'symbol')
|
|
995
1108
|
return `Symbol(${value.description})`;
|
|
996
1109
|
if (!value)
|
|
997
|
-
return JSON.stringify(value);
|
|
1110
|
+
return JSON.stringify(value); // 0, null, ""
|
|
998
1111
|
if (typeof value !== 'object' && typeof value !== 'function')
|
|
999
|
-
return JSON.stringify(value);
|
|
1112
|
+
return JSON.stringify(value); // boolean, number, string
|
|
1000
1113
|
}
|
|
1001
1114
|
caching: {
|
|
1002
1115
|
let key = $mol_key_store.get(value);
|
|
@@ -1074,6 +1187,10 @@ var $;
|
|
|
1074
1187
|
var $;
|
|
1075
1188
|
(function ($) {
|
|
1076
1189
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
1190
|
+
/**
|
|
1191
|
+
* Deeply compares two values. Returns true if equal.
|
|
1192
|
+
* Define `Symbol.toPrimitive` to customize.
|
|
1193
|
+
*/
|
|
1077
1194
|
function $mol_compare_deep(left, right) {
|
|
1078
1195
|
if (Object.is(left, right))
|
|
1079
1196
|
return true;
|
|
@@ -1213,6 +1330,7 @@ var $;
|
|
|
1213
1330
|
"use strict";
|
|
1214
1331
|
var $;
|
|
1215
1332
|
(function ($) {
|
|
1333
|
+
/** Log begin of collapsed group only when some logged inside, returns func to close group */
|
|
1216
1334
|
function $mol_log3_area_lazy(event) {
|
|
1217
1335
|
const self = this.$;
|
|
1218
1336
|
const stack = self.$mol_log3_stack;
|
|
@@ -1237,6 +1355,7 @@ var $;
|
|
|
1237
1355
|
"use strict";
|
|
1238
1356
|
var $;
|
|
1239
1357
|
(function ($) {
|
|
1358
|
+
/** Position in any resource. */
|
|
1240
1359
|
class $mol_span extends $mol_object2 {
|
|
1241
1360
|
uri;
|
|
1242
1361
|
source;
|
|
@@ -1252,13 +1371,17 @@ var $;
|
|
|
1252
1371
|
this.length = length;
|
|
1253
1372
|
this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
|
|
1254
1373
|
}
|
|
1374
|
+
/** Span for begin of unknown resource */
|
|
1255
1375
|
static unknown = $mol_span.begin('?');
|
|
1376
|
+
/** Makes new span for begin of resource. */
|
|
1256
1377
|
static begin(uri, source = '') {
|
|
1257
1378
|
return new $mol_span(uri, source, 1, 1, 0);
|
|
1258
1379
|
}
|
|
1380
|
+
/** Makes new span for end of resource. */
|
|
1259
1381
|
static end(uri, source) {
|
|
1260
1382
|
return new $mol_span(uri, source, 1, source.length + 1, 0);
|
|
1261
1383
|
}
|
|
1384
|
+
/** Makes new span for entire resource. */
|
|
1262
1385
|
static entire(uri, source) {
|
|
1263
1386
|
return new $mol_span(uri, source, 1, 1, source.length);
|
|
1264
1387
|
}
|
|
@@ -1273,15 +1396,19 @@ var $;
|
|
|
1273
1396
|
length: this.length
|
|
1274
1397
|
};
|
|
1275
1398
|
}
|
|
1399
|
+
/** Makes new error for this span. */
|
|
1276
1400
|
error(message, Class = Error) {
|
|
1277
1401
|
return new Class(`${message} (${this})`);
|
|
1278
1402
|
}
|
|
1403
|
+
/** Makes new span for same uri. */
|
|
1279
1404
|
span(row, col, length) {
|
|
1280
1405
|
return new $mol_span(this.uri, this.source, row, col, length);
|
|
1281
1406
|
}
|
|
1407
|
+
/** Makes new span after end of this. */
|
|
1282
1408
|
after(length = 0) {
|
|
1283
1409
|
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
1284
1410
|
}
|
|
1411
|
+
/** Makes new span between begin and end. */
|
|
1285
1412
|
slice(begin, end = -1) {
|
|
1286
1413
|
let len = this.length;
|
|
1287
1414
|
if (begin < 0)
|
|
@@ -1304,6 +1431,7 @@ var $;
|
|
|
1304
1431
|
"use strict";
|
|
1305
1432
|
var $;
|
|
1306
1433
|
(function ($) {
|
|
1434
|
+
/** Serializes tree to string in tree format. */
|
|
1307
1435
|
function $mol_tree2_to_string(tree) {
|
|
1308
1436
|
let output = [];
|
|
1309
1437
|
function dump(tree, prefix = '') {
|
|
@@ -1347,12 +1475,25 @@ var $;
|
|
|
1347
1475
|
"use strict";
|
|
1348
1476
|
var $;
|
|
1349
1477
|
(function ($) {
|
|
1478
|
+
/**
|
|
1479
|
+
* Abstract Syntax Tree with human readable serialization.
|
|
1480
|
+
* Avoid direct instantiation. Use static factories instead.
|
|
1481
|
+
* @see https://github.com/nin-jin/tree.d
|
|
1482
|
+
*/
|
|
1350
1483
|
class $mol_tree2 extends Object {
|
|
1351
1484
|
type;
|
|
1352
1485
|
value;
|
|
1353
1486
|
kids;
|
|
1354
1487
|
span;
|
|
1355
|
-
constructor(
|
|
1488
|
+
constructor(
|
|
1489
|
+
/** Type of structural node, `value` should be empty */
|
|
1490
|
+
type,
|
|
1491
|
+
/** Content of data node, `type` should be empty */
|
|
1492
|
+
value,
|
|
1493
|
+
/** Child nodes */
|
|
1494
|
+
kids,
|
|
1495
|
+
/** Position in most far source resource */
|
|
1496
|
+
span) {
|
|
1356
1497
|
super();
|
|
1357
1498
|
this.type = type;
|
|
1358
1499
|
this.value = value;
|
|
@@ -1360,12 +1501,15 @@ var $;
|
|
|
1360
1501
|
this.span = span;
|
|
1361
1502
|
this[Symbol.toStringTag] = type || '\\' + value;
|
|
1362
1503
|
}
|
|
1504
|
+
/** Makes collection node. */
|
|
1363
1505
|
static list(kids, span = $mol_span.unknown) {
|
|
1364
1506
|
return new $mol_tree2('', '', kids, span);
|
|
1365
1507
|
}
|
|
1508
|
+
/** Makes new derived collection node. */
|
|
1366
1509
|
list(kids) {
|
|
1367
1510
|
return $mol_tree2.list(kids, this.span);
|
|
1368
1511
|
}
|
|
1512
|
+
/** Makes data node for any string. */
|
|
1369
1513
|
static data(value, kids = [], span = $mol_span.unknown) {
|
|
1370
1514
|
const chunks = value.split('\n');
|
|
1371
1515
|
if (chunks.length > 1) {
|
|
@@ -1379,21 +1523,26 @@ var $;
|
|
|
1379
1523
|
}
|
|
1380
1524
|
return new $mol_tree2('', value, kids, span);
|
|
1381
1525
|
}
|
|
1526
|
+
/** Makes new derived data node. */
|
|
1382
1527
|
data(value, kids = []) {
|
|
1383
1528
|
return $mol_tree2.data(value, kids, this.span);
|
|
1384
1529
|
}
|
|
1530
|
+
/** Makes struct node. */
|
|
1385
1531
|
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
1386
1532
|
if (/[ \n\t\\]/.test(type)) {
|
|
1387
1533
|
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
1388
1534
|
}
|
|
1389
1535
|
return new $mol_tree2(type, '', kids, span);
|
|
1390
1536
|
}
|
|
1537
|
+
/** Makes new derived structural node. */
|
|
1391
1538
|
struct(type, kids = []) {
|
|
1392
1539
|
return $mol_tree2.struct(type, kids, this.span);
|
|
1393
1540
|
}
|
|
1541
|
+
/** Makes new derived node with different kids id defined. */
|
|
1394
1542
|
clone(kids, span = this.span) {
|
|
1395
1543
|
return new $mol_tree2(this.type, this.value, kids, span);
|
|
1396
1544
|
}
|
|
1545
|
+
/** Returns multiline text content. */
|
|
1397
1546
|
text() {
|
|
1398
1547
|
var values = [];
|
|
1399
1548
|
for (var kid of this.kids) {
|
|
@@ -1403,15 +1552,20 @@ var $;
|
|
|
1403
1552
|
}
|
|
1404
1553
|
return this.value + values.join('\n');
|
|
1405
1554
|
}
|
|
1555
|
+
/** Parses tree format. */
|
|
1556
|
+
/** @deprecated Use $mol_tree2_from_string */
|
|
1406
1557
|
static fromString(str, uri = 'unknown') {
|
|
1407
1558
|
return $$.$mol_tree2_from_string(str, uri);
|
|
1408
1559
|
}
|
|
1560
|
+
/** Serializes to tree format. */
|
|
1409
1561
|
toString() {
|
|
1410
1562
|
return $$.$mol_tree2_to_string(this);
|
|
1411
1563
|
}
|
|
1564
|
+
/** Makes new tree with node overrided by path. */
|
|
1412
1565
|
insert(value, ...path) {
|
|
1413
1566
|
return this.update($mol_maybe(value), ...path)[0];
|
|
1414
1567
|
}
|
|
1568
|
+
/** Makes new tree with node overrided by path. */
|
|
1415
1569
|
update(value, ...path) {
|
|
1416
1570
|
if (path.length === 0)
|
|
1417
1571
|
return value;
|
|
@@ -1444,6 +1598,7 @@ var $;
|
|
|
1444
1598
|
return [this.clone(kids)];
|
|
1445
1599
|
}
|
|
1446
1600
|
}
|
|
1601
|
+
/** Query nodes by path. */
|
|
1447
1602
|
select(...path) {
|
|
1448
1603
|
let next = [this];
|
|
1449
1604
|
for (const type of path) {
|
|
@@ -1470,6 +1625,7 @@ var $;
|
|
|
1470
1625
|
}
|
|
1471
1626
|
return this.list(next);
|
|
1472
1627
|
}
|
|
1628
|
+
/** Filter kids by path or value. */
|
|
1473
1629
|
filter(path, value) {
|
|
1474
1630
|
const sub = this.kids.filter(item => {
|
|
1475
1631
|
var found = item.select(...path);
|
|
@@ -1497,9 +1653,11 @@ var $;
|
|
|
1497
1653
|
$mol_fail_hidden(error);
|
|
1498
1654
|
}
|
|
1499
1655
|
}
|
|
1656
|
+
/** Transform tree through context with transformers */
|
|
1500
1657
|
hack(belt, context = {}) {
|
|
1501
1658
|
return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
|
|
1502
1659
|
}
|
|
1660
|
+
/** Makes Error with node coordinates. */
|
|
1503
1661
|
error(message, Class = Error) {
|
|
1504
1662
|
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
1505
1663
|
}
|
|
@@ -1517,6 +1675,7 @@ var $;
|
|
|
1517
1675
|
"use strict";
|
|
1518
1676
|
var $;
|
|
1519
1677
|
(function ($) {
|
|
1678
|
+
/** Syntax error with cordinates and source line snippet. */
|
|
1520
1679
|
class $mol_error_syntax extends SyntaxError {
|
|
1521
1680
|
reason;
|
|
1522
1681
|
line;
|
|
@@ -1535,6 +1694,7 @@ var $;
|
|
|
1535
1694
|
"use strict";
|
|
1536
1695
|
var $;
|
|
1537
1696
|
(function ($) {
|
|
1697
|
+
/** Parses tree format from string. */
|
|
1538
1698
|
function $mol_tree2_from_string(str, uri = '?') {
|
|
1539
1699
|
const span = $mol_span.entire(uri, str);
|
|
1540
1700
|
var root = $mol_tree2.list([], span);
|
|
@@ -1544,6 +1704,7 @@ var $;
|
|
|
1544
1704
|
var indent = 0;
|
|
1545
1705
|
var line_start = pos;
|
|
1546
1706
|
row++;
|
|
1707
|
+
// read indent
|
|
1547
1708
|
while (str.length > pos && str[pos] == '\t') {
|
|
1548
1709
|
indent++;
|
|
1549
1710
|
pos++;
|
|
@@ -1552,8 +1713,10 @@ var $;
|
|
|
1552
1713
|
min_indent = indent;
|
|
1553
1714
|
}
|
|
1554
1715
|
indent -= min_indent;
|
|
1716
|
+
// invalid tab size
|
|
1555
1717
|
if (indent < 0 || indent >= stack.length) {
|
|
1556
1718
|
const sp = span.span(row, 1, pos - line_start);
|
|
1719
|
+
// skip error line
|
|
1557
1720
|
while (str.length > pos && str[pos] != '\n') {
|
|
1558
1721
|
pos++;
|
|
1559
1722
|
}
|
|
@@ -1568,7 +1731,9 @@ var $;
|
|
|
1568
1731
|
}
|
|
1569
1732
|
stack.length = indent + 1;
|
|
1570
1733
|
var parent = stack[indent];
|
|
1734
|
+
// parse types
|
|
1571
1735
|
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
1736
|
+
// type can not contain space and tab
|
|
1572
1737
|
var error_start = pos;
|
|
1573
1738
|
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
1574
1739
|
pos++;
|
|
@@ -1580,6 +1745,7 @@ var $;
|
|
|
1580
1745
|
const sp = span.span(row, error_start - line_start + 1, pos - error_start);
|
|
1581
1746
|
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
1582
1747
|
}
|
|
1748
|
+
// read type
|
|
1583
1749
|
var type_start = pos;
|
|
1584
1750
|
while (str.length > pos &&
|
|
1585
1751
|
str[pos] != '\\' &&
|
|
@@ -1594,10 +1760,12 @@ var $;
|
|
|
1594
1760
|
parent_kids.push(next);
|
|
1595
1761
|
parent = next;
|
|
1596
1762
|
}
|
|
1763
|
+
// read one space if exists
|
|
1597
1764
|
if (str.length > pos && str[pos] == ' ') {
|
|
1598
1765
|
pos++;
|
|
1599
1766
|
}
|
|
1600
1767
|
}
|
|
1768
|
+
// read data
|
|
1601
1769
|
if (str.length > pos && str[pos] == '\\') {
|
|
1602
1770
|
var data_start = pos;
|
|
1603
1771
|
while (str.length > pos && str[pos] != '\n') {
|
|
@@ -1608,6 +1776,7 @@ var $;
|
|
|
1608
1776
|
parent_kids.push(next);
|
|
1609
1777
|
parent = next;
|
|
1610
1778
|
}
|
|
1779
|
+
// now must be end of text
|
|
1611
1780
|
if (str.length === pos && stack.length > 0) {
|
|
1612
1781
|
const sp = span.span(row, pos - line_start + 1, 1);
|
|
1613
1782
|
this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
@@ -1700,6 +1869,7 @@ var $;
|
|
|
1700
1869
|
"use strict";
|
|
1701
1870
|
var $;
|
|
1702
1871
|
(function ($) {
|
|
1872
|
+
/** Module for working with terminal. Text coloring when output in terminal */
|
|
1703
1873
|
class $mol_term_color {
|
|
1704
1874
|
static reset = this.ansi(0, 0);
|
|
1705
1875
|
static bold = this.ansi(1, 22);
|
|
@@ -1771,6 +1941,7 @@ var $;
|
|
|
1771
1941
|
"use strict";
|
|
1772
1942
|
var $;
|
|
1773
1943
|
(function ($) {
|
|
1944
|
+
/** One-shot fiber */
|
|
1774
1945
|
class $mol_wire_task extends $mol_wire_fiber {
|
|
1775
1946
|
static getter(task) {
|
|
1776
1947
|
return function $mol_wire_task_get(host, args) {
|
|
@@ -1796,6 +1967,7 @@ var $;
|
|
|
1796
1967
|
}
|
|
1797
1968
|
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
|
1798
1969
|
const next = new $mol_wire_task(key, task, host, args);
|
|
1970
|
+
// Disabled because non-idempotency is required for try-catch
|
|
1799
1971
|
if (existen?.temp) {
|
|
1800
1972
|
$$.$mol_log3_warn({
|
|
1801
1973
|
place: '$mol_wire_task',
|
|
@@ -1828,7 +2000,7 @@ var $;
|
|
|
1828
2000
|
try {
|
|
1829
2001
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
1830
2002
|
}
|
|
1831
|
-
catch {
|
|
2003
|
+
catch { // Promises throw in strict mode
|
|
1832
2004
|
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
1833
2005
|
}
|
|
1834
2006
|
}
|
|
@@ -1853,6 +2025,9 @@ var $;
|
|
|
1853
2025
|
"use strict";
|
|
1854
2026
|
var $;
|
|
1855
2027
|
(function ($) {
|
|
2028
|
+
/**
|
|
2029
|
+
* Decorates method to fiber to ensure it is executed only once inside other fiber.
|
|
2030
|
+
*/
|
|
1856
2031
|
function $mol_wire_method(host, field, descr) {
|
|
1857
2032
|
if (!descr)
|
|
1858
2033
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -1934,6 +2109,7 @@ var $;
|
|
|
1934
2109
|
"use strict";
|
|
1935
2110
|
var $;
|
|
1936
2111
|
(function ($) {
|
|
2112
|
+
/** Long-living fiber. */
|
|
1937
2113
|
class $mol_wire_atom extends $mol_wire_fiber {
|
|
1938
2114
|
static solo(host, task) {
|
|
1939
2115
|
const field = task.name + '()';
|
|
@@ -1984,7 +2160,11 @@ var $;
|
|
|
1984
2160
|
}
|
|
1985
2161
|
$mol_wire_atom.watching.add(this);
|
|
1986
2162
|
}
|
|
2163
|
+
/**
|
|
2164
|
+
* Update atom value through another temp fiber.
|
|
2165
|
+
*/
|
|
1987
2166
|
resync(args) {
|
|
2167
|
+
// enforce pulling tasks abort
|
|
1988
2168
|
for (let cursor = this.pub_from; cursor < this.sub_from; cursor += 2) {
|
|
1989
2169
|
const pub = this.data[cursor];
|
|
1990
2170
|
if (pub && pub instanceof $mol_wire_task) {
|
|
@@ -2045,7 +2225,7 @@ var $;
|
|
|
2045
2225
|
try {
|
|
2046
2226
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
2047
2227
|
}
|
|
2048
|
-
catch {
|
|
2228
|
+
catch { // Promises throw in strict mode
|
|
2049
2229
|
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
2050
2230
|
}
|
|
2051
2231
|
}
|
|
@@ -2082,7 +2262,7 @@ var $;
|
|
|
2082
2262
|
"use strict";
|
|
2083
2263
|
var $;
|
|
2084
2264
|
(function ($) {
|
|
2085
|
-
const mod = require('module');
|
|
2265
|
+
const mod = require /****/('module');
|
|
2086
2266
|
const internals = mod.builtinModules;
|
|
2087
2267
|
function $node_internal_check(name) {
|
|
2088
2268
|
if (name.startsWith('node:'))
|
|
@@ -2096,8 +2276,8 @@ var $;
|
|
|
2096
2276
|
"use strict";
|
|
2097
2277
|
var $;
|
|
2098
2278
|
(function ($) {
|
|
2099
|
-
const path = require('path');
|
|
2100
|
-
const mod = require('module');
|
|
2279
|
+
const path = require /****/('path');
|
|
2280
|
+
const mod = require /****/('module');
|
|
2101
2281
|
const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
|
|
2102
2282
|
function $node_autoinstall(name) {
|
|
2103
2283
|
try {
|
|
@@ -2172,6 +2352,7 @@ var $;
|
|
|
2172
2352
|
])
|
|
2173
2353
|
].map(frame_normalize).join('\n')
|
|
2174
2354
|
});
|
|
2355
|
+
// в nodejs, что б не дублировалось cause в консоли
|
|
2175
2356
|
Object.defineProperty(this, 'cause', {
|
|
2176
2357
|
get: () => cause
|
|
2177
2358
|
});
|
|
@@ -2260,6 +2441,10 @@ var $;
|
|
|
2260
2441
|
props[field] = get_val;
|
|
2261
2442
|
return get_val;
|
|
2262
2443
|
}
|
|
2444
|
+
/**
|
|
2445
|
+
* Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
|
|
2446
|
+
* @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
|
|
2447
|
+
*/
|
|
2263
2448
|
function $mol_wire_sync(obj) {
|
|
2264
2449
|
return new Proxy(obj, {
|
|
2265
2450
|
get(obj, field) {
|
|
@@ -2616,6 +2801,7 @@ var $;
|
|
|
2616
2801
|
;
|
|
2617
2802
|
$mol_wire_dom(this)[field] = getter;
|
|
2618
2803
|
}
|
|
2804
|
+
/** Polyfill makes DOM reactive. */
|
|
2619
2805
|
function $mol_wire_dom(el) {
|
|
2620
2806
|
if (el.__defineGetter__ === redefine)
|
|
2621
2807
|
return el;
|
|
@@ -2980,6 +3166,12 @@ var $;
|
|
|
2980
3166
|
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
2981
3167
|
};
|
|
2982
3168
|
$.$mol_jsx_frag = '';
|
|
3169
|
+
/**
|
|
3170
|
+
* JSX adapter that makes DOM tree.
|
|
3171
|
+
* Generates global unique ids for every DOM-element by components tree with ids.
|
|
3172
|
+
* Ensures all local ids are unique.
|
|
3173
|
+
* Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
|
|
3174
|
+
*/
|
|
2983
3175
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
2984
3176
|
const id = props && props.id || '';
|
|
2985
3177
|
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
@@ -3090,6 +3282,8 @@ var $;
|
|
|
3090
3282
|
|
|
3091
3283
|
;
|
|
3092
3284
|
"use strict";
|
|
3285
|
+
/** @jsx $mol_jsx */
|
|
3286
|
+
/** @jsxFrag $mol_jsx_frag */
|
|
3093
3287
|
var $;
|
|
3094
3288
|
(function ($) {
|
|
3095
3289
|
$mol_test({
|
|
@@ -3195,6 +3389,7 @@ var $;
|
|
|
3195
3389
|
"use strict";
|
|
3196
3390
|
var $;
|
|
3197
3391
|
(function ($) {
|
|
3392
|
+
/** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
|
|
3198
3393
|
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
3199
3394
|
const source = typeof item === 'function' ? new $mol_range2_array() : item;
|
|
3200
3395
|
if (typeof item !== 'function') {
|
|
@@ -3243,6 +3438,7 @@ var $;
|
|
|
3243
3438
|
}
|
|
3244
3439
|
$.$mol_range2 = $mol_range2;
|
|
3245
3440
|
class $mol_range2_array extends Array {
|
|
3441
|
+
// Lazy
|
|
3246
3442
|
concat(...tail) {
|
|
3247
3443
|
if (tail.length === 0)
|
|
3248
3444
|
return this;
|
|
@@ -3254,6 +3450,7 @@ var $;
|
|
|
3254
3450
|
}
|
|
3255
3451
|
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
3256
3452
|
}
|
|
3453
|
+
// Lazy
|
|
3257
3454
|
filter(check, context) {
|
|
3258
3455
|
const filtered = [];
|
|
3259
3456
|
let cursor = -1;
|
|
@@ -3266,13 +3463,16 @@ var $;
|
|
|
3266
3463
|
return filtered[index];
|
|
3267
3464
|
}, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
|
|
3268
3465
|
}
|
|
3466
|
+
// Diligent
|
|
3269
3467
|
forEach(proceed, context) {
|
|
3270
3468
|
for (let [key, value] of this.entries())
|
|
3271
3469
|
proceed.call(context, value, key, this);
|
|
3272
3470
|
}
|
|
3471
|
+
// Lazy
|
|
3273
3472
|
map(proceed, context) {
|
|
3274
3473
|
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
3275
3474
|
}
|
|
3475
|
+
// Diligent
|
|
3276
3476
|
reduce(merge, result) {
|
|
3277
3477
|
let index = 0;
|
|
3278
3478
|
if (arguments.length === 1) {
|
|
@@ -3283,12 +3483,15 @@ var $;
|
|
|
3283
3483
|
}
|
|
3284
3484
|
return result;
|
|
3285
3485
|
}
|
|
3486
|
+
// Lazy
|
|
3286
3487
|
toReversed() {
|
|
3287
3488
|
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
3288
3489
|
}
|
|
3490
|
+
// Lazy
|
|
3289
3491
|
slice(from = 0, to = this.length) {
|
|
3290
3492
|
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
3291
3493
|
}
|
|
3494
|
+
// Lazy
|
|
3292
3495
|
some(check, context) {
|
|
3293
3496
|
for (let index = 0; index < this.length; ++index) {
|
|
3294
3497
|
if (check.call(context, this[index], index, this))
|
|
@@ -3481,6 +3684,7 @@ var $;
|
|
|
3481
3684
|
|
|
3482
3685
|
;
|
|
3483
3686
|
"use strict";
|
|
3687
|
+
/** @jsx $mol_jsx */
|
|
3484
3688
|
var $;
|
|
3485
3689
|
(function ($) {
|
|
3486
3690
|
$mol_test({
|
|
@@ -3542,6 +3746,7 @@ var $;
|
|
|
3542
3746
|
const obj3_copy = { test: 3, obj2: obj2_copy };
|
|
3543
3747
|
obj1.obj3 = obj3;
|
|
3544
3748
|
obj1_copy.obj3 = obj3_copy;
|
|
3749
|
+
// warmup cache
|
|
3545
3750
|
$mol_assert_not($mol_compare_deep(obj1, {}));
|
|
3546
3751
|
$mol_assert_not($mol_compare_deep(obj2, {}));
|
|
3547
3752
|
$mol_assert_not($mol_compare_deep(obj3, {}));
|
|
@@ -3611,18 +3816,34 @@ var $;
|
|
|
3611
3816
|
"use strict";
|
|
3612
3817
|
var $;
|
|
3613
3818
|
(function ($) {
|
|
3819
|
+
/**
|
|
3820
|
+
* Argument must be Truthy
|
|
3821
|
+
* @deprecated use $mol_assert_equal instead
|
|
3822
|
+
*/
|
|
3614
3823
|
function $mol_assert_ok(value) {
|
|
3615
3824
|
if (value)
|
|
3616
3825
|
return;
|
|
3617
3826
|
$mol_fail(new Error(`${value} ≠ true`));
|
|
3618
3827
|
}
|
|
3619
3828
|
$.$mol_assert_ok = $mol_assert_ok;
|
|
3829
|
+
/**
|
|
3830
|
+
* Argument must be Falsy
|
|
3831
|
+
* @deprecated use $mol_assert_equal instead
|
|
3832
|
+
*/
|
|
3620
3833
|
function $mol_assert_not(value) {
|
|
3621
3834
|
if (!value)
|
|
3622
3835
|
return;
|
|
3623
3836
|
$mol_fail(new Error(`${value} ≠ false`));
|
|
3624
3837
|
}
|
|
3625
3838
|
$.$mol_assert_not = $mol_assert_not;
|
|
3839
|
+
/**
|
|
3840
|
+
* Handler must throw an error.
|
|
3841
|
+
* @example
|
|
3842
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
|
|
3843
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
|
|
3844
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
|
|
3845
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
3846
|
+
*/
|
|
3626
3847
|
function $mol_assert_fail(handler, ErrorRight) {
|
|
3627
3848
|
const fail = $.$mol_fail;
|
|
3628
3849
|
try {
|
|
@@ -3645,10 +3866,18 @@ var $;
|
|
|
3645
3866
|
$mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
|
|
3646
3867
|
}
|
|
3647
3868
|
$.$mol_assert_fail = $mol_assert_fail;
|
|
3869
|
+
/** @deprecated Use $mol_assert_equal */
|
|
3648
3870
|
function $mol_assert_like(...args) {
|
|
3649
3871
|
$mol_assert_equal(...args);
|
|
3650
3872
|
}
|
|
3651
3873
|
$.$mol_assert_like = $mol_assert_like;
|
|
3874
|
+
/**
|
|
3875
|
+
* All arguments must not be structural equal to each other.
|
|
3876
|
+
* @example
|
|
3877
|
+
* $mol_assert_unique( 1 , 2 , 3 ) // Passes
|
|
3878
|
+
* $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
|
|
3879
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
3880
|
+
*/
|
|
3652
3881
|
function $mol_assert_unique(...args) {
|
|
3653
3882
|
for (let i = 0; i < args.length; ++i) {
|
|
3654
3883
|
for (let j = 0; j < args.length; ++j) {
|
|
@@ -3661,6 +3890,13 @@ var $;
|
|
|
3661
3890
|
}
|
|
3662
3891
|
}
|
|
3663
3892
|
$.$mol_assert_unique = $mol_assert_unique;
|
|
3893
|
+
/**
|
|
3894
|
+
* All arguments must be structural equal each other.
|
|
3895
|
+
* @example
|
|
3896
|
+
* $mol_assert_like( [1] , [1] , [1] ) // Passes
|
|
3897
|
+
* $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
|
|
3898
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
3899
|
+
*/
|
|
3664
3900
|
function $mol_assert_equal(...args) {
|
|
3665
3901
|
for (let i = 1; i < args.length; ++i) {
|
|
3666
3902
|
if ($mol_compare_deep(args[0], args[i]))
|
|
@@ -4048,6 +4284,12 @@ var $;
|
|
|
4048
4284
|
'return result without errors'() {
|
|
4049
4285
|
$mol_assert_equal($mol_try(() => false), false);
|
|
4050
4286
|
},
|
|
4287
|
+
//'return error if thrown'() {
|
|
4288
|
+
//
|
|
4289
|
+
// const error = new Error( '$mol_try test error' )
|
|
4290
|
+
// $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
|
|
4291
|
+
//
|
|
4292
|
+
//} ,
|
|
4051
4293
|
});
|
|
4052
4294
|
})($ || ($ = {}));
|
|
4053
4295
|
|
|
@@ -4120,6 +4362,7 @@ var $;
|
|
|
4120
4362
|
"use strict";
|
|
4121
4363
|
var $;
|
|
4122
4364
|
(function ($) {
|
|
4365
|
+
/// @todo right orderinng
|
|
4123
4366
|
$.$mol_after_mock_queue = [];
|
|
4124
4367
|
function $mol_after_mock_warp() {
|
|
4125
4368
|
const queue = $.$mol_after_mock_queue.splice(0);
|
|
@@ -4247,6 +4490,7 @@ var $;
|
|
|
4247
4490
|
|
|
4248
4491
|
;
|
|
4249
4492
|
"use strict";
|
|
4493
|
+
/** @jsx $mol_jsx */
|
|
4250
4494
|
var $;
|
|
4251
4495
|
(function ($) {
|
|
4252
4496
|
$mol_test({
|
|
@@ -4455,6 +4699,7 @@ var $;
|
|
|
4455
4699
|
"use strict";
|
|
4456
4700
|
var $;
|
|
4457
4701
|
(function ($) {
|
|
4702
|
+
/** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
|
|
4458
4703
|
function $mol_wire_async(obj) {
|
|
4459
4704
|
let fiber;
|
|
4460
4705
|
const temp = $mol_wire_task.getter(obj);
|
|
@@ -4538,6 +4783,7 @@ var $;
|
|
|
4538
4783
|
"use strict";
|
|
4539
4784
|
var $;
|
|
4540
4785
|
(function ($) {
|
|
4786
|
+
/** Decorates solo object channel to [mol_wire_atom](../atom/atom.ts). */
|
|
4541
4787
|
function $mol_wire_solo(host, field, descr) {
|
|
4542
4788
|
if (!descr)
|
|
4543
4789
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -4577,6 +4823,7 @@ var $;
|
|
|
4577
4823
|
var $;
|
|
4578
4824
|
(function ($_1) {
|
|
4579
4825
|
$mol_test({
|
|
4826
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#component-states
|
|
4580
4827
|
'Cached channel'($) {
|
|
4581
4828
|
class App extends $mol_object2 {
|
|
4582
4829
|
static $ = $;
|
|
@@ -4634,6 +4881,7 @@ var $;
|
|
|
4634
4881
|
$mol_assert_equal(App.value(5), 21);
|
|
4635
4882
|
$mol_assert_equal(App.value(), 21);
|
|
4636
4883
|
},
|
|
4884
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-consistency
|
|
4637
4885
|
'Auto recalculation of cached values'($) {
|
|
4638
4886
|
class App extends $mol_object2 {
|
|
4639
4887
|
static $ = $;
|
|
@@ -4661,6 +4909,7 @@ var $;
|
|
|
4661
4909
|
App.xxx(5);
|
|
4662
4910
|
$mol_assert_equal(App.zzz(), 7);
|
|
4663
4911
|
},
|
|
4912
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-reasonability
|
|
4664
4913
|
'Skip recalculation when actually no dependency changes'($) {
|
|
4665
4914
|
const log = [];
|
|
4666
4915
|
class App extends $mol_object2 {
|
|
@@ -4694,6 +4943,7 @@ var $;
|
|
|
4694
4943
|
App.zzz();
|
|
4695
4944
|
$mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
|
|
4696
4945
|
},
|
|
4946
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#flow-auto
|
|
4697
4947
|
'Flow: Auto'($) {
|
|
4698
4948
|
class App extends $mol_object2 {
|
|
4699
4949
|
static get $() { return $; }
|
|
@@ -4731,6 +4981,7 @@ var $;
|
|
|
4731
4981
|
$mol_assert_equal(App.result(), 23);
|
|
4732
4982
|
$mol_assert_equal(App.counter, 4);
|
|
4733
4983
|
},
|
|
4984
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#dupes-equality
|
|
4734
4985
|
'Dupes: Equality'($) {
|
|
4735
4986
|
let counter = 0;
|
|
4736
4987
|
class App extends $mol_object2 {
|
|
@@ -4754,6 +5005,7 @@ var $;
|
|
|
4754
5005
|
App.foo({ numbs: [2] });
|
|
4755
5006
|
$mol_assert_like(App.bar(), { numbs: [2], count: 2 });
|
|
4756
5007
|
},
|
|
5008
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#cycle-fail
|
|
4757
5009
|
'Cycle: Fail'($) {
|
|
4758
5010
|
class App extends $mol_object2 {
|
|
4759
5011
|
static $ = $;
|
|
@@ -4778,6 +5030,29 @@ var $;
|
|
|
4778
5030
|
], App, "test", null);
|
|
4779
5031
|
App.test();
|
|
4780
5032
|
},
|
|
5033
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
5034
|
+
// 'Update deps on push'( $ ) {
|
|
5035
|
+
// class App extends $mol_object2 {
|
|
5036
|
+
// static $ = $
|
|
5037
|
+
// @ $mol_wire_solo
|
|
5038
|
+
// static left( next = false ) {
|
|
5039
|
+
// return next
|
|
5040
|
+
// }
|
|
5041
|
+
// @ $mol_wire_solo
|
|
5042
|
+
// static right( next = false ) {
|
|
5043
|
+
// return next
|
|
5044
|
+
// }
|
|
5045
|
+
// @ $mol_wire_solo
|
|
5046
|
+
// static res( next?: boolean ) {
|
|
5047
|
+
// return this.left( next ) && this.right()
|
|
5048
|
+
// }
|
|
5049
|
+
// }
|
|
5050
|
+
// $mol_assert_equal( App.res(), false )
|
|
5051
|
+
// $mol_assert_equal( App.res( true ), false )
|
|
5052
|
+
// $mol_assert_equal( App.right( true ), true )
|
|
5053
|
+
// $mol_assert_equal( App.res(), true )
|
|
5054
|
+
// } ,
|
|
5055
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
4781
5056
|
'Different order of pull and push'($) {
|
|
4782
5057
|
class App extends $mol_object2 {
|
|
4783
5058
|
static $ = $;
|
|
@@ -4789,7 +5064,7 @@ var $;
|
|
|
4789
5064
|
}
|
|
4790
5065
|
static slow(next) {
|
|
4791
5066
|
if (next !== undefined)
|
|
4792
|
-
this.slow();
|
|
5067
|
+
this.slow(); // enforce pull before push
|
|
4793
5068
|
return this.store(next);
|
|
4794
5069
|
}
|
|
4795
5070
|
}
|
|
@@ -4808,6 +5083,7 @@ var $;
|
|
|
4808
5083
|
App.store(777);
|
|
4809
5084
|
$mol_assert_equal(App.fast(), App.slow(), 777);
|
|
4810
5085
|
},
|
|
5086
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
4811
5087
|
'Actions inside invariant'($) {
|
|
4812
5088
|
class App extends $mol_object2 {
|
|
4813
5089
|
static $ = $;
|
|
@@ -4847,6 +5123,7 @@ var $;
|
|
|
4847
5123
|
static toggle() {
|
|
4848
5124
|
const prev = this.checked();
|
|
4849
5125
|
$mol_assert_unique(this.checked(!prev), prev);
|
|
5126
|
+
// $mol_assert_equal( this.checked() , prev )
|
|
4850
5127
|
}
|
|
4851
5128
|
static res() {
|
|
4852
5129
|
return this.checked();
|
|
@@ -4871,6 +5148,39 @@ var $;
|
|
|
4871
5148
|
], App, "test", null);
|
|
4872
5149
|
await $mol_wire_async(App).test();
|
|
4873
5150
|
},
|
|
5151
|
+
// // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
5152
|
+
// 'Stable order of multiple root'( $ ) {
|
|
5153
|
+
// class App extends $mol_object2 {
|
|
5154
|
+
// static $ = $
|
|
5155
|
+
// static counter = 0
|
|
5156
|
+
// @ $mol_wire_solo
|
|
5157
|
+
// static left_trigger( next = 0 ) {
|
|
5158
|
+
// return next
|
|
5159
|
+
// }
|
|
5160
|
+
// @ $mol_wire_solo
|
|
5161
|
+
// static left_root() {
|
|
5162
|
+
// this.left_trigger()
|
|
5163
|
+
// return ++ this.counter
|
|
5164
|
+
// }
|
|
5165
|
+
// @ $mol_wire_solo
|
|
5166
|
+
// static right_trigger( next = 0 ) {
|
|
5167
|
+
// return next
|
|
5168
|
+
// }
|
|
5169
|
+
// @ $mol_wire_solo
|
|
5170
|
+
// static right_root() {
|
|
5171
|
+
// this.right_trigger()
|
|
5172
|
+
// return ++ this.counter
|
|
5173
|
+
// }
|
|
5174
|
+
// }
|
|
5175
|
+
// $mol_assert_equal( App.left_root(), 1 )
|
|
5176
|
+
// $mol_assert_equal( App.right_root(), 2 )
|
|
5177
|
+
// App.right_trigger( 1 )
|
|
5178
|
+
// App.left_trigger( 1 )
|
|
5179
|
+
// $mol_wire_fiber.sync()
|
|
5180
|
+
// $mol_assert_equal( App.right_root(), 4 )
|
|
5181
|
+
// $mol_assert_equal( App.left_root(), 3 )
|
|
5182
|
+
// } ,
|
|
5183
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#error-store
|
|
4874
5184
|
'Restore after error'($) {
|
|
4875
5185
|
class App extends $mol_object2 {
|
|
4876
5186
|
static get $() { return $; }
|
|
@@ -4968,6 +5278,7 @@ var $;
|
|
|
4968
5278
|
App.showing(true);
|
|
4969
5279
|
$mol_assert_unique(App.render(), details);
|
|
4970
5280
|
},
|
|
5281
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
4971
5282
|
async 'Hold pubs while wait async task'($) {
|
|
4972
5283
|
class App extends $mol_object2 {
|
|
4973
5284
|
static $ = $;
|
|
@@ -5044,6 +5355,7 @@ var $;
|
|
|
5044
5355
|
"use strict";
|
|
5045
5356
|
var $;
|
|
5046
5357
|
(function ($) {
|
|
5358
|
+
/** Reactive memoizing multiplexed property decorator. */
|
|
5047
5359
|
function $mol_wire_plex(host, field, descr) {
|
|
5048
5360
|
if (!descr)
|
|
5049
5361
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -5197,6 +5509,7 @@ var $;
|
|
|
5197
5509
|
"use strict";
|
|
5198
5510
|
var $;
|
|
5199
5511
|
(function ($) {
|
|
5512
|
+
/** Run code without state changes */
|
|
5200
5513
|
function $mol_wire_probe(task, def) {
|
|
5201
5514
|
const warm = $mol_wire_fiber.warm;
|
|
5202
5515
|
try {
|
|
@@ -5243,7 +5556,25 @@ var $;
|
|
|
5243
5556
|
"use strict";
|
|
5244
5557
|
var $;
|
|
5245
5558
|
(function ($) {
|
|
5559
|
+
/**
|
|
5560
|
+
* Reactive memoizing solo property decorator from [mol_wire](../wire/README.md)
|
|
5561
|
+
* @example
|
|
5562
|
+
* '@' $mol_mem
|
|
5563
|
+
* name(next?: string) {
|
|
5564
|
+
* return next ?? 'default'
|
|
5565
|
+
* }
|
|
5566
|
+
* @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
|
|
5567
|
+
*/
|
|
5246
5568
|
$.$mol_mem = $mol_wire_solo;
|
|
5569
|
+
/**
|
|
5570
|
+
* Reactive memoizing multiplexed property decorator [mol_wire](../wire/README.md)
|
|
5571
|
+
* @example
|
|
5572
|
+
* '@' $mol_mem_key
|
|
5573
|
+
* name(id: number, next?: string) {
|
|
5574
|
+
* return next ?? 'default'
|
|
5575
|
+
* }
|
|
5576
|
+
* @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
|
|
5577
|
+
*/
|
|
5247
5578
|
$.$mol_mem_key = $mol_wire_plex;
|
|
5248
5579
|
})($ || ($ = {}));
|
|
5249
5580
|
|
|
@@ -5251,6 +5582,7 @@ var $;
|
|
|
5251
5582
|
"use strict";
|
|
5252
5583
|
var $;
|
|
5253
5584
|
(function ($) {
|
|
5585
|
+
/** Watch and logs reactive states. Logger automatically added to test bundle which is adding to `test.html`. */
|
|
5254
5586
|
class $mol_wire_log extends $mol_object2 {
|
|
5255
5587
|
static watch(task) {
|
|
5256
5588
|
return task;
|