mol_wire_lib 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web.test.js ADDED
@@ -0,0 +1,1649 @@
1
+ "use strict";
2
+ function require( path ){ return $node[ path ] };
3
+ "use strict";
4
+ var $;
5
+ (function ($_1) {
6
+ function $mol_test(set) {
7
+ for (let name in set) {
8
+ const code = set[name];
9
+ const test = (typeof code === 'string') ? new Function('', code) : code;
10
+ $_1.$mol_test_all.push(test);
11
+ }
12
+ $mol_test_schedule();
13
+ }
14
+ $_1.$mol_test = $mol_test;
15
+ $_1.$mol_test_mocks = [];
16
+ $_1.$mol_test_all = [];
17
+ async function $mol_test_run() {
18
+ for (var test of $_1.$mol_test_all) {
19
+ let context = Object.create($$);
20
+ for (let mock of $_1.$mol_test_mocks)
21
+ await mock(context);
22
+ const res = test(context);
23
+ if (res instanceof Promise) {
24
+ await new Promise((done, fail) => {
25
+ res.then(done, fail);
26
+ setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
27
+ });
28
+ }
29
+ }
30
+ $$.$mol_log3_done({
31
+ place: '$mol_test',
32
+ message: 'All tests passed',
33
+ count: $_1.$mol_test_all.length,
34
+ });
35
+ }
36
+ $_1.$mol_test_run = $mol_test_run;
37
+ let scheduled = false;
38
+ function $mol_test_schedule() {
39
+ if (scheduled)
40
+ return;
41
+ scheduled = true;
42
+ setTimeout(async () => {
43
+ scheduled = false;
44
+ try {
45
+ await $mol_test_run();
46
+ }
47
+ finally {
48
+ $$.$mol_test_complete();
49
+ }
50
+ }, 0);
51
+ }
52
+ $_1.$mol_test_schedule = $mol_test_schedule;
53
+ $_1.$mol_test_mocks.push(context => {
54
+ let seed = 0;
55
+ context.Math = Object.create(Math);
56
+ context.Math.random = () => Math.sin(seed++);
57
+ const forbidden = ['XMLHttpRequest', 'fetch'];
58
+ for (let api of forbidden) {
59
+ context[api] = new Proxy(function () { }, {
60
+ get() {
61
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
62
+ },
63
+ apply() {
64
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
65
+ },
66
+ });
67
+ }
68
+ });
69
+ $mol_test({
70
+ 'mocked Math.random'($) {
71
+ console.assert($.Math.random() === 0);
72
+ console.assert($.Math.random() === Math.sin(1));
73
+ },
74
+ 'forbidden XMLHttpRequest'($) {
75
+ try {
76
+ console.assert(void new $.XMLHttpRequest);
77
+ }
78
+ catch (error) {
79
+ console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
80
+ }
81
+ },
82
+ 'forbidden fetch'($) {
83
+ try {
84
+ console.assert(void $.fetch(''));
85
+ }
86
+ catch (error) {
87
+ console.assert(error.message === 'fetch is forbidden in tests');
88
+ }
89
+ },
90
+ });
91
+ })($ || ($ = {}));
92
+ //mol/test/test.test.ts
93
+ ;
94
+ "use strict";
95
+ var $;
96
+ (function ($) {
97
+ function $mol_test_complete() {
98
+ }
99
+ $.$mol_test_complete = $mol_test_complete;
100
+ })($ || ($ = {}));
101
+ //mol/test/test.web.test.ts
102
+ ;
103
+ "use strict";
104
+ var $;
105
+ (function ($) {
106
+ })($ || ($ = {}));
107
+ //mol/dom/context/context.ts
108
+ ;
109
+ "use strict";
110
+ var $;
111
+ (function ($) {
112
+ $.$mol_dom_context = self;
113
+ })($ || ($ = {}));
114
+ //mol/dom/context/context.web.ts
115
+ ;
116
+ "use strict";
117
+ var $;
118
+ (function ($) {
119
+ function $mol_dom_render_children(el, childNodes) {
120
+ const node_set = new Set(childNodes);
121
+ let nextNode = el.firstChild;
122
+ for (let view of childNodes) {
123
+ if (view == null)
124
+ continue;
125
+ if (view instanceof $mol_dom_context.Node) {
126
+ while (true) {
127
+ if (!nextNode) {
128
+ el.appendChild(view);
129
+ break;
130
+ }
131
+ if (nextNode == view) {
132
+ nextNode = nextNode.nextSibling;
133
+ break;
134
+ }
135
+ else {
136
+ if (node_set.has(nextNode)) {
137
+ el.insertBefore(view, nextNode);
138
+ break;
139
+ }
140
+ else {
141
+ const nn = nextNode.nextSibling;
142
+ el.removeChild(nextNode);
143
+ nextNode = nn;
144
+ }
145
+ }
146
+ }
147
+ }
148
+ else {
149
+ if (nextNode && nextNode.nodeName === '#text') {
150
+ const str = String(view);
151
+ if (nextNode.nodeValue !== str)
152
+ nextNode.nodeValue = str;
153
+ nextNode = nextNode.nextSibling;
154
+ }
155
+ else {
156
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
157
+ el.insertBefore(textNode, nextNode);
158
+ }
159
+ }
160
+ }
161
+ while (nextNode) {
162
+ const currNode = nextNode;
163
+ nextNode = currNode.nextSibling;
164
+ el.removeChild(currNode);
165
+ }
166
+ }
167
+ $.$mol_dom_render_children = $mol_dom_render_children;
168
+ })($ || ($ = {}));
169
+ //mol/dom/render/children/children.ts
170
+ ;
171
+ "use strict";
172
+ //mol/type/error/error.ts
173
+ ;
174
+ "use strict";
175
+ //mol/type/assert/assert.test.ts
176
+ ;
177
+ "use strict";
178
+ //mol/type/assert/assert.ts
179
+ ;
180
+ "use strict";
181
+ //mol/type/partial/deep/deep.test.ts
182
+ ;
183
+ "use strict";
184
+ //mol/type/partial/deep/deep.ts
185
+ ;
186
+ "use strict";
187
+ var $;
188
+ (function ($) {
189
+ $mol_test({
190
+ 'Make empty div'() {
191
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
192
+ },
193
+ 'Define native field'() {
194
+ const dom = $mol_jsx("input", { value: '123' });
195
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
196
+ $mol_assert_equal(dom.value, '123');
197
+ },
198
+ 'Define classes'() {
199
+ const dom = $mol_jsx("div", { class: 'foo bar' });
200
+ $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
201
+ },
202
+ 'Define styles'() {
203
+ const dom = $mol_jsx("div", { style: { color: 'red' } });
204
+ $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
205
+ },
206
+ 'Define dataset'() {
207
+ const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
208
+ $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
209
+ },
210
+ 'Define attributes'() {
211
+ const dom = $mol_jsx("div", { lang: "ru", hidden: true });
212
+ $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
213
+ },
214
+ 'Define child nodes'() {
215
+ const dom = $mol_jsx("div", null,
216
+ "hello",
217
+ $mol_jsx("strong", null, "world"),
218
+ "!");
219
+ $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
220
+ },
221
+ 'Function as component'() {
222
+ const Button = ({ hint }, target) => {
223
+ return $mol_jsx("button", { title: hint }, target());
224
+ };
225
+ const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
226
+ $mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
227
+ },
228
+ 'Nested guid generation'() {
229
+ const Foo = () => {
230
+ return $mol_jsx("div", null,
231
+ $mol_jsx(Bar, { id: "/bar" },
232
+ $mol_jsx("img", { id: "/icon" })));
233
+ };
234
+ const Bar = (props, icon) => {
235
+ return $mol_jsx("span", null, icon);
236
+ };
237
+ const dom = $mol_jsx(Foo, { id: "/foo" });
238
+ $mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
239
+ },
240
+ 'Fail on non unique ids'() {
241
+ const App = () => {
242
+ return $mol_jsx("div", null,
243
+ $mol_jsx("span", { id: "/bar" }),
244
+ $mol_jsx("span", { id: "/bar" }));
245
+ };
246
+ $mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
247
+ },
248
+ });
249
+ })($ || ($ = {}));
250
+ //mol/jsx/jsx.test.tsx
251
+ ;
252
+ "use strict";
253
+ var $;
254
+ (function ($) {
255
+ $.$mol_jsx_prefix = '';
256
+ $.$mol_jsx_booked = null;
257
+ $.$mol_jsx_document = {
258
+ getElementById: () => null,
259
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
260
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
261
+ };
262
+ $.$mol_jsx_frag = '';
263
+ function $mol_jsx(Elem, props, ...childNodes) {
264
+ const id = props && props.id || '';
265
+ if (Elem && $.$mol_jsx_booked) {
266
+ if ($.$mol_jsx_booked.has(id)) {
267
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
268
+ }
269
+ else {
270
+ $.$mol_jsx_booked.add(id);
271
+ }
272
+ }
273
+ const guid = $.$mol_jsx_prefix + id;
274
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
275
+ if (typeof Elem !== 'string') {
276
+ if ('prototype' in Elem) {
277
+ const view = node && node[Elem] || new Elem;
278
+ Object.assign(view, props);
279
+ view[Symbol.toStringTag] = guid;
280
+ view.childNodes = childNodes;
281
+ if (!view.ownerDocument)
282
+ view.ownerDocument = $.$mol_jsx_document;
283
+ node = view.valueOf();
284
+ node[Elem] = view;
285
+ return node;
286
+ }
287
+ else {
288
+ const prefix = $.$mol_jsx_prefix;
289
+ const booked = $.$mol_jsx_booked;
290
+ try {
291
+ $.$mol_jsx_prefix = guid;
292
+ $.$mol_jsx_booked = new Set;
293
+ return Elem(props, ...childNodes);
294
+ }
295
+ finally {
296
+ $.$mol_jsx_prefix = prefix;
297
+ $.$mol_jsx_booked = booked;
298
+ }
299
+ }
300
+ }
301
+ if (!node) {
302
+ node = Elem
303
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
304
+ : $.$mol_jsx_document.createDocumentFragment();
305
+ }
306
+ $mol_dom_render_children(node, [].concat(...childNodes));
307
+ if (!Elem)
308
+ return node;
309
+ for (const key in props) {
310
+ if (typeof props[key] === 'string') {
311
+ ;
312
+ node.setAttribute(key, props[key]);
313
+ }
314
+ else if (props[key] &&
315
+ typeof props[key] === 'object' &&
316
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
317
+ if (typeof node[key] === 'object') {
318
+ Object.assign(node[key], props[key]);
319
+ continue;
320
+ }
321
+ }
322
+ else {
323
+ node[key] = props[key];
324
+ }
325
+ }
326
+ if (guid)
327
+ node.id = guid;
328
+ return node;
329
+ }
330
+ $.$mol_jsx = $mol_jsx;
331
+ })($ || ($ = {}));
332
+ //mol/jsx/jsx.ts
333
+ ;
334
+ "use strict";
335
+ var $;
336
+ (function ($) {
337
+ $mol_test({
338
+ 'nulls & undefineds'() {
339
+ $mol_assert_ok($mol_compare_deep(null, null));
340
+ $mol_assert_ok($mol_compare_deep(undefined, undefined));
341
+ $mol_assert_not($mol_compare_deep(undefined, null));
342
+ $mol_assert_not($mol_compare_deep({}, null));
343
+ },
344
+ 'number'() {
345
+ $mol_assert_ok($mol_compare_deep(1, 1));
346
+ $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
347
+ $mol_assert_not($mol_compare_deep(1, 2));
348
+ $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
349
+ $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
350
+ },
351
+ 'POJO'() {
352
+ $mol_assert_ok($mol_compare_deep({}, {}));
353
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
354
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
355
+ $mol_assert_not($mol_compare_deep({}, { a: undefined }));
356
+ $mol_assert_ok($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
357
+ $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
358
+ },
359
+ 'Array'() {
360
+ $mol_assert_ok($mol_compare_deep([], []));
361
+ $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
362
+ $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
363
+ $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
364
+ },
365
+ 'Non POJO are different'() {
366
+ class Thing extends Object {
367
+ }
368
+ $mol_assert_not($mol_compare_deep(new Thing, new Thing));
369
+ $mol_assert_not($mol_compare_deep(() => 1, () => 1));
370
+ $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
371
+ },
372
+ 'same POJOs with cyclic reference'() {
373
+ const a = { foo: {} };
374
+ a['self'] = a;
375
+ const b = { foo: {} };
376
+ b['self'] = b;
377
+ $mol_assert_ok($mol_compare_deep(a, b));
378
+ },
379
+ 'Date'() {
380
+ $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
381
+ $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
382
+ },
383
+ 'RegExp'() {
384
+ $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
385
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
386
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
387
+ },
388
+ 'Map'() {
389
+ $mol_assert_ok($mol_compare_deep(new Map, new Map));
390
+ $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
391
+ $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
392
+ $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
393
+ },
394
+ 'Set'() {
395
+ $mol_assert_ok($mol_compare_deep(new Set, new Set));
396
+ $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
397
+ $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
398
+ },
399
+ 'Uint8Array'() {
400
+ $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
401
+ $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
402
+ $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
403
+ },
404
+ 'Custom comparator'() {
405
+ class User {
406
+ name;
407
+ rand;
408
+ constructor(name, rand = Math.random()) {
409
+ this.name = name;
410
+ this.rand = rand;
411
+ }
412
+ [Symbol.toPrimitive](mode) {
413
+ return this.name;
414
+ }
415
+ }
416
+ $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
417
+ $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
418
+ },
419
+ });
420
+ })($ || ($ = {}));
421
+ //mol/compare/deep/deep.test.tsx
422
+ ;
423
+ "use strict";
424
+ var $;
425
+ (function ($) {
426
+ function $mol_dom_serialize(node) {
427
+ const serializer = new $mol_dom_context.XMLSerializer;
428
+ return serializer.serializeToString(node);
429
+ }
430
+ $.$mol_dom_serialize = $mol_dom_serialize;
431
+ })($ || ($ = {}));
432
+ //mol/dom/serialize/serialize.ts
433
+ ;
434
+ "use strict";
435
+ var $;
436
+ (function ($) {
437
+ $mol_test({
438
+ 'must be false'() {
439
+ $mol_assert_not(0);
440
+ },
441
+ 'must be true'() {
442
+ $mol_assert_ok(1);
443
+ },
444
+ 'two must be equal'() {
445
+ $mol_assert_equal(2, 2);
446
+ },
447
+ 'three must be equal'() {
448
+ $mol_assert_equal(2, 2, 2);
449
+ },
450
+ 'two must be unique'() {
451
+ $mol_assert_unique([3], [3]);
452
+ },
453
+ 'three must be unique'() {
454
+ $mol_assert_unique([3], [3], [3]);
455
+ },
456
+ 'two must be alike'() {
457
+ $mol_assert_like([3], [3]);
458
+ },
459
+ 'three must be alike'() {
460
+ $mol_assert_like([3], [3], [3]);
461
+ },
462
+ });
463
+ })($ || ($ = {}));
464
+ //mol/assert/assert.test.ts
465
+ ;
466
+ "use strict";
467
+ var $;
468
+ (function ($) {
469
+ function $mol_assert_ok(value) {
470
+ if (value)
471
+ return;
472
+ $mol_fail(new Error(`${value} ≠ true`));
473
+ }
474
+ $.$mol_assert_ok = $mol_assert_ok;
475
+ function $mol_assert_not(value) {
476
+ if (!value)
477
+ return;
478
+ $mol_fail(new Error(`${value} ≠ false`));
479
+ }
480
+ $.$mol_assert_not = $mol_assert_not;
481
+ function $mol_assert_fail(handler, ErrorRight) {
482
+ const fail = $.$mol_fail;
483
+ try {
484
+ $.$mol_fail = $.$mol_fail_hidden;
485
+ handler();
486
+ }
487
+ catch (error) {
488
+ if (!ErrorRight)
489
+ return error;
490
+ $.$mol_fail = fail;
491
+ if (typeof ErrorRight === 'string') {
492
+ $mol_assert_equal(error.message, ErrorRight);
493
+ }
494
+ else {
495
+ $mol_assert_ok(error instanceof ErrorRight);
496
+ }
497
+ return error;
498
+ }
499
+ finally {
500
+ $.$mol_fail = fail;
501
+ }
502
+ $mol_fail(new Error('Not failed'));
503
+ }
504
+ $.$mol_assert_fail = $mol_assert_fail;
505
+ function $mol_assert_equal(...args) {
506
+ for (let i = 0; i < args.length; ++i) {
507
+ for (let j = 0; j < args.length; ++j) {
508
+ if (i === j)
509
+ continue;
510
+ if (Number.isNaN(args[i]) && Number.isNaN(args[j]))
511
+ continue;
512
+ if (args[i] !== args[j])
513
+ $mol_fail(new Error(`Not equal (${i + 1}:${j + 1})\n${args[i]}\n${args[j]}`));
514
+ }
515
+ }
516
+ }
517
+ $.$mol_assert_equal = $mol_assert_equal;
518
+ function $mol_assert_unique(...args) {
519
+ for (let i = 0; i < args.length; ++i) {
520
+ for (let j = 0; j < args.length; ++j) {
521
+ if (i === j)
522
+ continue;
523
+ if (args[i] === args[j] || (Number.isNaN(args[i]) && Number.isNaN(args[j]))) {
524
+ $mol_fail(new Error(`args[${i}] = args[${j}] = ${args[i]}`));
525
+ }
526
+ }
527
+ }
528
+ }
529
+ $.$mol_assert_unique = $mol_assert_unique;
530
+ function $mol_assert_like(head, ...tail) {
531
+ for (let [index, value] of Object.entries(tail)) {
532
+ if (!$mol_compare_deep(value, head)) {
533
+ const print = (val) => {
534
+ if (!val)
535
+ return val;
536
+ if (typeof val !== 'object')
537
+ return val;
538
+ if ('outerHTML' in val)
539
+ return val.outerHTML;
540
+ try {
541
+ return JSON.stringify(val);
542
+ }
543
+ catch (error) {
544
+ console.error(error);
545
+ return val;
546
+ }
547
+ };
548
+ return $mol_fail(new Error(`Not like (1:${+index + 2})\n${print(head)}\n---\n${print(value)}`));
549
+ }
550
+ }
551
+ }
552
+ $.$mol_assert_like = $mol_assert_like;
553
+ function $mol_assert_dom(left, right) {
554
+ $mol_assert_equal($mol_dom_serialize(left), $mol_dom_serialize(right));
555
+ }
556
+ $.$mol_assert_dom = $mol_assert_dom;
557
+ })($ || ($ = {}));
558
+ //mol/assert/assert.ts
559
+ ;
560
+ "use strict";
561
+ var $;
562
+ (function ($_1) {
563
+ $mol_test({
564
+ 'Collect deps'() {
565
+ const pub1 = new $mol_wire_pub;
566
+ const pub2 = new $mol_wire_pub;
567
+ const sub = new $mol_wire_pub_sub;
568
+ const bu1 = sub.track_on();
569
+ try {
570
+ pub1.track_promote();
571
+ pub2.track_promote();
572
+ pub2.track_promote();
573
+ }
574
+ finally {
575
+ sub.track_off(bu1);
576
+ }
577
+ pub1.emit();
578
+ pub2.emit();
579
+ $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
580
+ const bu2 = sub.track_on();
581
+ try {
582
+ pub1.track_promote();
583
+ pub1.track_promote();
584
+ pub2.track_promote();
585
+ }
586
+ finally {
587
+ sub.track_off(bu2);
588
+ }
589
+ pub1.emit();
590
+ pub2.emit();
591
+ $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
592
+ },
593
+ 'cyclic detection'($) {
594
+ const sub1 = new $mol_wire_pub_sub;
595
+ const sub2 = new $mol_wire_pub_sub;
596
+ const bu1 = sub1.track_on();
597
+ try {
598
+ const bu2 = sub2.track_on();
599
+ try {
600
+ $mol_assert_fail(() => sub1.track_promote(), 'Circular subscription');
601
+ }
602
+ finally {
603
+ sub2.track_off(bu2);
604
+ }
605
+ }
606
+ finally {
607
+ sub1.track_off(bu1);
608
+ }
609
+ },
610
+ });
611
+ })($ || ($ = {}));
612
+ //mol/wire/pub/sub/sub.test.ts
613
+ ;
614
+ "use strict";
615
+ var $;
616
+ (function ($) {
617
+ $mol_test({
618
+ 'get'() {
619
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
620
+ $mol_assert_equal(proxy.foo, 777);
621
+ },
622
+ 'has'() {
623
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
624
+ $mol_assert_equal('foo' in proxy, true);
625
+ },
626
+ 'set'() {
627
+ const target = { foo: 777 };
628
+ const proxy = $mol_delegate({}, () => target);
629
+ proxy.foo = 123;
630
+ $mol_assert_equal(target.foo, 123);
631
+ },
632
+ 'getOwnPropertyDescriptor'() {
633
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
634
+ $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
635
+ value: 777,
636
+ writable: true,
637
+ enumerable: true,
638
+ configurable: true,
639
+ });
640
+ },
641
+ 'ownKeys'() {
642
+ const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
643
+ $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
644
+ },
645
+ 'getPrototypeOf'() {
646
+ class Foo {
647
+ }
648
+ const proxy = $mol_delegate({}, () => new Foo);
649
+ $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
650
+ },
651
+ 'setPrototypeOf'() {
652
+ class Foo {
653
+ }
654
+ const target = {};
655
+ const proxy = $mol_delegate({}, () => target);
656
+ Object.setPrototypeOf(proxy, Foo.prototype);
657
+ $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
658
+ },
659
+ 'instanceof'() {
660
+ class Foo {
661
+ }
662
+ const proxy = $mol_delegate({}, () => new Foo);
663
+ $mol_assert_ok(proxy instanceof Foo);
664
+ $mol_assert_ok(proxy instanceof $mol_delegate);
665
+ },
666
+ 'autobind'() {
667
+ class Foo {
668
+ }
669
+ const proxy = $mol_delegate({}, () => new Foo);
670
+ $mol_assert_ok(proxy instanceof Foo);
671
+ $mol_assert_ok(proxy instanceof $mol_delegate);
672
+ },
673
+ });
674
+ })($ || ($ = {}));
675
+ //mol/delegate/delegate.test.ts
676
+ ;
677
+ "use strict";
678
+ //mol/type/writable/writable.test.ts
679
+ ;
680
+ "use strict";
681
+ var $;
682
+ (function ($) {
683
+ function $mol_promise() {
684
+ let done;
685
+ let fail;
686
+ const promise = new Promise((d, f) => {
687
+ done = d;
688
+ fail = f;
689
+ });
690
+ return Object.assign(promise, {
691
+ done,
692
+ fail,
693
+ });
694
+ }
695
+ $.$mol_promise = $mol_promise;
696
+ })($ || ($ = {}));
697
+ //mol/promise/promise.ts
698
+ ;
699
+ "use strict";
700
+ var $;
701
+ (function ($) {
702
+ $.$mol_after_mock_queue = [];
703
+ function $mol_after_mock_warp() {
704
+ const queue = $.$mol_after_mock_queue.splice(0);
705
+ for (const task of queue)
706
+ task();
707
+ }
708
+ $.$mol_after_mock_warp = $mol_after_mock_warp;
709
+ class $mol_after_mock_commmon extends $mol_object2 {
710
+ task;
711
+ promise = Promise.resolve();
712
+ cancelled = false;
713
+ id;
714
+ constructor(task) {
715
+ super();
716
+ this.task = task;
717
+ $.$mol_after_mock_queue.push(task);
718
+ }
719
+ destructor() {
720
+ const index = $.$mol_after_mock_queue.indexOf(this.task);
721
+ if (index >= 0)
722
+ $.$mol_after_mock_queue.splice(index, 1);
723
+ }
724
+ }
725
+ $.$mol_after_mock_commmon = $mol_after_mock_commmon;
726
+ class $mol_after_mock_timeout extends $mol_after_mock_commmon {
727
+ delay;
728
+ constructor(delay, task) {
729
+ super(task);
730
+ this.delay = delay;
731
+ }
732
+ }
733
+ $.$mol_after_mock_timeout = $mol_after_mock_timeout;
734
+ })($ || ($ = {}));
735
+ //mol/after/mock/mock.test.ts
736
+ ;
737
+ "use strict";
738
+ var $;
739
+ (function ($_1) {
740
+ $mol_test_mocks.push($ => {
741
+ $.$mol_after_timeout = $mol_after_mock_timeout;
742
+ });
743
+ })($ || ($ = {}));
744
+ //mol/after/timeout/timeout.test.ts
745
+ ;
746
+ "use strict";
747
+ var $;
748
+ (function ($) {
749
+ class $mol_after_timeout extends $mol_object2 {
750
+ delay;
751
+ task;
752
+ id;
753
+ constructor(delay, task) {
754
+ super();
755
+ this.delay = delay;
756
+ this.task = task;
757
+ this.id = setTimeout(task, delay);
758
+ }
759
+ destructor() {
760
+ clearTimeout(this.id);
761
+ }
762
+ }
763
+ $.$mol_after_timeout = $mol_after_timeout;
764
+ })($ || ($ = {}));
765
+ //mol/after/timeout/timeout.ts
766
+ ;
767
+ "use strict";
768
+ var $;
769
+ (function ($) {
770
+ function $mol_wait_timeout_async(timeout) {
771
+ const promise = $mol_promise();
772
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
773
+ return Object.assign(promise, {
774
+ destructor: () => task.destructor()
775
+ });
776
+ }
777
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
778
+ function $mol_wait_timeout(timeout) {
779
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
780
+ }
781
+ $.$mol_wait_timeout = $mol_wait_timeout;
782
+ })($ || ($ = {}));
783
+ //mol/wait/timeout/timeout.ts
784
+ ;
785
+ "use strict";
786
+ var $;
787
+ (function ($_1) {
788
+ $mol_test({
789
+ async 'Latest Calls Wins on Concurrency'($) {
790
+ class NameLogger extends $mol_object2 {
791
+ static $ = $;
792
+ static first = [];
793
+ static last = [];
794
+ static send(next) {
795
+ $mol_wire_sync(this.first).push(next);
796
+ this.$.$mol_wait_timeout(0);
797
+ this.last.push(next);
798
+ }
799
+ }
800
+ const name = $mol_wire_async(NameLogger).send;
801
+ name('john');
802
+ const promise = name('jin');
803
+ $.$mol_after_mock_warp();
804
+ await promise;
805
+ $mol_assert_like(NameLogger.first, ['john', 'jin']);
806
+ $mol_assert_like(NameLogger.last, ['jin']);
807
+ },
808
+ });
809
+ })($ || ($ = {}));
810
+ //mol/wire/async/async.test.ts
811
+ ;
812
+ "use strict";
813
+ var $;
814
+ (function ($) {
815
+ $mol_test({
816
+ 'Primitives'() {
817
+ $mol_assert_equal($mol_key(null), 'null');
818
+ $mol_assert_equal($mol_key(false), 'false');
819
+ $mol_assert_equal($mol_key(true), 'true');
820
+ $mol_assert_equal($mol_key(0), '0');
821
+ $mol_assert_equal($mol_key(''), '""');
822
+ },
823
+ 'Array & POJO'() {
824
+ $mol_assert_equal($mol_key([null]), '[null]');
825
+ $mol_assert_equal($mol_key({ foo: 0 }), '{"foo":0}');
826
+ $mol_assert_equal($mol_key({ foo: [false] }), '{"foo":[false]}');
827
+ },
828
+ 'Function'() {
829
+ const func = () => { };
830
+ $mol_assert_equal($mol_key(func), $mol_key(func));
831
+ $mol_assert_unique($mol_key(func), $mol_key(() => { }));
832
+ },
833
+ 'Objects'() {
834
+ class User {
835
+ }
836
+ const jin = new User();
837
+ $mol_assert_equal($mol_key(jin), $mol_key(jin));
838
+ $mol_assert_unique($mol_key(jin), $mol_key(new User()));
839
+ },
840
+ 'Elements'() {
841
+ const foo = $mol_jsx("div", null, "bar");
842
+ $mol_assert_equal($mol_key(foo), $mol_key(foo));
843
+ $mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
844
+ },
845
+ 'Custom JSON representation'() {
846
+ class User {
847
+ name;
848
+ age;
849
+ constructor(name, age) {
850
+ this.name = name;
851
+ this.age = age;
852
+ }
853
+ toJSON() { return { name: this.name }; }
854
+ }
855
+ $mol_assert_equal($mol_key(new User('jin', 18)), '{"name":"jin"}');
856
+ },
857
+ 'Special native classes'() {
858
+ $mol_assert_equal($mol_key(new Date('xyz')), 'null');
859
+ $mol_assert_equal($mol_key(new Date('2001-01-02T03:04:05.678Z')), '"2001-01-02T03:04:05.678Z"');
860
+ $mol_assert_equal($mol_key(/./), '"/./"');
861
+ $mol_assert_equal($mol_key(/\./gimsu), '"/\\\\./gimsu"');
862
+ },
863
+ });
864
+ })($ || ($ = {}));
865
+ //mol/key/key.test.tsx
866
+ ;
867
+ "use strict";
868
+ var $;
869
+ (function ($_1) {
870
+ $mol_test_mocks.push($ => {
871
+ $.$mol_after_frame = $mol_after_mock_commmon;
872
+ });
873
+ })($ || ($ = {}));
874
+ //mol/after/frame/frame.test.ts
875
+ ;
876
+ "use strict";
877
+ var $;
878
+ (function ($) {
879
+ $mol_test({
880
+ 'Sync execution'() {
881
+ class Sync extends $mol_object2 {
882
+ static calc(a, b) {
883
+ return a + b;
884
+ }
885
+ }
886
+ __decorate([
887
+ $mol_wire_method
888
+ ], Sync, "calc", null);
889
+ $mol_assert_equal(Sync.calc(1, 2), 3);
890
+ },
891
+ async 'async <=> sync'() {
892
+ class SyncAsync extends $mol_object2 {
893
+ static async val(a) {
894
+ return a;
895
+ }
896
+ static sum(a, b) {
897
+ const syn = $mol_wire_sync(this);
898
+ return syn.val(a) + syn.val(b);
899
+ }
900
+ static async calc(a, b) {
901
+ return 5 + await $mol_wire_async(this).sum(a, b);
902
+ }
903
+ }
904
+ $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
905
+ },
906
+ async 'Idempotence control'() {
907
+ class Idempotence extends $mol_object2 {
908
+ static logs_idemp = 0;
909
+ static logs_unidemp = 0;
910
+ static log_idemp() {
911
+ this.logs_idemp += 1;
912
+ }
913
+ static log_unidemp() {
914
+ this.logs_unidemp += 1;
915
+ }
916
+ static async val(a) {
917
+ return a;
918
+ }
919
+ static sum(a, b) {
920
+ this.log_idemp();
921
+ this.log_unidemp();
922
+ const syn = $mol_wire_sync(this);
923
+ return syn.val(a) + syn.val(b);
924
+ }
925
+ static async calc(a, b) {
926
+ return 5 + await $mol_wire_async(this).sum(a, b);
927
+ }
928
+ }
929
+ __decorate([
930
+ $mol_wire_method
931
+ ], Idempotence, "log_idemp", null);
932
+ $mol_assert_equal(await Idempotence.calc(1, 2), 8);
933
+ $mol_assert_equal(Idempotence.logs_idemp, 1);
934
+ $mol_assert_equal(Idempotence.logs_unidemp, 3);
935
+ },
936
+ async 'Error handling'() {
937
+ class Handle extends $mol_object2 {
938
+ static async sum(a, b) {
939
+ $mol_fail(new Error('test error ' + (a + b)));
940
+ }
941
+ static check() {
942
+ try {
943
+ return $mol_wire_sync(Handle).sum(1, 2);
944
+ }
945
+ catch (error) {
946
+ if (error instanceof Promise)
947
+ $mol_fail_hidden(error);
948
+ $mol_assert_equal(error.message, 'test error 3');
949
+ }
950
+ }
951
+ }
952
+ await $mol_wire_async(Handle).check();
953
+ },
954
+ });
955
+ })($ || ($ = {}));
956
+ //mol/wire/fiber/fiber.test.ts
957
+ ;
958
+ "use strict";
959
+ var $;
960
+ (function ($_1) {
961
+ $mol_test({
962
+ 'Cached channel'($) {
963
+ class App extends $mol_object2 {
964
+ static $ = $;
965
+ static value(next = 1) {
966
+ return next + 1;
967
+ }
968
+ static test() {
969
+ $mol_assert_equal(App.value(), 2);
970
+ App.value(2);
971
+ $mol_assert_equal(App.value(), 3);
972
+ }
973
+ }
974
+ __decorate([
975
+ $mol_wire_mem(0)
976
+ ], App, "value", null);
977
+ __decorate([
978
+ $mol_wire_method
979
+ ], App, "test", null);
980
+ App.test();
981
+ },
982
+ 'Mem overrides mem'($) {
983
+ class Base extends $mol_object2 {
984
+ static $ = $;
985
+ static value(next = 1) {
986
+ return next + 1;
987
+ }
988
+ }
989
+ __decorate([
990
+ $mol_wire_mem(0)
991
+ ], Base, "value", null);
992
+ class Middle extends Base {
993
+ static value(next) {
994
+ return super.value(next) + 1;
995
+ }
996
+ }
997
+ __decorate([
998
+ $mol_wire_mem(0)
999
+ ], Middle, "value", null);
1000
+ class App extends Middle {
1001
+ static value(next) {
1002
+ return super.value(next) * 3;
1003
+ }
1004
+ static test() {
1005
+ $mol_assert_equal(this.value(), 9);
1006
+ $mol_assert_equal(this.value(5), 21);
1007
+ $mol_assert_equal(this.value(), 21);
1008
+ }
1009
+ }
1010
+ __decorate([
1011
+ $mol_wire_mem(0)
1012
+ ], App, "value", null);
1013
+ __decorate([
1014
+ $mol_wire_method
1015
+ ], App, "test", null);
1016
+ App.test();
1017
+ },
1018
+ 'Auto recalculation of cached values'($) {
1019
+ class App extends $mol_object2 {
1020
+ static $ = $;
1021
+ static xxx(next) {
1022
+ return next || 1;
1023
+ }
1024
+ static yyy() {
1025
+ return this.xxx() + 1;
1026
+ }
1027
+ static zzz() {
1028
+ return this.yyy() + 1;
1029
+ }
1030
+ static test() {
1031
+ $mol_assert_equal(App.yyy(), 2);
1032
+ $mol_assert_equal(App.zzz(), 3);
1033
+ App.xxx(5);
1034
+ $mol_assert_equal(App.zzz(), 7);
1035
+ }
1036
+ }
1037
+ __decorate([
1038
+ $mol_wire_mem(0)
1039
+ ], App, "xxx", null);
1040
+ __decorate([
1041
+ $mol_wire_mem(0)
1042
+ ], App, "yyy", null);
1043
+ __decorate([
1044
+ $mol_wire_mem(0)
1045
+ ], App, "zzz", null);
1046
+ __decorate([
1047
+ $mol_wire_method
1048
+ ], App, "test", null);
1049
+ App.test();
1050
+ },
1051
+ 'Skip recalculation when actually no dependency changes'($) {
1052
+ const log = [];
1053
+ class App extends $mol_object2 {
1054
+ static $ = $;
1055
+ static xxx(next) {
1056
+ log.push('xxx');
1057
+ return next || 1;
1058
+ }
1059
+ static yyy() {
1060
+ log.push('yyy');
1061
+ return [Math.sign(this.xxx())];
1062
+ }
1063
+ static zzz() {
1064
+ log.push('zzz');
1065
+ return this.yyy()[0] + 1;
1066
+ }
1067
+ static test() {
1068
+ App.zzz();
1069
+ $mol_assert_like(log, ['zzz', 'yyy', 'xxx']);
1070
+ App.xxx(5);
1071
+ App.zzz();
1072
+ $mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
1073
+ }
1074
+ }
1075
+ __decorate([
1076
+ $mol_wire_mem(0)
1077
+ ], App, "xxx", null);
1078
+ __decorate([
1079
+ $mol_wire_mem(0)
1080
+ ], App, "yyy", null);
1081
+ __decorate([
1082
+ $mol_wire_mem(0)
1083
+ ], App, "zzz", null);
1084
+ __decorate([
1085
+ $mol_wire_method
1086
+ ], App, "test", null);
1087
+ App.test();
1088
+ },
1089
+ 'Flow: Auto'($) {
1090
+ class App extends $mol_object2 {
1091
+ static get $() { return $; }
1092
+ static first(next = 1) { return next; }
1093
+ static second(next = 2) { return next; }
1094
+ static condition(next = true) { return next; }
1095
+ static counter = 0;
1096
+ static result() {
1097
+ const res = this.condition() ? this.first() : this.second();
1098
+ return res + this.counter++;
1099
+ }
1100
+ }
1101
+ __decorate([
1102
+ $mol_wire_mem(0)
1103
+ ], App, "first", null);
1104
+ __decorate([
1105
+ $mol_wire_mem(0)
1106
+ ], App, "second", null);
1107
+ __decorate([
1108
+ $mol_wire_mem(0)
1109
+ ], App, "condition", null);
1110
+ __decorate([
1111
+ $mol_wire_mem(0)
1112
+ ], App, "result", null);
1113
+ $mol_assert_equal(App.result(), 1);
1114
+ $mol_assert_equal(App.counter, 1);
1115
+ App.condition(false);
1116
+ $mol_assert_equal(App.result(), 3);
1117
+ $mol_assert_equal(App.counter, 2);
1118
+ App.first(10);
1119
+ $mol_assert_equal(App.result(), 3);
1120
+ $mol_assert_equal(App.counter, 2);
1121
+ },
1122
+ 'Dupes: Equality'($) {
1123
+ let counter = 0;
1124
+ class App extends $mol_object2 {
1125
+ static $ = $;
1126
+ static foo(next) {
1127
+ return next ?? { numbs: [1] };
1128
+ }
1129
+ static bar() {
1130
+ return { ...this.foo(), count: ++counter };
1131
+ }
1132
+ static test() {
1133
+ $mol_assert_like(App.bar(), { numbs: [1], count: 1 });
1134
+ App.foo({ numbs: [1] });
1135
+ $mol_assert_like(App.bar(), { numbs: [1], count: 1 });
1136
+ App.foo({ numbs: [2] });
1137
+ $mol_assert_like(App.bar(), { numbs: [2], count: 2 });
1138
+ }
1139
+ }
1140
+ __decorate([
1141
+ $mol_wire_mem(0)
1142
+ ], App, "foo", null);
1143
+ __decorate([
1144
+ $mol_wire_mem(0)
1145
+ ], App, "bar", null);
1146
+ __decorate([
1147
+ $mol_wire_method
1148
+ ], App, "test", null);
1149
+ App.test();
1150
+ },
1151
+ 'Cycle: Fail'($) {
1152
+ class App extends $mol_object2 {
1153
+ static $ = $;
1154
+ static foo() {
1155
+ return this.bar() + 1;
1156
+ }
1157
+ static bar() {
1158
+ return this.foo() + 1;
1159
+ }
1160
+ static test() {
1161
+ $mol_assert_fail(() => App.foo(), 'Circular subscription');
1162
+ }
1163
+ }
1164
+ __decorate([
1165
+ $mol_wire_mem(0)
1166
+ ], App, "foo", null);
1167
+ __decorate([
1168
+ $mol_wire_mem(0)
1169
+ ], App, "bar", null);
1170
+ __decorate([
1171
+ $mol_wire_method
1172
+ ], App, "test", null);
1173
+ App.test();
1174
+ },
1175
+ 'Different order of pull and push'($) {
1176
+ class App extends $mol_object2 {
1177
+ static $ = $;
1178
+ static store(next = 0) {
1179
+ return next;
1180
+ }
1181
+ static fast(next) {
1182
+ return this.store(next);
1183
+ }
1184
+ static slow(next) {
1185
+ return this.store(next);
1186
+ }
1187
+ static test() {
1188
+ App.fast();
1189
+ $mol_assert_equal(App.slow(666), 666);
1190
+ $mol_assert_equal(App.fast(), App.slow(), 666);
1191
+ App.store(777);
1192
+ $mol_assert_equal(App.fast(), App.slow(), 777);
1193
+ }
1194
+ }
1195
+ __decorate([
1196
+ $mol_wire_mem(0)
1197
+ ], App, "store", null);
1198
+ __decorate([
1199
+ $mol_wire_mem(0)
1200
+ ], App, "fast", null);
1201
+ __decorate([
1202
+ $mol_wire_mem(0)
1203
+ ], App, "slow", null);
1204
+ __decorate([
1205
+ $mol_wire_method
1206
+ ], App, "test", null);
1207
+ App.test();
1208
+ },
1209
+ 'Actions inside invariant'($) {
1210
+ class App extends $mol_object2 {
1211
+ static $ = $;
1212
+ static count(next = 0) {
1213
+ return next;
1214
+ }
1215
+ static count2() {
1216
+ return this.count();
1217
+ }
1218
+ static res() {
1219
+ const count = this.count2();
1220
+ if (!count)
1221
+ this.count(count + 1);
1222
+ return count + 1;
1223
+ }
1224
+ static test() {
1225
+ $mol_assert_like(App.res(), 1);
1226
+ App.count(5);
1227
+ $mol_assert_like(App.res(), 6);
1228
+ }
1229
+ }
1230
+ __decorate([
1231
+ $mol_wire_mem(0)
1232
+ ], App, "count", null);
1233
+ __decorate([
1234
+ $mol_wire_mem(0)
1235
+ ], App, "count2", null);
1236
+ __decorate([
1237
+ $mol_wire_mem(0)
1238
+ ], App, "res", null);
1239
+ __decorate([
1240
+ $mol_wire_method
1241
+ ], App, "test", null);
1242
+ App.test();
1243
+ },
1244
+ 'Restore after error'($) {
1245
+ class App extends $mol_object2 {
1246
+ static get $() { return $; }
1247
+ static condition(next = false) { return next; }
1248
+ static broken() {
1249
+ if (this.condition()) {
1250
+ $mol_fail(new Error('test error'));
1251
+ }
1252
+ return 1;
1253
+ }
1254
+ static result() {
1255
+ return this.broken();
1256
+ }
1257
+ }
1258
+ __decorate([
1259
+ $mol_wire_mem(0)
1260
+ ], App, "condition", null);
1261
+ __decorate([
1262
+ $mol_wire_mem(0)
1263
+ ], App, "broken", null);
1264
+ __decorate([
1265
+ $mol_wire_mem(0)
1266
+ ], App, "result", null);
1267
+ $mol_assert_equal(App.result(), 1);
1268
+ App.condition(true);
1269
+ $mol_assert_fail(() => App.result());
1270
+ App.condition(false);
1271
+ $mol_assert_equal(App.result(), 1);
1272
+ },
1273
+ async 'Wait for data'($) {
1274
+ class App extends $mol_object2 {
1275
+ static $ = $;
1276
+ static async source() {
1277
+ return 'Jin';
1278
+ }
1279
+ static middle() {
1280
+ return $mol_wire_sync(this).source();
1281
+ }
1282
+ static target() {
1283
+ return this.middle();
1284
+ }
1285
+ static test() {
1286
+ $mol_assert_equal(App.target(), 'Jin');
1287
+ }
1288
+ }
1289
+ __decorate([
1290
+ $mol_wire_mem(0)
1291
+ ], App, "middle", null);
1292
+ __decorate([
1293
+ $mol_wire_mem(0)
1294
+ ], App, "target", null);
1295
+ __decorate([
1296
+ $mol_wire_method
1297
+ ], App, "test", null);
1298
+ await $mol_wire_async(App).test();
1299
+ },
1300
+ 'Auto destroy on long alone'($) {
1301
+ let destroyed = false;
1302
+ class App extends $mol_object2 {
1303
+ static $ = $;
1304
+ static showing(next = true) {
1305
+ return next;
1306
+ }
1307
+ static details() {
1308
+ return {
1309
+ destructor() {
1310
+ destroyed = true;
1311
+ }
1312
+ };
1313
+ }
1314
+ static render() {
1315
+ return this.showing() ? this.details() : null;
1316
+ }
1317
+ }
1318
+ __decorate([
1319
+ $mol_wire_mem(0)
1320
+ ], App, "showing", null);
1321
+ __decorate([
1322
+ $mol_wire_mem(0)
1323
+ ], App, "details", null);
1324
+ __decorate([
1325
+ $mol_wire_mem(0)
1326
+ ], App, "render", null);
1327
+ const details = App.render();
1328
+ $mol_assert_ok(details);
1329
+ App.showing(false);
1330
+ $mol_assert_not(App.render());
1331
+ App.showing(true);
1332
+ $mol_assert_equal(App.render(), details);
1333
+ $mol_wire_fiber.sync();
1334
+ $mol_assert_not(destroyed);
1335
+ App.showing(false);
1336
+ $mol_wire_fiber.sync();
1337
+ $mol_assert_ok(destroyed);
1338
+ App.showing(true);
1339
+ $mol_assert_unique(App.render(), details);
1340
+ },
1341
+ 'Forget sub fibers on complete'($) {
1342
+ class App extends $mol_object2 {
1343
+ static get $() { return $; }
1344
+ static counter = 0;
1345
+ static count() { return this.counter++; }
1346
+ static data(next = 1) { return next; }
1347
+ static result() {
1348
+ return this.count() + this.data();
1349
+ }
1350
+ }
1351
+ __decorate([
1352
+ $mol_wire_method
1353
+ ], App, "count", null);
1354
+ __decorate([
1355
+ $mol_wire_mem(0)
1356
+ ], App, "data", null);
1357
+ __decorate([
1358
+ $mol_wire_mem(0)
1359
+ ], App, "result", null);
1360
+ $mol_assert_equal(App.result(), 1);
1361
+ App.data(2);
1362
+ $mol_assert_equal(App.result(), 3);
1363
+ },
1364
+ 'Memoize by single simple key'($) {
1365
+ class Team extends $mol_object2 {
1366
+ static $ = $;
1367
+ static user_name(user, next) {
1368
+ return next ?? user;
1369
+ }
1370
+ static user_names() {
1371
+ return [
1372
+ this.user_name('jin'),
1373
+ this.user_name('john'),
1374
+ ];
1375
+ }
1376
+ static test() {
1377
+ $mol_assert_like(this.user_names(), ['jin', 'john']);
1378
+ Team.user_name('jin', 'JIN');
1379
+ $mol_assert_like(this.user_names(), ['JIN', 'john']);
1380
+ }
1381
+ }
1382
+ __decorate([
1383
+ $mol_wire_mem(1)
1384
+ ], Team, "user_name", null);
1385
+ __decorate([
1386
+ $mol_wire_mem(1)
1387
+ ], Team, "user_names", null);
1388
+ __decorate([
1389
+ $mol_wire_method
1390
+ ], Team, "test", null);
1391
+ Team.test();
1392
+ },
1393
+ 'Memoize by single complex key'($) {
1394
+ class Map extends $mol_object2 {
1395
+ static $ = $;
1396
+ static tile(pos) {
1397
+ return new String(`/tile=${pos}`);
1398
+ }
1399
+ static test() {
1400
+ $mol_assert_like(this.tile([0, 1]), new String('/tile=0,1'));
1401
+ $mol_assert_equal(this.tile([0, 1]), this.tile([0, 1]));
1402
+ }
1403
+ }
1404
+ __decorate([
1405
+ $mol_wire_mem(1)
1406
+ ], Map, "tile", null);
1407
+ __decorate([
1408
+ $mol_wire_method
1409
+ ], Map, "test", null);
1410
+ Map.test();
1411
+ },
1412
+ 'Memoize by multiple keys'($) {
1413
+ class Map extends $mol_object2 {
1414
+ static $ = $;
1415
+ static tile(x, y) {
1416
+ return new String(`/tile=${x},${y}`);
1417
+ }
1418
+ static test() {
1419
+ $mol_assert_like(this.tile(0, 1), new String('/tile=0,1'));
1420
+ $mol_assert_equal(this.tile(0, 1), this.tile(0, 1));
1421
+ }
1422
+ }
1423
+ __decorate([
1424
+ $mol_wire_mem(2)
1425
+ ], Map, "tile", null);
1426
+ __decorate([
1427
+ $mol_wire_method
1428
+ ], Map, "test", null);
1429
+ Map.test();
1430
+ },
1431
+ 'Owned value has js-path name'() {
1432
+ class App extends $mol_object2 {
1433
+ static title() {
1434
+ return new $mol_object2;
1435
+ }
1436
+ static like(friend) {
1437
+ return new $mol_object2;
1438
+ }
1439
+ static relation(friend, props) {
1440
+ return new $mol_object2;
1441
+ }
1442
+ }
1443
+ __decorate([
1444
+ $mol_wire_mem(0)
1445
+ ], App, "title", null);
1446
+ __decorate([
1447
+ $mol_wire_mem(1)
1448
+ ], App, "like", null);
1449
+ __decorate([
1450
+ $mol_wire_mem(2)
1451
+ ], App, "relation", null);
1452
+ $mol_assert_equal(`${App.title()}`, 'App.title()');
1453
+ $mol_assert_equal(`${App.like(123)}`, 'App.like(123)');
1454
+ $mol_assert_equal(`${App.relation(123, [456])}`, 'App.relation(123,[456])');
1455
+ },
1456
+ 'Deep deps'($) {
1457
+ class Fib extends $mol_object2 {
1458
+ static $ = $;
1459
+ static sums = 0;
1460
+ static value(index, next) {
1461
+ if (next)
1462
+ return next;
1463
+ if (index < 2)
1464
+ return 1;
1465
+ ++this.sums;
1466
+ return this.value(index - 1) + this.value(index - 2);
1467
+ }
1468
+ static test() {
1469
+ $mol_assert_equal(this.value(4), 5);
1470
+ $mol_assert_equal(this.sums, 3);
1471
+ this.value(1, 2);
1472
+ $mol_assert_equal(this.value(4), 8);
1473
+ $mol_assert_equal(this.sums, 6);
1474
+ }
1475
+ }
1476
+ __decorate([
1477
+ $mol_wire_mem(1)
1478
+ ], Fib, "value", null);
1479
+ __decorate([
1480
+ $mol_wire_method
1481
+ ], Fib, "test", null);
1482
+ Fib.test();
1483
+ },
1484
+ 'Unsubscribe from temp pubs on complete'($) {
1485
+ class Random extends $mol_object2 {
1486
+ static $ = $;
1487
+ static seed() {
1488
+ return Math.random();
1489
+ }
1490
+ static resets(next) {
1491
+ return Math.random();
1492
+ }
1493
+ static value() {
1494
+ this.resets();
1495
+ return this.seed();
1496
+ }
1497
+ static test() {
1498
+ const first = this.value();
1499
+ this.resets(null);
1500
+ const second = this.value();
1501
+ $mol_assert_unique(first, second);
1502
+ }
1503
+ }
1504
+ __decorate([
1505
+ $mol_wire_method
1506
+ ], Random, "seed", null);
1507
+ __decorate([
1508
+ $mol_wire_mem(0)
1509
+ ], Random, "resets", null);
1510
+ __decorate([
1511
+ $mol_wire_mem(0)
1512
+ ], Random, "value", null);
1513
+ __decorate([
1514
+ $mol_wire_method
1515
+ ], Random, "test", null);
1516
+ Random.test();
1517
+ },
1518
+ });
1519
+ })($ || ($ = {}));
1520
+ //mol/wire/mem/mem.test.ts
1521
+ ;
1522
+ "use strict";
1523
+ var $;
1524
+ (function ($) {
1525
+ $mol_test({
1526
+ 'const returns stored value'() {
1527
+ const foo = { bar: $mol_const(Math.random()) };
1528
+ $mol_assert_equal(foo.bar(), foo.bar());
1529
+ $mol_assert_equal(foo.bar(), foo.bar['()']);
1530
+ },
1531
+ });
1532
+ })($ || ($ = {}));
1533
+ //mol/const/const.test.ts
1534
+ ;
1535
+ "use strict";
1536
+ var $;
1537
+ (function ($_1) {
1538
+ $mol_test({
1539
+ 'Cached field'($) {
1540
+ class App extends $mol_object2 {
1541
+ static $ = $;
1542
+ static low = 1;
1543
+ static get high() {
1544
+ return this.low + 1;
1545
+ }
1546
+ static set high(next) {
1547
+ this.low = next - 1;
1548
+ }
1549
+ static test() {
1550
+ $mol_assert_equal(App.high, 2);
1551
+ App.high = 3;
1552
+ $mol_assert_equal(App.high, 3);
1553
+ }
1554
+ }
1555
+ __decorate([
1556
+ $mol_wire_field
1557
+ ], App, "low", void 0);
1558
+ __decorate([
1559
+ $mol_wire_field
1560
+ ], App, "high", null);
1561
+ __decorate([
1562
+ $mol_wire_method
1563
+ ], App, "test", null);
1564
+ App.test();
1565
+ },
1566
+ });
1567
+ })($ || ($ = {}));
1568
+ //mol/wire/field/field.test.ts
1569
+ ;
1570
+ "use strict";
1571
+ var $;
1572
+ (function ($) {
1573
+ function $mol_log3_area_lazy(event) {
1574
+ const self = this;
1575
+ const stack = self.$mol_log3_stack;
1576
+ const deep = stack.length;
1577
+ let logged = false;
1578
+ stack.push(() => {
1579
+ logged = true;
1580
+ self.$mol_log3_area.call(self, event);
1581
+ });
1582
+ return () => {
1583
+ if (logged)
1584
+ self.console.groupEnd();
1585
+ if (stack.length > deep)
1586
+ stack.length = deep;
1587
+ };
1588
+ }
1589
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1590
+ $.$mol_log3_stack = [];
1591
+ })($ || ($ = {}));
1592
+ //mol/log3/log3.ts
1593
+ ;
1594
+ "use strict";
1595
+ //mol/type/keys/extract/extract.test.ts
1596
+ ;
1597
+ "use strict";
1598
+ //mol/type/keys/extract/extract.ts
1599
+ ;
1600
+ "use strict";
1601
+ var $;
1602
+ (function ($_1) {
1603
+ $mol_test_mocks.push($ => {
1604
+ $.$mol_log3_come = () => { };
1605
+ $.$mol_log3_done = () => { };
1606
+ $.$mol_log3_fail = () => { };
1607
+ $.$mol_log3_warn = () => { };
1608
+ $.$mol_log3_rise = () => { };
1609
+ $.$mol_log3_area = () => () => { };
1610
+ });
1611
+ })($ || ($ = {}));
1612
+ //mol/log3/log3.test.ts
1613
+ ;
1614
+ "use strict";
1615
+ var $;
1616
+ (function ($) {
1617
+ function $mol_log3_web_make(level, color) {
1618
+ return function $mol_log3_logger(event) {
1619
+ const pending = this.$mol_log3_stack.pop();
1620
+ if (pending)
1621
+ pending();
1622
+ let tpl = '%c';
1623
+ const chunks = Object.values(event);
1624
+ for (let i = 0; i < chunks.length; ++i) {
1625
+ tpl += (typeof chunks[i] === 'string') ? ' ⦙ %s' : ' ⦙ %o';
1626
+ }
1627
+ const style = `color:${color};font-weight:bolder`;
1628
+ this.console[level](tpl, style, ...chunks);
1629
+ const self = this;
1630
+ return () => self.console.groupEnd();
1631
+ };
1632
+ }
1633
+ $.$mol_log3_web_make = $mol_log3_web_make;
1634
+ $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
1635
+ $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
1636
+ $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
1637
+ $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
1638
+ $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
1639
+ $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
1640
+ })($ || ($ = {}));
1641
+ //mol/log3/log3.web.ts
1642
+ ;
1643
+ "use strict";
1644
+ //mol/type/equals/equals.test.ts
1645
+ ;
1646
+ "use strict";
1647
+ //mol/type/equals/equals.ts
1648
+
1649
+ //# sourceMappingURL=web.test.js.map