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/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,10 @@ var $;
|
|
|
987
1099
|
var $;
|
|
988
1100
|
(function ($) {
|
|
989
1101
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
1102
|
+
/**
|
|
1103
|
+
* Deeply compares two values. Returns true if equal.
|
|
1104
|
+
* Define `Symbol.toPrimitive` to customize.
|
|
1105
|
+
*/
|
|
990
1106
|
function $mol_compare_deep(left, right) {
|
|
991
1107
|
if (Object.is(left, right))
|
|
992
1108
|
return true;
|
|
@@ -1126,6 +1242,7 @@ var $;
|
|
|
1126
1242
|
"use strict";
|
|
1127
1243
|
var $;
|
|
1128
1244
|
(function ($) {
|
|
1245
|
+
/** Log begin of collapsed group only when some logged inside, returns func to close group */
|
|
1129
1246
|
function $mol_log3_area_lazy(event) {
|
|
1130
1247
|
const self = this.$;
|
|
1131
1248
|
const stack = self.$mol_log3_stack;
|
|
@@ -1150,6 +1267,7 @@ var $;
|
|
|
1150
1267
|
"use strict";
|
|
1151
1268
|
var $;
|
|
1152
1269
|
(function ($) {
|
|
1270
|
+
/** Position in any resource. */
|
|
1153
1271
|
class $mol_span extends $mol_object2 {
|
|
1154
1272
|
uri;
|
|
1155
1273
|
source;
|
|
@@ -1165,13 +1283,17 @@ var $;
|
|
|
1165
1283
|
this.length = length;
|
|
1166
1284
|
this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
|
|
1167
1285
|
}
|
|
1286
|
+
/** Span for begin of unknown resource */
|
|
1168
1287
|
static unknown = $mol_span.begin('?');
|
|
1288
|
+
/** Makes new span for begin of resource. */
|
|
1169
1289
|
static begin(uri, source = '') {
|
|
1170
1290
|
return new $mol_span(uri, source, 1, 1, 0);
|
|
1171
1291
|
}
|
|
1292
|
+
/** Makes new span for end of resource. */
|
|
1172
1293
|
static end(uri, source) {
|
|
1173
1294
|
return new $mol_span(uri, source, 1, source.length + 1, 0);
|
|
1174
1295
|
}
|
|
1296
|
+
/** Makes new span for entire resource. */
|
|
1175
1297
|
static entire(uri, source) {
|
|
1176
1298
|
return new $mol_span(uri, source, 1, 1, source.length);
|
|
1177
1299
|
}
|
|
@@ -1186,15 +1308,19 @@ var $;
|
|
|
1186
1308
|
length: this.length
|
|
1187
1309
|
};
|
|
1188
1310
|
}
|
|
1311
|
+
/** Makes new error for this span. */
|
|
1189
1312
|
error(message, Class = Error) {
|
|
1190
1313
|
return new Class(`${message} (${this})`);
|
|
1191
1314
|
}
|
|
1315
|
+
/** Makes new span for same uri. */
|
|
1192
1316
|
span(row, col, length) {
|
|
1193
1317
|
return new $mol_span(this.uri, this.source, row, col, length);
|
|
1194
1318
|
}
|
|
1319
|
+
/** Makes new span after end of this. */
|
|
1195
1320
|
after(length = 0) {
|
|
1196
1321
|
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
1197
1322
|
}
|
|
1323
|
+
/** Makes new span between begin and end. */
|
|
1198
1324
|
slice(begin, end = -1) {
|
|
1199
1325
|
let len = this.length;
|
|
1200
1326
|
if (begin < 0)
|
|
@@ -1217,6 +1343,7 @@ var $;
|
|
|
1217
1343
|
"use strict";
|
|
1218
1344
|
var $;
|
|
1219
1345
|
(function ($) {
|
|
1346
|
+
/** Serializes tree to string in tree format. */
|
|
1220
1347
|
function $mol_tree2_to_string(tree) {
|
|
1221
1348
|
let output = [];
|
|
1222
1349
|
function dump(tree, prefix = '') {
|
|
@@ -1260,12 +1387,25 @@ var $;
|
|
|
1260
1387
|
"use strict";
|
|
1261
1388
|
var $;
|
|
1262
1389
|
(function ($) {
|
|
1390
|
+
/**
|
|
1391
|
+
* Abstract Syntax Tree with human readable serialization.
|
|
1392
|
+
* Avoid direct instantiation. Use static factories instead.
|
|
1393
|
+
* @see https://github.com/nin-jin/tree.d
|
|
1394
|
+
*/
|
|
1263
1395
|
class $mol_tree2 extends Object {
|
|
1264
1396
|
type;
|
|
1265
1397
|
value;
|
|
1266
1398
|
kids;
|
|
1267
1399
|
span;
|
|
1268
|
-
constructor(
|
|
1400
|
+
constructor(
|
|
1401
|
+
/** Type of structural node, `value` should be empty */
|
|
1402
|
+
type,
|
|
1403
|
+
/** Content of data node, `type` should be empty */
|
|
1404
|
+
value,
|
|
1405
|
+
/** Child nodes */
|
|
1406
|
+
kids,
|
|
1407
|
+
/** Position in most far source resource */
|
|
1408
|
+
span) {
|
|
1269
1409
|
super();
|
|
1270
1410
|
this.type = type;
|
|
1271
1411
|
this.value = value;
|
|
@@ -1273,12 +1413,15 @@ var $;
|
|
|
1273
1413
|
this.span = span;
|
|
1274
1414
|
this[Symbol.toStringTag] = type || '\\' + value;
|
|
1275
1415
|
}
|
|
1416
|
+
/** Makes collection node. */
|
|
1276
1417
|
static list(kids, span = $mol_span.unknown) {
|
|
1277
1418
|
return new $mol_tree2('', '', kids, span);
|
|
1278
1419
|
}
|
|
1420
|
+
/** Makes new derived collection node. */
|
|
1279
1421
|
list(kids) {
|
|
1280
1422
|
return $mol_tree2.list(kids, this.span);
|
|
1281
1423
|
}
|
|
1424
|
+
/** Makes data node for any string. */
|
|
1282
1425
|
static data(value, kids = [], span = $mol_span.unknown) {
|
|
1283
1426
|
const chunks = value.split('\n');
|
|
1284
1427
|
if (chunks.length > 1) {
|
|
@@ -1292,21 +1435,26 @@ var $;
|
|
|
1292
1435
|
}
|
|
1293
1436
|
return new $mol_tree2('', value, kids, span);
|
|
1294
1437
|
}
|
|
1438
|
+
/** Makes new derived data node. */
|
|
1295
1439
|
data(value, kids = []) {
|
|
1296
1440
|
return $mol_tree2.data(value, kids, this.span);
|
|
1297
1441
|
}
|
|
1442
|
+
/** Makes struct node. */
|
|
1298
1443
|
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
1299
1444
|
if (/[ \n\t\\]/.test(type)) {
|
|
1300
1445
|
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
1301
1446
|
}
|
|
1302
1447
|
return new $mol_tree2(type, '', kids, span);
|
|
1303
1448
|
}
|
|
1449
|
+
/** Makes new derived structural node. */
|
|
1304
1450
|
struct(type, kids = []) {
|
|
1305
1451
|
return $mol_tree2.struct(type, kids, this.span);
|
|
1306
1452
|
}
|
|
1453
|
+
/** Makes new derived node with different kids id defined. */
|
|
1307
1454
|
clone(kids, span = this.span) {
|
|
1308
1455
|
return new $mol_tree2(this.type, this.value, kids, span);
|
|
1309
1456
|
}
|
|
1457
|
+
/** Returns multiline text content. */
|
|
1310
1458
|
text() {
|
|
1311
1459
|
var values = [];
|
|
1312
1460
|
for (var kid of this.kids) {
|
|
@@ -1316,15 +1464,20 @@ var $;
|
|
|
1316
1464
|
}
|
|
1317
1465
|
return this.value + values.join('\n');
|
|
1318
1466
|
}
|
|
1467
|
+
/** Parses tree format. */
|
|
1468
|
+
/** @deprecated Use $mol_tree2_from_string */
|
|
1319
1469
|
static fromString(str, uri = 'unknown') {
|
|
1320
1470
|
return $$.$mol_tree2_from_string(str, uri);
|
|
1321
1471
|
}
|
|
1472
|
+
/** Serializes to tree format. */
|
|
1322
1473
|
toString() {
|
|
1323
1474
|
return $$.$mol_tree2_to_string(this);
|
|
1324
1475
|
}
|
|
1476
|
+
/** Makes new tree with node overrided by path. */
|
|
1325
1477
|
insert(value, ...path) {
|
|
1326
1478
|
return this.update($mol_maybe(value), ...path)[0];
|
|
1327
1479
|
}
|
|
1480
|
+
/** Makes new tree with node overrided by path. */
|
|
1328
1481
|
update(value, ...path) {
|
|
1329
1482
|
if (path.length === 0)
|
|
1330
1483
|
return value;
|
|
@@ -1357,6 +1510,7 @@ var $;
|
|
|
1357
1510
|
return [this.clone(kids)];
|
|
1358
1511
|
}
|
|
1359
1512
|
}
|
|
1513
|
+
/** Query nodes by path. */
|
|
1360
1514
|
select(...path) {
|
|
1361
1515
|
let next = [this];
|
|
1362
1516
|
for (const type of path) {
|
|
@@ -1383,6 +1537,7 @@ var $;
|
|
|
1383
1537
|
}
|
|
1384
1538
|
return this.list(next);
|
|
1385
1539
|
}
|
|
1540
|
+
/** Filter kids by path or value. */
|
|
1386
1541
|
filter(path, value) {
|
|
1387
1542
|
const sub = this.kids.filter(item => {
|
|
1388
1543
|
var found = item.select(...path);
|
|
@@ -1410,9 +1565,11 @@ var $;
|
|
|
1410
1565
|
$mol_fail_hidden(error);
|
|
1411
1566
|
}
|
|
1412
1567
|
}
|
|
1568
|
+
/** Transform tree through context with transformers */
|
|
1413
1569
|
hack(belt, context = {}) {
|
|
1414
1570
|
return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
|
|
1415
1571
|
}
|
|
1572
|
+
/** Makes Error with node coordinates. */
|
|
1416
1573
|
error(message, Class = Error) {
|
|
1417
1574
|
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
1418
1575
|
}
|
|
@@ -1430,6 +1587,7 @@ var $;
|
|
|
1430
1587
|
"use strict";
|
|
1431
1588
|
var $;
|
|
1432
1589
|
(function ($) {
|
|
1590
|
+
/** Syntax error with cordinates and source line snippet. */
|
|
1433
1591
|
class $mol_error_syntax extends SyntaxError {
|
|
1434
1592
|
reason;
|
|
1435
1593
|
line;
|
|
@@ -1448,6 +1606,7 @@ var $;
|
|
|
1448
1606
|
"use strict";
|
|
1449
1607
|
var $;
|
|
1450
1608
|
(function ($) {
|
|
1609
|
+
/** Parses tree format from string. */
|
|
1451
1610
|
function $mol_tree2_from_string(str, uri = '?') {
|
|
1452
1611
|
const span = $mol_span.entire(uri, str);
|
|
1453
1612
|
var root = $mol_tree2.list([], span);
|
|
@@ -1457,6 +1616,7 @@ var $;
|
|
|
1457
1616
|
var indent = 0;
|
|
1458
1617
|
var line_start = pos;
|
|
1459
1618
|
row++;
|
|
1619
|
+
// read indent
|
|
1460
1620
|
while (str.length > pos && str[pos] == '\t') {
|
|
1461
1621
|
indent++;
|
|
1462
1622
|
pos++;
|
|
@@ -1465,8 +1625,10 @@ var $;
|
|
|
1465
1625
|
min_indent = indent;
|
|
1466
1626
|
}
|
|
1467
1627
|
indent -= min_indent;
|
|
1628
|
+
// invalid tab size
|
|
1468
1629
|
if (indent < 0 || indent >= stack.length) {
|
|
1469
1630
|
const sp = span.span(row, 1, pos - line_start);
|
|
1631
|
+
// skip error line
|
|
1470
1632
|
while (str.length > pos && str[pos] != '\n') {
|
|
1471
1633
|
pos++;
|
|
1472
1634
|
}
|
|
@@ -1481,7 +1643,9 @@ var $;
|
|
|
1481
1643
|
}
|
|
1482
1644
|
stack.length = indent + 1;
|
|
1483
1645
|
var parent = stack[indent];
|
|
1646
|
+
// parse types
|
|
1484
1647
|
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
1648
|
+
// type can not contain space and tab
|
|
1485
1649
|
var error_start = pos;
|
|
1486
1650
|
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
1487
1651
|
pos++;
|
|
@@ -1493,6 +1657,7 @@ var $;
|
|
|
1493
1657
|
const sp = span.span(row, error_start - line_start + 1, pos - error_start);
|
|
1494
1658
|
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
1495
1659
|
}
|
|
1660
|
+
// read type
|
|
1496
1661
|
var type_start = pos;
|
|
1497
1662
|
while (str.length > pos &&
|
|
1498
1663
|
str[pos] != '\\' &&
|
|
@@ -1507,10 +1672,12 @@ var $;
|
|
|
1507
1672
|
parent_kids.push(next);
|
|
1508
1673
|
parent = next;
|
|
1509
1674
|
}
|
|
1675
|
+
// read one space if exists
|
|
1510
1676
|
if (str.length > pos && str[pos] == ' ') {
|
|
1511
1677
|
pos++;
|
|
1512
1678
|
}
|
|
1513
1679
|
}
|
|
1680
|
+
// read data
|
|
1514
1681
|
if (str.length > pos && str[pos] == '\\') {
|
|
1515
1682
|
var data_start = pos;
|
|
1516
1683
|
while (str.length > pos && str[pos] != '\n') {
|
|
@@ -1521,6 +1688,7 @@ var $;
|
|
|
1521
1688
|
parent_kids.push(next);
|
|
1522
1689
|
parent = next;
|
|
1523
1690
|
}
|
|
1691
|
+
// now must be end of text
|
|
1524
1692
|
if (str.length === pos && stack.length > 0) {
|
|
1525
1693
|
const sp = span.span(row, pos - line_start + 1, 1);
|
|
1526
1694
|
this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
@@ -1613,6 +1781,7 @@ var $;
|
|
|
1613
1781
|
"use strict";
|
|
1614
1782
|
var $;
|
|
1615
1783
|
(function ($) {
|
|
1784
|
+
/** Module for working with terminal. Text coloring when output in terminal */
|
|
1616
1785
|
class $mol_term_color {
|
|
1617
1786
|
static reset = this.ansi(0, 0);
|
|
1618
1787
|
static bold = this.ansi(1, 22);
|
|
@@ -1684,6 +1853,7 @@ var $;
|
|
|
1684
1853
|
"use strict";
|
|
1685
1854
|
var $;
|
|
1686
1855
|
(function ($) {
|
|
1856
|
+
/** One-shot fiber */
|
|
1687
1857
|
class $mol_wire_task extends $mol_wire_fiber {
|
|
1688
1858
|
static getter(task) {
|
|
1689
1859
|
return function $mol_wire_task_get(host, args) {
|
|
@@ -1709,6 +1879,7 @@ var $;
|
|
|
1709
1879
|
}
|
|
1710
1880
|
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
|
1711
1881
|
const next = new $mol_wire_task(key, task, host, args);
|
|
1882
|
+
// Disabled because non-idempotency is required for try-catch
|
|
1712
1883
|
if (existen?.temp) {
|
|
1713
1884
|
$$.$mol_log3_warn({
|
|
1714
1885
|
place: '$mol_wire_task',
|
|
@@ -1741,7 +1912,7 @@ var $;
|
|
|
1741
1912
|
try {
|
|
1742
1913
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
1743
1914
|
}
|
|
1744
|
-
catch {
|
|
1915
|
+
catch { // Promises throw in strict mode
|
|
1745
1916
|
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
1746
1917
|
}
|
|
1747
1918
|
}
|
|
@@ -1767,6 +1938,7 @@ var $;
|
|
|
1767
1938
|
var $;
|
|
1768
1939
|
(function ($) {
|
|
1769
1940
|
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
1941
|
+
/** Returns string key for any value. */
|
|
1770
1942
|
function $mol_key(value) {
|
|
1771
1943
|
primitives: {
|
|
1772
1944
|
if (typeof value === 'bigint')
|
|
@@ -1774,9 +1946,9 @@ var $;
|
|
|
1774
1946
|
if (typeof value === 'symbol')
|
|
1775
1947
|
return `Symbol(${value.description})`;
|
|
1776
1948
|
if (!value)
|
|
1777
|
-
return JSON.stringify(value);
|
|
1949
|
+
return JSON.stringify(value); // 0, null, ""
|
|
1778
1950
|
if (typeof value !== 'object' && typeof value !== 'function')
|
|
1779
|
-
return JSON.stringify(value);
|
|
1951
|
+
return JSON.stringify(value); // boolean, number, string
|
|
1780
1952
|
}
|
|
1781
1953
|
caching: {
|
|
1782
1954
|
let key = $mol_key_store.get(value);
|
|
@@ -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
|
}
|
|
@@ -2073,6 +2253,7 @@ var $;
|
|
|
2073
2253
|
"use strict";
|
|
2074
2254
|
var $;
|
|
2075
2255
|
(function ($) {
|
|
2256
|
+
/** Run code without state changes */
|
|
2076
2257
|
function $mol_wire_probe(task, def) {
|
|
2077
2258
|
const warm = $mol_wire_fiber.warm;
|
|
2078
2259
|
try {
|
|
@@ -2093,6 +2274,9 @@ var $;
|
|
|
2093
2274
|
"use strict";
|
|
2094
2275
|
var $;
|
|
2095
2276
|
(function ($) {
|
|
2277
|
+
/**
|
|
2278
|
+
* Disable reaping of current subscriber
|
|
2279
|
+
*/
|
|
2096
2280
|
function $mol_wire_solid() {
|
|
2097
2281
|
let current = $mol_wire_auto();
|
|
2098
2282
|
if (current.temp)
|
|
@@ -2111,6 +2295,10 @@ var $;
|
|
|
2111
2295
|
"use strict";
|
|
2112
2296
|
var $;
|
|
2113
2297
|
(function ($) {
|
|
2298
|
+
/**
|
|
2299
|
+
* Real-time refresh current atom.
|
|
2300
|
+
* Don't use if possible. May reduce performance.
|
|
2301
|
+
*/
|
|
2114
2302
|
function $mol_wire_watch() {
|
|
2115
2303
|
const atom = $mol_wire_auto();
|
|
2116
2304
|
if (atom instanceof $mol_wire_atom) {
|
|
@@ -2155,6 +2343,10 @@ var $;
|
|
|
2155
2343
|
props[field] = get_val;
|
|
2156
2344
|
return get_val;
|
|
2157
2345
|
}
|
|
2346
|
+
/**
|
|
2347
|
+
* Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
|
|
2348
|
+
* @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
|
|
2349
|
+
*/
|
|
2158
2350
|
function $mol_wire_sync(obj) {
|
|
2159
2351
|
return new Proxy(obj, {
|
|
2160
2352
|
get(obj, field) {
|
|
@@ -2189,6 +2381,7 @@ var $;
|
|
|
2189
2381
|
"use strict";
|
|
2190
2382
|
var $;
|
|
2191
2383
|
(function ($) {
|
|
2384
|
+
/** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
|
|
2192
2385
|
function $mol_wire_async(obj) {
|
|
2193
2386
|
let fiber;
|
|
2194
2387
|
const temp = $mol_wire_task.getter(obj);
|
|
@@ -2219,6 +2412,7 @@ var $;
|
|
|
2219
2412
|
"use strict";
|
|
2220
2413
|
var $;
|
|
2221
2414
|
(function ($) {
|
|
2415
|
+
/** Starts subtasks concurrently instead of serial. */
|
|
2222
2416
|
function $mol_wire_race(...tasks) {
|
|
2223
2417
|
const results = tasks.map(task => {
|
|
2224
2418
|
try {
|
|
@@ -2243,6 +2437,7 @@ var $;
|
|
|
2243
2437
|
"use strict";
|
|
2244
2438
|
var $;
|
|
2245
2439
|
(function ($) {
|
|
2440
|
+
/** Decorates solo object channel to [mol_wire_atom](../atom/atom.ts). */
|
|
2246
2441
|
function $mol_wire_solo(host, field, descr) {
|
|
2247
2442
|
if (!descr)
|
|
2248
2443
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -2281,6 +2476,7 @@ var $;
|
|
|
2281
2476
|
"use strict";
|
|
2282
2477
|
var $;
|
|
2283
2478
|
(function ($) {
|
|
2479
|
+
/** Reactive memoizing multiplexed property decorator. */
|
|
2284
2480
|
function $mol_wire_plex(host, field, descr) {
|
|
2285
2481
|
if (!descr)
|
|
2286
2482
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -2319,6 +2515,11 @@ var $;
|
|
|
2319
2515
|
"use strict";
|
|
2320
2516
|
var $;
|
|
2321
2517
|
(function ($) {
|
|
2518
|
+
/**
|
|
2519
|
+
* Returns closure that returns constant value.
|
|
2520
|
+
* @example
|
|
2521
|
+
* const rnd = $mol_const( Math.random() )
|
|
2522
|
+
*/
|
|
2322
2523
|
function $mol_const(value) {
|
|
2323
2524
|
const getter = (() => value);
|
|
2324
2525
|
getter['()'] = value;
|
|
@@ -2333,6 +2534,7 @@ var $;
|
|
|
2333
2534
|
"use strict";
|
|
2334
2535
|
var $;
|
|
2335
2536
|
(function ($) {
|
|
2537
|
+
/** Incompatible with instance fields with initializators */
|
|
2336
2538
|
function $mol_wire_field(host, field, descr) {
|
|
2337
2539
|
if (!descr)
|
|
2338
2540
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -2386,7 +2588,25 @@ var $;
|
|
|
2386
2588
|
"use strict";
|
|
2387
2589
|
var $;
|
|
2388
2590
|
(function ($) {
|
|
2591
|
+
/**
|
|
2592
|
+
* Reactive memoizing solo property decorator from [mol_wire](../wire/README.md)
|
|
2593
|
+
* @example
|
|
2594
|
+
* '@' $mol_mem
|
|
2595
|
+
* name(next?: string) {
|
|
2596
|
+
* return next ?? 'default'
|
|
2597
|
+
* }
|
|
2598
|
+
* @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
|
|
2599
|
+
*/
|
|
2389
2600
|
$.$mol_mem = $mol_wire_solo;
|
|
2601
|
+
/**
|
|
2602
|
+
* Reactive memoizing multiplexed property decorator [mol_wire](../wire/README.md)
|
|
2603
|
+
* @example
|
|
2604
|
+
* '@' $mol_mem_key
|
|
2605
|
+
* name(id: number, next?: string) {
|
|
2606
|
+
* return next ?? 'default'
|
|
2607
|
+
* }
|
|
2608
|
+
* @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
|
|
2609
|
+
*/
|
|
2390
2610
|
$.$mol_mem_key = $mol_wire_plex;
|
|
2391
2611
|
})($ || ($ = {}));
|
|
2392
2612
|
|
|
@@ -2394,6 +2614,7 @@ var $;
|
|
|
2394
2614
|
"use strict";
|
|
2395
2615
|
var $;
|
|
2396
2616
|
(function ($) {
|
|
2617
|
+
/** State of time moment */
|
|
2397
2618
|
class $mol_state_time extends $mol_object {
|
|
2398
2619
|
static task(precision, reset) {
|
|
2399
2620
|
if (precision) {
|
|
@@ -2421,6 +2642,7 @@ var $;
|
|
|
2421
2642
|
"use strict";
|
|
2422
2643
|
var $;
|
|
2423
2644
|
(function ($) {
|
|
2645
|
+
/** Transition atom value */
|
|
2424
2646
|
function $mol_wire_easing(next) {
|
|
2425
2647
|
const atom = $mol_wire_auto();
|
|
2426
2648
|
if (!(atom instanceof $mol_wire_atom))
|
|
@@ -2490,8 +2712,10 @@ var $;
|
|
|
2490
2712
|
"use strict";
|
|
2491
2713
|
var $;
|
|
2492
2714
|
(function ($) {
|
|
2715
|
+
/** Reactive Set */
|
|
2493
2716
|
class $mol_wire_set extends Set {
|
|
2494
2717
|
pub = new $mol_wire_pub;
|
|
2718
|
+
// Accessors
|
|
2495
2719
|
has(value) {
|
|
2496
2720
|
this.pub.promote();
|
|
2497
2721
|
return super.has(value);
|
|
@@ -2520,6 +2744,7 @@ var $;
|
|
|
2520
2744
|
this.pub.promote();
|
|
2521
2745
|
return super.size;
|
|
2522
2746
|
}
|
|
2747
|
+
// Mutators
|
|
2523
2748
|
add(value) {
|
|
2524
2749
|
if (super.has(value))
|
|
2525
2750
|
return this;
|
|
@@ -2539,6 +2764,7 @@ var $;
|
|
|
2539
2764
|
super.clear();
|
|
2540
2765
|
this.pub.emit();
|
|
2541
2766
|
}
|
|
2767
|
+
// Extensions
|
|
2542
2768
|
item(val, next) {
|
|
2543
2769
|
if (next === undefined)
|
|
2544
2770
|
return this.has(val);
|
|
@@ -2571,6 +2797,7 @@ var $;
|
|
|
2571
2797
|
if (type !== 'object' && type !== 'function')
|
|
2572
2798
|
return target;
|
|
2573
2799
|
return new Proxy(target, {
|
|
2800
|
+
// Readers
|
|
2574
2801
|
get(target, property) {
|
|
2575
2802
|
$mol_wire_proxy_pub(id, target).promote();
|
|
2576
2803
|
const suffix = '.' + (typeof property === 'symbol' ? property.description : property);
|
|
@@ -2596,6 +2823,7 @@ var $;
|
|
|
2596
2823
|
$mol_wire_proxy_pub(id, target).promote();
|
|
2597
2824
|
return Reflect.isExtensible(target);
|
|
2598
2825
|
},
|
|
2826
|
+
// Writers
|
|
2599
2827
|
set(target, property, next) {
|
|
2600
2828
|
const pub = pubs.get(target);
|
|
2601
2829
|
if (pub) {
|
|
@@ -2631,8 +2859,10 @@ var $;
|
|
|
2631
2859
|
"use strict";
|
|
2632
2860
|
var $;
|
|
2633
2861
|
(function ($) {
|
|
2862
|
+
/** reactive Dictionary */
|
|
2634
2863
|
class $mol_wire_dict extends Map {
|
|
2635
2864
|
pub = new $mol_wire_pub;
|
|
2865
|
+
// Accessors
|
|
2636
2866
|
has(key) {
|
|
2637
2867
|
this.pub.promote();
|
|
2638
2868
|
return super.has(key);
|
|
@@ -2665,11 +2895,12 @@ var $;
|
|
|
2665
2895
|
this.pub.promote();
|
|
2666
2896
|
return super.size;
|
|
2667
2897
|
}
|
|
2898
|
+
// Mutators
|
|
2668
2899
|
set(key, value) {
|
|
2669
2900
|
if (super.get(key) === value)
|
|
2670
2901
|
return this;
|
|
2671
2902
|
super.set(key, value);
|
|
2672
|
-
this.pub?.emit();
|
|
2903
|
+
this.pub?.emit(); // undefined in constructor
|
|
2673
2904
|
return this;
|
|
2674
2905
|
}
|
|
2675
2906
|
delete(key) {
|
|
@@ -2684,6 +2915,7 @@ var $;
|
|
|
2684
2915
|
super.clear();
|
|
2685
2916
|
this.pub.emit();
|
|
2686
2917
|
}
|
|
2918
|
+
// Extensions
|
|
2687
2919
|
item(key, next) {
|
|
2688
2920
|
if (next === undefined)
|
|
2689
2921
|
return this.get(key) ?? null;
|
|
@@ -2741,6 +2973,7 @@ var $;
|
|
|
2741
2973
|
"use strict";
|
|
2742
2974
|
var $;
|
|
2743
2975
|
(function ($) {
|
|
2976
|
+
/** Watch and logs reactive states. Logger automatically added to test bundle which is adding to `test.html`. */
|
|
2744
2977
|
class $mol_wire_log extends $mol_object2 {
|
|
2745
2978
|
static watch(task) {
|
|
2746
2979
|
return task;
|
|
@@ -2913,7 +3146,7 @@ var $;
|
|
|
2913
3146
|
"use strict";
|
|
2914
3147
|
var $;
|
|
2915
3148
|
(function ($) {
|
|
2916
|
-
const mod = require('module');
|
|
3149
|
+
const mod = require /****/('module');
|
|
2917
3150
|
const internals = mod.builtinModules;
|
|
2918
3151
|
function $node_internal_check(name) {
|
|
2919
3152
|
if (name.startsWith('node:'))
|
|
@@ -2927,8 +3160,8 @@ var $;
|
|
|
2927
3160
|
"use strict";
|
|
2928
3161
|
var $;
|
|
2929
3162
|
(function ($) {
|
|
2930
|
-
const path = require('path');
|
|
2931
|
-
const mod = require('module');
|
|
3163
|
+
const path = require /****/('path');
|
|
3164
|
+
const mod = require /****/('module');
|
|
2932
3165
|
const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
|
|
2933
3166
|
function $node_autoinstall(name) {
|
|
2934
3167
|
try {
|
|
@@ -3017,6 +3250,7 @@ var $;
|
|
|
3017
3250
|
])
|
|
3018
3251
|
].map(frame_normalize).join('\n')
|
|
3019
3252
|
});
|
|
3253
|
+
// в nodejs, что б не дублировалось cause в консоли
|
|
3020
3254
|
Object.defineProperty(this, 'cause', {
|
|
3021
3255
|
get: () => cause
|
|
3022
3256
|
});
|
|
@@ -3470,6 +3704,12 @@ var $;
|
|
|
3470
3704
|
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
3471
3705
|
};
|
|
3472
3706
|
$.$mol_jsx_frag = '';
|
|
3707
|
+
/**
|
|
3708
|
+
* JSX adapter that makes DOM tree.
|
|
3709
|
+
* Generates global unique ids for every DOM-element by components tree with ids.
|
|
3710
|
+
* Ensures all local ids are unique.
|
|
3711
|
+
* Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
|
|
3712
|
+
*/
|
|
3473
3713
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
3474
3714
|
const id = props && props.id || '';
|
|
3475
3715
|
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
@@ -3580,6 +3820,8 @@ var $;
|
|
|
3580
3820
|
|
|
3581
3821
|
;
|
|
3582
3822
|
"use strict";
|
|
3823
|
+
/** @jsx $mol_jsx */
|
|
3824
|
+
/** @jsxFrag $mol_jsx_frag */
|
|
3583
3825
|
var $;
|
|
3584
3826
|
(function ($) {
|
|
3585
3827
|
$mol_test({
|
|
@@ -3685,6 +3927,7 @@ var $;
|
|
|
3685
3927
|
"use strict";
|
|
3686
3928
|
var $;
|
|
3687
3929
|
(function ($) {
|
|
3930
|
+
/** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
|
|
3688
3931
|
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
3689
3932
|
const source = typeof item === 'function' ? new $mol_range2_array() : item;
|
|
3690
3933
|
if (typeof item !== 'function') {
|
|
@@ -3733,6 +3976,7 @@ var $;
|
|
|
3733
3976
|
}
|
|
3734
3977
|
$.$mol_range2 = $mol_range2;
|
|
3735
3978
|
class $mol_range2_array extends Array {
|
|
3979
|
+
// Lazy
|
|
3736
3980
|
concat(...tail) {
|
|
3737
3981
|
if (tail.length === 0)
|
|
3738
3982
|
return this;
|
|
@@ -3744,6 +3988,7 @@ var $;
|
|
|
3744
3988
|
}
|
|
3745
3989
|
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
3746
3990
|
}
|
|
3991
|
+
// Lazy
|
|
3747
3992
|
filter(check, context) {
|
|
3748
3993
|
const filtered = [];
|
|
3749
3994
|
let cursor = -1;
|
|
@@ -3756,13 +4001,16 @@ var $;
|
|
|
3756
4001
|
return filtered[index];
|
|
3757
4002
|
}, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
|
|
3758
4003
|
}
|
|
4004
|
+
// Diligent
|
|
3759
4005
|
forEach(proceed, context) {
|
|
3760
4006
|
for (let [key, value] of this.entries())
|
|
3761
4007
|
proceed.call(context, value, key, this);
|
|
3762
4008
|
}
|
|
4009
|
+
// Lazy
|
|
3763
4010
|
map(proceed, context) {
|
|
3764
4011
|
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
3765
4012
|
}
|
|
4013
|
+
// Diligent
|
|
3766
4014
|
reduce(merge, result) {
|
|
3767
4015
|
let index = 0;
|
|
3768
4016
|
if (arguments.length === 1) {
|
|
@@ -3773,12 +4021,15 @@ var $;
|
|
|
3773
4021
|
}
|
|
3774
4022
|
return result;
|
|
3775
4023
|
}
|
|
4024
|
+
// Lazy
|
|
3776
4025
|
toReversed() {
|
|
3777
4026
|
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
3778
4027
|
}
|
|
4028
|
+
// Lazy
|
|
3779
4029
|
slice(from = 0, to = this.length) {
|
|
3780
4030
|
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
3781
4031
|
}
|
|
4032
|
+
// Lazy
|
|
3782
4033
|
some(check, context) {
|
|
3783
4034
|
for (let index = 0; index < this.length; ++index) {
|
|
3784
4035
|
if (check.call(context, this[index], index, this))
|
|
@@ -3971,6 +4222,7 @@ var $;
|
|
|
3971
4222
|
|
|
3972
4223
|
;
|
|
3973
4224
|
"use strict";
|
|
4225
|
+
/** @jsx $mol_jsx */
|
|
3974
4226
|
var $;
|
|
3975
4227
|
(function ($) {
|
|
3976
4228
|
$mol_test({
|
|
@@ -4032,6 +4284,7 @@ var $;
|
|
|
4032
4284
|
const obj3_copy = { test: 3, obj2: obj2_copy };
|
|
4033
4285
|
obj1.obj3 = obj3;
|
|
4034
4286
|
obj1_copy.obj3 = obj3_copy;
|
|
4287
|
+
// warmup cache
|
|
4035
4288
|
$mol_assert_not($mol_compare_deep(obj1, {}));
|
|
4036
4289
|
$mol_assert_not($mol_compare_deep(obj2, {}));
|
|
4037
4290
|
$mol_assert_not($mol_compare_deep(obj3, {}));
|
|
@@ -4101,18 +4354,34 @@ var $;
|
|
|
4101
4354
|
"use strict";
|
|
4102
4355
|
var $;
|
|
4103
4356
|
(function ($) {
|
|
4357
|
+
/**
|
|
4358
|
+
* Argument must be Truthy
|
|
4359
|
+
* @deprecated use $mol_assert_equal instead
|
|
4360
|
+
*/
|
|
4104
4361
|
function $mol_assert_ok(value) {
|
|
4105
4362
|
if (value)
|
|
4106
4363
|
return;
|
|
4107
4364
|
$mol_fail(new Error(`${value} ≠ true`));
|
|
4108
4365
|
}
|
|
4109
4366
|
$.$mol_assert_ok = $mol_assert_ok;
|
|
4367
|
+
/**
|
|
4368
|
+
* Argument must be Falsy
|
|
4369
|
+
* @deprecated use $mol_assert_equal instead
|
|
4370
|
+
*/
|
|
4110
4371
|
function $mol_assert_not(value) {
|
|
4111
4372
|
if (!value)
|
|
4112
4373
|
return;
|
|
4113
4374
|
$mol_fail(new Error(`${value} ≠ false`));
|
|
4114
4375
|
}
|
|
4115
4376
|
$.$mol_assert_not = $mol_assert_not;
|
|
4377
|
+
/**
|
|
4378
|
+
* Handler must throw an error.
|
|
4379
|
+
* @example
|
|
4380
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
|
|
4381
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
|
|
4382
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
|
|
4383
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
4384
|
+
*/
|
|
4116
4385
|
function $mol_assert_fail(handler, ErrorRight) {
|
|
4117
4386
|
const fail = $.$mol_fail;
|
|
4118
4387
|
try {
|
|
@@ -4135,10 +4404,18 @@ var $;
|
|
|
4135
4404
|
$mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
|
|
4136
4405
|
}
|
|
4137
4406
|
$.$mol_assert_fail = $mol_assert_fail;
|
|
4407
|
+
/** @deprecated Use $mol_assert_equal */
|
|
4138
4408
|
function $mol_assert_like(...args) {
|
|
4139
4409
|
$mol_assert_equal(...args);
|
|
4140
4410
|
}
|
|
4141
4411
|
$.$mol_assert_like = $mol_assert_like;
|
|
4412
|
+
/**
|
|
4413
|
+
* All arguments must not be structural equal to each other.
|
|
4414
|
+
* @example
|
|
4415
|
+
* $mol_assert_unique( 1 , 2 , 3 ) // Passes
|
|
4416
|
+
* $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
|
|
4417
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
4418
|
+
*/
|
|
4142
4419
|
function $mol_assert_unique(...args) {
|
|
4143
4420
|
for (let i = 0; i < args.length; ++i) {
|
|
4144
4421
|
for (let j = 0; j < args.length; ++j) {
|
|
@@ -4151,6 +4428,13 @@ var $;
|
|
|
4151
4428
|
}
|
|
4152
4429
|
}
|
|
4153
4430
|
$.$mol_assert_unique = $mol_assert_unique;
|
|
4431
|
+
/**
|
|
4432
|
+
* All arguments must be structural equal each other.
|
|
4433
|
+
* @example
|
|
4434
|
+
* $mol_assert_like( [1] , [1] , [1] ) // Passes
|
|
4435
|
+
* $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
|
|
4436
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
4437
|
+
*/
|
|
4154
4438
|
function $mol_assert_equal(...args) {
|
|
4155
4439
|
for (let i = 1; i < args.length; ++i) {
|
|
4156
4440
|
if ($mol_compare_deep(args[0], args[i]))
|
|
@@ -4538,6 +4822,12 @@ var $;
|
|
|
4538
4822
|
'return result without errors'() {
|
|
4539
4823
|
$mol_assert_equal($mol_try(() => false), false);
|
|
4540
4824
|
},
|
|
4825
|
+
//'return error if thrown'() {
|
|
4826
|
+
//
|
|
4827
|
+
// const error = new Error( '$mol_try test error' )
|
|
4828
|
+
// $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
|
|
4829
|
+
//
|
|
4830
|
+
//} ,
|
|
4541
4831
|
});
|
|
4542
4832
|
})($ || ($ = {}));
|
|
4543
4833
|
|
|
@@ -4610,6 +4900,7 @@ var $;
|
|
|
4610
4900
|
"use strict";
|
|
4611
4901
|
var $;
|
|
4612
4902
|
(function ($) {
|
|
4903
|
+
/// @todo right orderinng
|
|
4613
4904
|
$.$mol_after_mock_queue = [];
|
|
4614
4905
|
function $mol_after_mock_warp() {
|
|
4615
4906
|
const queue = $.$mol_after_mock_queue.splice(0);
|
|
@@ -4737,6 +5028,7 @@ var $;
|
|
|
4737
5028
|
|
|
4738
5029
|
;
|
|
4739
5030
|
"use strict";
|
|
5031
|
+
/** @jsx $mol_jsx */
|
|
4740
5032
|
var $;
|
|
4741
5033
|
(function ($) {
|
|
4742
5034
|
$mol_test({
|
|
@@ -4959,6 +5251,7 @@ var $;
|
|
|
4959
5251
|
var $;
|
|
4960
5252
|
(function ($_1) {
|
|
4961
5253
|
$mol_test({
|
|
5254
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#component-states
|
|
4962
5255
|
'Cached channel'($) {
|
|
4963
5256
|
class App extends $mol_object2 {
|
|
4964
5257
|
static $ = $;
|
|
@@ -5016,6 +5309,7 @@ var $;
|
|
|
5016
5309
|
$mol_assert_equal(App.value(5), 21);
|
|
5017
5310
|
$mol_assert_equal(App.value(), 21);
|
|
5018
5311
|
},
|
|
5312
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-consistency
|
|
5019
5313
|
'Auto recalculation of cached values'($) {
|
|
5020
5314
|
class App extends $mol_object2 {
|
|
5021
5315
|
static $ = $;
|
|
@@ -5043,6 +5337,7 @@ var $;
|
|
|
5043
5337
|
App.xxx(5);
|
|
5044
5338
|
$mol_assert_equal(App.zzz(), 7);
|
|
5045
5339
|
},
|
|
5340
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-reasonability
|
|
5046
5341
|
'Skip recalculation when actually no dependency changes'($) {
|
|
5047
5342
|
const log = [];
|
|
5048
5343
|
class App extends $mol_object2 {
|
|
@@ -5076,6 +5371,7 @@ var $;
|
|
|
5076
5371
|
App.zzz();
|
|
5077
5372
|
$mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
|
|
5078
5373
|
},
|
|
5374
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#flow-auto
|
|
5079
5375
|
'Flow: Auto'($) {
|
|
5080
5376
|
class App extends $mol_object2 {
|
|
5081
5377
|
static get $() { return $; }
|
|
@@ -5113,6 +5409,7 @@ var $;
|
|
|
5113
5409
|
$mol_assert_equal(App.result(), 23);
|
|
5114
5410
|
$mol_assert_equal(App.counter, 4);
|
|
5115
5411
|
},
|
|
5412
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#dupes-equality
|
|
5116
5413
|
'Dupes: Equality'($) {
|
|
5117
5414
|
let counter = 0;
|
|
5118
5415
|
class App extends $mol_object2 {
|
|
@@ -5136,6 +5433,7 @@ var $;
|
|
|
5136
5433
|
App.foo({ numbs: [2] });
|
|
5137
5434
|
$mol_assert_like(App.bar(), { numbs: [2], count: 2 });
|
|
5138
5435
|
},
|
|
5436
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#cycle-fail
|
|
5139
5437
|
'Cycle: Fail'($) {
|
|
5140
5438
|
class App extends $mol_object2 {
|
|
5141
5439
|
static $ = $;
|
|
@@ -5160,6 +5458,29 @@ var $;
|
|
|
5160
5458
|
], App, "test", null);
|
|
5161
5459
|
App.test();
|
|
5162
5460
|
},
|
|
5461
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
5462
|
+
// 'Update deps on push'( $ ) {
|
|
5463
|
+
// class App extends $mol_object2 {
|
|
5464
|
+
// static $ = $
|
|
5465
|
+
// @ $mol_wire_solo
|
|
5466
|
+
// static left( next = false ) {
|
|
5467
|
+
// return next
|
|
5468
|
+
// }
|
|
5469
|
+
// @ $mol_wire_solo
|
|
5470
|
+
// static right( next = false ) {
|
|
5471
|
+
// return next
|
|
5472
|
+
// }
|
|
5473
|
+
// @ $mol_wire_solo
|
|
5474
|
+
// static res( next?: boolean ) {
|
|
5475
|
+
// return this.left( next ) && this.right()
|
|
5476
|
+
// }
|
|
5477
|
+
// }
|
|
5478
|
+
// $mol_assert_equal( App.res(), false )
|
|
5479
|
+
// $mol_assert_equal( App.res( true ), false )
|
|
5480
|
+
// $mol_assert_equal( App.right( true ), true )
|
|
5481
|
+
// $mol_assert_equal( App.res(), true )
|
|
5482
|
+
// } ,
|
|
5483
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
5163
5484
|
'Different order of pull and push'($) {
|
|
5164
5485
|
class App extends $mol_object2 {
|
|
5165
5486
|
static $ = $;
|
|
@@ -5171,7 +5492,7 @@ var $;
|
|
|
5171
5492
|
}
|
|
5172
5493
|
static slow(next) {
|
|
5173
5494
|
if (next !== undefined)
|
|
5174
|
-
this.slow();
|
|
5495
|
+
this.slow(); // enforce pull before push
|
|
5175
5496
|
return this.store(next);
|
|
5176
5497
|
}
|
|
5177
5498
|
}
|
|
@@ -5190,6 +5511,7 @@ var $;
|
|
|
5190
5511
|
App.store(777);
|
|
5191
5512
|
$mol_assert_equal(App.fast(), App.slow(), 777);
|
|
5192
5513
|
},
|
|
5514
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
5193
5515
|
'Actions inside invariant'($) {
|
|
5194
5516
|
class App extends $mol_object2 {
|
|
5195
5517
|
static $ = $;
|
|
@@ -5229,6 +5551,7 @@ var $;
|
|
|
5229
5551
|
static toggle() {
|
|
5230
5552
|
const prev = this.checked();
|
|
5231
5553
|
$mol_assert_unique(this.checked(!prev), prev);
|
|
5554
|
+
// $mol_assert_equal( this.checked() , prev )
|
|
5232
5555
|
}
|
|
5233
5556
|
static res() {
|
|
5234
5557
|
return this.checked();
|
|
@@ -5253,6 +5576,39 @@ var $;
|
|
|
5253
5576
|
], App, "test", null);
|
|
5254
5577
|
await $mol_wire_async(App).test();
|
|
5255
5578
|
},
|
|
5579
|
+
// // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
5580
|
+
// 'Stable order of multiple root'( $ ) {
|
|
5581
|
+
// class App extends $mol_object2 {
|
|
5582
|
+
// static $ = $
|
|
5583
|
+
// static counter = 0
|
|
5584
|
+
// @ $mol_wire_solo
|
|
5585
|
+
// static left_trigger( next = 0 ) {
|
|
5586
|
+
// return next
|
|
5587
|
+
// }
|
|
5588
|
+
// @ $mol_wire_solo
|
|
5589
|
+
// static left_root() {
|
|
5590
|
+
// this.left_trigger()
|
|
5591
|
+
// return ++ this.counter
|
|
5592
|
+
// }
|
|
5593
|
+
// @ $mol_wire_solo
|
|
5594
|
+
// static right_trigger( next = 0 ) {
|
|
5595
|
+
// return next
|
|
5596
|
+
// }
|
|
5597
|
+
// @ $mol_wire_solo
|
|
5598
|
+
// static right_root() {
|
|
5599
|
+
// this.right_trigger()
|
|
5600
|
+
// return ++ this.counter
|
|
5601
|
+
// }
|
|
5602
|
+
// }
|
|
5603
|
+
// $mol_assert_equal( App.left_root(), 1 )
|
|
5604
|
+
// $mol_assert_equal( App.right_root(), 2 )
|
|
5605
|
+
// App.right_trigger( 1 )
|
|
5606
|
+
// App.left_trigger( 1 )
|
|
5607
|
+
// $mol_wire_fiber.sync()
|
|
5608
|
+
// $mol_assert_equal( App.right_root(), 4 )
|
|
5609
|
+
// $mol_assert_equal( App.left_root(), 3 )
|
|
5610
|
+
// } ,
|
|
5611
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#error-store
|
|
5256
5612
|
'Restore after error'($) {
|
|
5257
5613
|
class App extends $mol_object2 {
|
|
5258
5614
|
static get $() { return $; }
|
|
@@ -5350,6 +5706,7 @@ var $;
|
|
|
5350
5706
|
App.showing(true);
|
|
5351
5707
|
$mol_assert_unique(App.render(), details);
|
|
5352
5708
|
},
|
|
5709
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
5353
5710
|
async 'Hold pubs while wait async task'($) {
|
|
5354
5711
|
class App extends $mol_object2 {
|
|
5355
5712
|
static $ = $;
|