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