mol_wire_lib 1.0.90 → 1.0.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node.d.ts +25 -21
- package/node.deps.json +1 -1
- package/node.esm.js +283 -268
- package/node.esm.js.map +1 -1
- package/node.js +283 -268
- package/node.js.map +1 -1
- package/node.test.js +837 -852
- package/node.test.js.map +1 -1
- package/package.json +5 -5
- package/web.d.ts +25 -21
- package/web.deps.json +1 -1
- package/web.esm.js +283 -268
- package/web.esm.js.map +1 -1
- package/web.js +283 -268
- package/web.js.map +1 -1
- package/web.test.js +97 -127
- package/web.test.js.map +1 -1
package/web.esm.js
CHANGED
|
@@ -369,183 +369,6 @@ var $;
|
|
|
369
369
|
;
|
|
370
370
|
"use strict";
|
|
371
371
|
var $;
|
|
372
|
-
(function ($) {
|
|
373
|
-
$.$mol_compare_deep_cache = new WeakMap();
|
|
374
|
-
function $mol_compare_deep(left, right) {
|
|
375
|
-
if (Object.is(left, right))
|
|
376
|
-
return true;
|
|
377
|
-
if (left === null)
|
|
378
|
-
return false;
|
|
379
|
-
if (right === null)
|
|
380
|
-
return false;
|
|
381
|
-
if (typeof left !== 'object')
|
|
382
|
-
return false;
|
|
383
|
-
if (typeof right !== 'object')
|
|
384
|
-
return false;
|
|
385
|
-
const left_proto = Reflect.getPrototypeOf(left);
|
|
386
|
-
const right_proto = Reflect.getPrototypeOf(right);
|
|
387
|
-
if (left_proto !== right_proto)
|
|
388
|
-
return false;
|
|
389
|
-
if (left instanceof Boolean)
|
|
390
|
-
return Object.is(left.valueOf(), right['valueOf']());
|
|
391
|
-
if (left instanceof Number)
|
|
392
|
-
return Object.is(left.valueOf(), right['valueOf']());
|
|
393
|
-
if (left instanceof String)
|
|
394
|
-
return Object.is(left.valueOf(), right['valueOf']());
|
|
395
|
-
if (left instanceof Date)
|
|
396
|
-
return Object.is(left.valueOf(), right['valueOf']());
|
|
397
|
-
if (left instanceof RegExp)
|
|
398
|
-
return left.source === right['source'] && left.flags === right['flags'];
|
|
399
|
-
let left_cache = $.$mol_compare_deep_cache.get(left);
|
|
400
|
-
if (left_cache) {
|
|
401
|
-
const right_cache = left_cache.get(right);
|
|
402
|
-
if (typeof right_cache === 'boolean')
|
|
403
|
-
return right_cache;
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
left_cache = new WeakMap([[right, true]]);
|
|
407
|
-
$.$mol_compare_deep_cache.set(left, left_cache);
|
|
408
|
-
}
|
|
409
|
-
let result;
|
|
410
|
-
try {
|
|
411
|
-
if (left_proto && !Reflect.getPrototypeOf(left_proto))
|
|
412
|
-
result = compare_pojo(left, right);
|
|
413
|
-
else if (Array.isArray(left))
|
|
414
|
-
result = compare_array(left, right);
|
|
415
|
-
else if (left instanceof Set)
|
|
416
|
-
result = compare_set(left, right);
|
|
417
|
-
else if (left instanceof Map)
|
|
418
|
-
result = compare_map(left, right);
|
|
419
|
-
else if (left instanceof Error)
|
|
420
|
-
result = left.stack === right.stack;
|
|
421
|
-
else if (ArrayBuffer.isView(left))
|
|
422
|
-
result = compare_buffer(left, right);
|
|
423
|
-
else if (Symbol.toPrimitive in left)
|
|
424
|
-
result = compare_primitive(left, right);
|
|
425
|
-
else
|
|
426
|
-
result = false;
|
|
427
|
-
}
|
|
428
|
-
finally {
|
|
429
|
-
left_cache.set(right, result);
|
|
430
|
-
}
|
|
431
|
-
return result;
|
|
432
|
-
}
|
|
433
|
-
$.$mol_compare_deep = $mol_compare_deep;
|
|
434
|
-
function compare_array(left, right) {
|
|
435
|
-
const len = left.length;
|
|
436
|
-
if (len !== right.length)
|
|
437
|
-
return false;
|
|
438
|
-
for (let i = 0; i < len; ++i) {
|
|
439
|
-
if (!$mol_compare_deep(left[i], right[i]))
|
|
440
|
-
return false;
|
|
441
|
-
}
|
|
442
|
-
return true;
|
|
443
|
-
}
|
|
444
|
-
function compare_buffer(left, right) {
|
|
445
|
-
const len = left.byteLength;
|
|
446
|
-
if (len !== right.byteLength)
|
|
447
|
-
return false;
|
|
448
|
-
for (let i = 0; i < len; ++i) {
|
|
449
|
-
if (left[i] !== right[i])
|
|
450
|
-
return false;
|
|
451
|
-
}
|
|
452
|
-
return true;
|
|
453
|
-
}
|
|
454
|
-
function compare_iterator(left, right, compare) {
|
|
455
|
-
while (true) {
|
|
456
|
-
const left_next = left.next();
|
|
457
|
-
const right_next = right.next();
|
|
458
|
-
if (left_next.done !== right_next.done)
|
|
459
|
-
return false;
|
|
460
|
-
if (left_next.done)
|
|
461
|
-
break;
|
|
462
|
-
if (!compare(left_next.value, right_next.value))
|
|
463
|
-
return false;
|
|
464
|
-
}
|
|
465
|
-
return true;
|
|
466
|
-
}
|
|
467
|
-
function compare_set(left, right) {
|
|
468
|
-
if (left.size !== right.size)
|
|
469
|
-
return false;
|
|
470
|
-
return compare_iterator(left.values(), right.values(), $mol_compare_deep);
|
|
471
|
-
}
|
|
472
|
-
function compare_map(left, right) {
|
|
473
|
-
if (left.size !== right.size)
|
|
474
|
-
return false;
|
|
475
|
-
return compare_iterator(left.keys(), right.keys(), Object.is)
|
|
476
|
-
&& compare_iterator(left.values(), right.values(), $mol_compare_deep);
|
|
477
|
-
}
|
|
478
|
-
function compare_pojo(left, right) {
|
|
479
|
-
const left_keys = Object.getOwnPropertyNames(left);
|
|
480
|
-
const right_keys = Object.getOwnPropertyNames(right);
|
|
481
|
-
if (left_keys.length !== right_keys.length)
|
|
482
|
-
return false;
|
|
483
|
-
for (let key of left_keys) {
|
|
484
|
-
if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
|
|
485
|
-
return false;
|
|
486
|
-
}
|
|
487
|
-
return true;
|
|
488
|
-
}
|
|
489
|
-
function compare_primitive(left, right) {
|
|
490
|
-
return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
|
|
491
|
-
}
|
|
492
|
-
})($ || ($ = {}));
|
|
493
|
-
//mol/compare/deep/deep.ts
|
|
494
|
-
;
|
|
495
|
-
"use strict";
|
|
496
|
-
var $;
|
|
497
|
-
(function ($) {
|
|
498
|
-
function $mol_guid(length = 8, exists = () => false) {
|
|
499
|
-
for (;;) {
|
|
500
|
-
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
501
|
-
if (exists(id))
|
|
502
|
-
continue;
|
|
503
|
-
return id;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
$.$mol_guid = $mol_guid;
|
|
507
|
-
})($ || ($ = {}));
|
|
508
|
-
//mol/guid/guid.ts
|
|
509
|
-
;
|
|
510
|
-
"use strict";
|
|
511
|
-
var $;
|
|
512
|
-
(function ($) {
|
|
513
|
-
$.$mol_key_store = new WeakMap();
|
|
514
|
-
function $mol_key(value) {
|
|
515
|
-
if (!value)
|
|
516
|
-
return JSON.stringify(value);
|
|
517
|
-
if (typeof value !== 'object' && typeof value !== 'function')
|
|
518
|
-
return JSON.stringify(value);
|
|
519
|
-
return JSON.stringify(value, (field, value) => {
|
|
520
|
-
if (!value)
|
|
521
|
-
return value;
|
|
522
|
-
if (typeof value !== 'object' && typeof value !== 'function')
|
|
523
|
-
return value;
|
|
524
|
-
if (Array.isArray(value))
|
|
525
|
-
return value;
|
|
526
|
-
const proto = Reflect.getPrototypeOf(value);
|
|
527
|
-
if (!proto)
|
|
528
|
-
return value;
|
|
529
|
-
if (Reflect.getPrototypeOf(proto) === null)
|
|
530
|
-
return value;
|
|
531
|
-
if ('toJSON' in value)
|
|
532
|
-
return value;
|
|
533
|
-
if (value instanceof RegExp)
|
|
534
|
-
return value.toString();
|
|
535
|
-
let key = $.$mol_key_store.get(value);
|
|
536
|
-
if (key)
|
|
537
|
-
return key;
|
|
538
|
-
key = $mol_guid();
|
|
539
|
-
$.$mol_key_store.set(value, key);
|
|
540
|
-
return key;
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
$.$mol_key = $mol_key;
|
|
544
|
-
})($ || ($ = {}));
|
|
545
|
-
//mol/key/key.ts
|
|
546
|
-
;
|
|
547
|
-
"use strict";
|
|
548
|
-
var $;
|
|
549
372
|
(function ($) {
|
|
550
373
|
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
551
374
|
function $mol_ambient(overrides) {
|
|
@@ -745,6 +568,183 @@ var $;
|
|
|
745
568
|
;
|
|
746
569
|
"use strict";
|
|
747
570
|
var $;
|
|
571
|
+
(function ($) {
|
|
572
|
+
$.$mol_compare_deep_cache = new WeakMap();
|
|
573
|
+
function $mol_compare_deep(left, right) {
|
|
574
|
+
if (Object.is(left, right))
|
|
575
|
+
return true;
|
|
576
|
+
if (left === null)
|
|
577
|
+
return false;
|
|
578
|
+
if (right === null)
|
|
579
|
+
return false;
|
|
580
|
+
if (typeof left !== 'object')
|
|
581
|
+
return false;
|
|
582
|
+
if (typeof right !== 'object')
|
|
583
|
+
return false;
|
|
584
|
+
const left_proto = Reflect.getPrototypeOf(left);
|
|
585
|
+
const right_proto = Reflect.getPrototypeOf(right);
|
|
586
|
+
if (left_proto !== right_proto)
|
|
587
|
+
return false;
|
|
588
|
+
if (left instanceof Boolean)
|
|
589
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
590
|
+
if (left instanceof Number)
|
|
591
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
592
|
+
if (left instanceof String)
|
|
593
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
594
|
+
if (left instanceof Date)
|
|
595
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
596
|
+
if (left instanceof RegExp)
|
|
597
|
+
return left.source === right['source'] && left.flags === right['flags'];
|
|
598
|
+
let left_cache = $.$mol_compare_deep_cache.get(left);
|
|
599
|
+
if (left_cache) {
|
|
600
|
+
const right_cache = left_cache.get(right);
|
|
601
|
+
if (typeof right_cache === 'boolean')
|
|
602
|
+
return right_cache;
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
left_cache = new WeakMap([[right, true]]);
|
|
606
|
+
$.$mol_compare_deep_cache.set(left, left_cache);
|
|
607
|
+
}
|
|
608
|
+
let result;
|
|
609
|
+
try {
|
|
610
|
+
if (left_proto && !Reflect.getPrototypeOf(left_proto))
|
|
611
|
+
result = compare_pojo(left, right);
|
|
612
|
+
else if (Array.isArray(left))
|
|
613
|
+
result = compare_array(left, right);
|
|
614
|
+
else if (left instanceof Set)
|
|
615
|
+
result = compare_set(left, right);
|
|
616
|
+
else if (left instanceof Map)
|
|
617
|
+
result = compare_map(left, right);
|
|
618
|
+
else if (left instanceof Error)
|
|
619
|
+
result = left.stack === right.stack;
|
|
620
|
+
else if (ArrayBuffer.isView(left))
|
|
621
|
+
result = compare_buffer(left, right);
|
|
622
|
+
else if (Symbol.toPrimitive in left)
|
|
623
|
+
result = compare_primitive(left, right);
|
|
624
|
+
else
|
|
625
|
+
result = false;
|
|
626
|
+
}
|
|
627
|
+
finally {
|
|
628
|
+
left_cache.set(right, result);
|
|
629
|
+
}
|
|
630
|
+
return result;
|
|
631
|
+
}
|
|
632
|
+
$.$mol_compare_deep = $mol_compare_deep;
|
|
633
|
+
function compare_array(left, right) {
|
|
634
|
+
const len = left.length;
|
|
635
|
+
if (len !== right.length)
|
|
636
|
+
return false;
|
|
637
|
+
for (let i = 0; i < len; ++i) {
|
|
638
|
+
if (!$mol_compare_deep(left[i], right[i]))
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
function compare_buffer(left, right) {
|
|
644
|
+
const len = left.byteLength;
|
|
645
|
+
if (len !== right.byteLength)
|
|
646
|
+
return false;
|
|
647
|
+
for (let i = 0; i < len; ++i) {
|
|
648
|
+
if (left[i] !== right[i])
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
function compare_iterator(left, right, compare) {
|
|
654
|
+
while (true) {
|
|
655
|
+
const left_next = left.next();
|
|
656
|
+
const right_next = right.next();
|
|
657
|
+
if (left_next.done !== right_next.done)
|
|
658
|
+
return false;
|
|
659
|
+
if (left_next.done)
|
|
660
|
+
break;
|
|
661
|
+
if (!compare(left_next.value, right_next.value))
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
function compare_set(left, right) {
|
|
667
|
+
if (left.size !== right.size)
|
|
668
|
+
return false;
|
|
669
|
+
return compare_iterator(left.values(), right.values(), $mol_compare_deep);
|
|
670
|
+
}
|
|
671
|
+
function compare_map(left, right) {
|
|
672
|
+
if (left.size !== right.size)
|
|
673
|
+
return false;
|
|
674
|
+
return compare_iterator(left.keys(), right.keys(), Object.is)
|
|
675
|
+
&& compare_iterator(left.values(), right.values(), $mol_compare_deep);
|
|
676
|
+
}
|
|
677
|
+
function compare_pojo(left, right) {
|
|
678
|
+
const left_keys = Object.getOwnPropertyNames(left);
|
|
679
|
+
const right_keys = Object.getOwnPropertyNames(right);
|
|
680
|
+
if (left_keys.length !== right_keys.length)
|
|
681
|
+
return false;
|
|
682
|
+
for (let key of left_keys) {
|
|
683
|
+
if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
function compare_primitive(left, right) {
|
|
689
|
+
return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
|
|
690
|
+
}
|
|
691
|
+
})($ || ($ = {}));
|
|
692
|
+
//mol/compare/deep/deep.ts
|
|
693
|
+
;
|
|
694
|
+
"use strict";
|
|
695
|
+
var $;
|
|
696
|
+
(function ($) {
|
|
697
|
+
function $mol_guid(length = 8, exists = () => false) {
|
|
698
|
+
for (;;) {
|
|
699
|
+
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
700
|
+
if (exists(id))
|
|
701
|
+
continue;
|
|
702
|
+
return id;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
$.$mol_guid = $mol_guid;
|
|
706
|
+
})($ || ($ = {}));
|
|
707
|
+
//mol/guid/guid.ts
|
|
708
|
+
;
|
|
709
|
+
"use strict";
|
|
710
|
+
var $;
|
|
711
|
+
(function ($) {
|
|
712
|
+
$.$mol_key_store = new WeakMap();
|
|
713
|
+
function $mol_key(value) {
|
|
714
|
+
if (!value)
|
|
715
|
+
return JSON.stringify(value);
|
|
716
|
+
if (typeof value !== 'object' && typeof value !== 'function')
|
|
717
|
+
return JSON.stringify(value);
|
|
718
|
+
return JSON.stringify(value, (field, value) => {
|
|
719
|
+
if (!value)
|
|
720
|
+
return value;
|
|
721
|
+
if (typeof value !== 'object' && typeof value !== 'function')
|
|
722
|
+
return value;
|
|
723
|
+
if (Array.isArray(value))
|
|
724
|
+
return value;
|
|
725
|
+
const proto = Reflect.getPrototypeOf(value);
|
|
726
|
+
if (!proto)
|
|
727
|
+
return value;
|
|
728
|
+
if (Reflect.getPrototypeOf(proto) === null)
|
|
729
|
+
return value;
|
|
730
|
+
if ('toJSON' in value)
|
|
731
|
+
return value;
|
|
732
|
+
if (value instanceof RegExp)
|
|
733
|
+
return value.toString();
|
|
734
|
+
let key = $.$mol_key_store.get(value);
|
|
735
|
+
if (key)
|
|
736
|
+
return key;
|
|
737
|
+
key = $mol_guid();
|
|
738
|
+
$.$mol_key_store.set(value, key);
|
|
739
|
+
return key;
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
$.$mol_key = $mol_key;
|
|
743
|
+
})($ || ($ = {}));
|
|
744
|
+
//mol/key/key.ts
|
|
745
|
+
;
|
|
746
|
+
"use strict";
|
|
747
|
+
var $;
|
|
748
748
|
(function ($) {
|
|
749
749
|
function $mol_wire_method(host, field, descr) {
|
|
750
750
|
if (!descr)
|
|
@@ -754,8 +754,9 @@ var $;
|
|
|
754
754
|
if (typeof sup[field] === 'function') {
|
|
755
755
|
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
|
756
756
|
}
|
|
757
|
+
const temp = $mol_wire_fiber_temp.getter(orig);
|
|
757
758
|
const value = function (...args) {
|
|
758
|
-
const fiber =
|
|
759
|
+
const fiber = temp(this ?? null, args);
|
|
759
760
|
return fiber.sync();
|
|
760
761
|
};
|
|
761
762
|
Object.defineProperty(value, 'name', { value: orig.name + ' ' });
|
|
@@ -775,53 +776,6 @@ var $;
|
|
|
775
776
|
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
|
776
777
|
task;
|
|
777
778
|
host;
|
|
778
|
-
static temp(host, task, ...args) {
|
|
779
|
-
const existen = $mol_wire_auto()?.track_next();
|
|
780
|
-
reuse: if (existen) {
|
|
781
|
-
if (!(existen instanceof $mol_wire_fiber))
|
|
782
|
-
break reuse;
|
|
783
|
-
if (existen.host !== host)
|
|
784
|
-
break reuse;
|
|
785
|
-
if (existen.task !== task)
|
|
786
|
-
break reuse;
|
|
787
|
-
if (!$mol_compare_deep(existen.args, args))
|
|
788
|
-
break reuse;
|
|
789
|
-
return existen;
|
|
790
|
-
}
|
|
791
|
-
return new this(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
|
|
792
|
-
}
|
|
793
|
-
static persist(task, keys) {
|
|
794
|
-
const field = task.name + '()';
|
|
795
|
-
if (keys) {
|
|
796
|
-
return function $mol_wire_fiber_persist(host, args) {
|
|
797
|
-
let dict, key, fiber;
|
|
798
|
-
key = `${host?.[Symbol.toStringTag] ?? host}.${task.name}(${args.map(v => $mol_key(v)).join(',')})`;
|
|
799
|
-
dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
800
|
-
if (dict) {
|
|
801
|
-
const existen = dict.get(key);
|
|
802
|
-
if (existen)
|
|
803
|
-
return existen;
|
|
804
|
-
}
|
|
805
|
-
else {
|
|
806
|
-
dict = (host ?? task)[field] = new Map();
|
|
807
|
-
}
|
|
808
|
-
fiber = new $mol_wire_fiber(key, task, host, ...args);
|
|
809
|
-
dict.set(key, fiber);
|
|
810
|
-
return fiber;
|
|
811
|
-
};
|
|
812
|
-
}
|
|
813
|
-
else {
|
|
814
|
-
return function $mol_wire_fiber_persist(host, args) {
|
|
815
|
-
const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
816
|
-
if (existen)
|
|
817
|
-
return existen;
|
|
818
|
-
const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
|
|
819
|
-
const fiber = new $mol_wire_fiber(key, task, host, ...args);
|
|
820
|
-
(host ?? task)[field] = fiber;
|
|
821
|
-
return fiber;
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
779
|
static warm = true;
|
|
826
780
|
static planning = [];
|
|
827
781
|
static reaping = [];
|
|
@@ -865,10 +819,6 @@ var $;
|
|
|
865
819
|
return;
|
|
866
820
|
return this.cache;
|
|
867
821
|
}
|
|
868
|
-
persistent() {
|
|
869
|
-
const id = this[Symbol.toStringTag];
|
|
870
|
-
return id[id.length - 2] !== '#';
|
|
871
|
-
}
|
|
872
822
|
field() {
|
|
873
823
|
return this.task.name + '()';
|
|
874
824
|
}
|
|
@@ -881,23 +831,6 @@ var $;
|
|
|
881
831
|
this.pub_from = this.sub_from = args.length;
|
|
882
832
|
this[Symbol.toStringTag] = id;
|
|
883
833
|
}
|
|
884
|
-
destructor() {
|
|
885
|
-
super.destructor();
|
|
886
|
-
const prev = this.cache;
|
|
887
|
-
if ($mol_owning_check(this, prev)) {
|
|
888
|
-
prev.destructor();
|
|
889
|
-
}
|
|
890
|
-
if (this.persistent()) {
|
|
891
|
-
if (this.pub_from === 0) {
|
|
892
|
-
;
|
|
893
|
-
(this.host ?? this.task)[this.field()] = null;
|
|
894
|
-
}
|
|
895
|
-
else {
|
|
896
|
-
;
|
|
897
|
-
(this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
834
|
plan() {
|
|
902
835
|
$mol_wire_fiber.planning.push(this);
|
|
903
836
|
$mol_wire_fiber.plan();
|
|
@@ -930,15 +863,6 @@ var $;
|
|
|
930
863
|
else
|
|
931
864
|
super.emit(quant);
|
|
932
865
|
}
|
|
933
|
-
commit() {
|
|
934
|
-
if (this.persistent())
|
|
935
|
-
return;
|
|
936
|
-
super.commit();
|
|
937
|
-
if (this.host instanceof $mol_wire_fiber) {
|
|
938
|
-
this.host.put(this.cache);
|
|
939
|
-
}
|
|
940
|
-
this.destructor();
|
|
941
|
-
}
|
|
942
866
|
refresh() {
|
|
943
867
|
if (this.cursor === $mol_wire_cursor.fresh)
|
|
944
868
|
return;
|
|
@@ -957,7 +881,17 @@ var $;
|
|
|
957
881
|
const bu = this.track_on();
|
|
958
882
|
let result;
|
|
959
883
|
try {
|
|
960
|
-
|
|
884
|
+
switch (this.pub_from) {
|
|
885
|
+
case 0:
|
|
886
|
+
result = this.task.call(this.host);
|
|
887
|
+
break;
|
|
888
|
+
case 1:
|
|
889
|
+
result = this.task.call(this.host, this[0]);
|
|
890
|
+
break;
|
|
891
|
+
default:
|
|
892
|
+
result = this.task.call(this.host, ...this.slice(0, this.pub_from));
|
|
893
|
+
break;
|
|
894
|
+
}
|
|
961
895
|
if (result instanceof Promise) {
|
|
962
896
|
const put = (res) => {
|
|
963
897
|
if (this.cache === result)
|
|
@@ -995,7 +929,7 @@ var $;
|
|
|
995
929
|
prev.destructor();
|
|
996
930
|
}
|
|
997
931
|
this.cache = next;
|
|
998
|
-
if (this
|
|
932
|
+
if (this instanceof $mol_wire_fiber_persist && $mol_owning_catch(this, next)) {
|
|
999
933
|
try {
|
|
1000
934
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
1001
935
|
}
|
|
@@ -1010,19 +944,19 @@ var $;
|
|
|
1010
944
|
this.cursor = $mol_wire_cursor.fresh;
|
|
1011
945
|
if (next instanceof Promise)
|
|
1012
946
|
return next;
|
|
1013
|
-
if (this
|
|
947
|
+
if (this instanceof $mol_wire_fiber_persist) {
|
|
1014
948
|
this.commit_pubs();
|
|
1015
949
|
}
|
|
1016
950
|
else {
|
|
1017
951
|
if (this.sub_empty) {
|
|
1018
952
|
this.commit();
|
|
1019
953
|
}
|
|
954
|
+
else {
|
|
955
|
+
this.commit_pubs();
|
|
956
|
+
}
|
|
1020
957
|
}
|
|
1021
958
|
return next;
|
|
1022
959
|
}
|
|
1023
|
-
recall(...args) {
|
|
1024
|
-
return this.task.call(this.host, ...args);
|
|
1025
|
-
}
|
|
1026
960
|
sync() {
|
|
1027
961
|
if (!$mol_wire_fiber.warm) {
|
|
1028
962
|
return this.result();
|
|
@@ -1052,10 +986,88 @@ var $;
|
|
|
1052
986
|
}
|
|
1053
987
|
}
|
|
1054
988
|
}
|
|
989
|
+
$.$mol_wire_fiber = $mol_wire_fiber;
|
|
990
|
+
class $mol_wire_fiber_temp extends $mol_wire_fiber {
|
|
991
|
+
static getter(task) {
|
|
992
|
+
return function $mol_wire_fiber_temp_get(host, args) {
|
|
993
|
+
const existen = $mol_wire_auto()?.track_next();
|
|
994
|
+
reuse: if (existen) {
|
|
995
|
+
if (!(existen instanceof $mol_wire_fiber_temp))
|
|
996
|
+
break reuse;
|
|
997
|
+
if (existen.host !== host)
|
|
998
|
+
break reuse;
|
|
999
|
+
if (existen.task !== task)
|
|
1000
|
+
break reuse;
|
|
1001
|
+
if (!$mol_compare_deep(existen.args, args))
|
|
1002
|
+
break reuse;
|
|
1003
|
+
return existen;
|
|
1004
|
+
}
|
|
1005
|
+
return new $mol_wire_fiber_temp(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
commit() {
|
|
1009
|
+
super.commit();
|
|
1010
|
+
this.destructor();
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
$.$mol_wire_fiber_temp = $mol_wire_fiber_temp;
|
|
1014
|
+
class $mol_wire_fiber_persist extends $mol_wire_fiber {
|
|
1015
|
+
static getter(task, keys) {
|
|
1016
|
+
const field = task.name + '()';
|
|
1017
|
+
if (keys) {
|
|
1018
|
+
return function $mol_wire_fiber_persist_get(host, args) {
|
|
1019
|
+
let dict, key, fiber;
|
|
1020
|
+
key = `${host?.[Symbol.toStringTag] ?? host}.${task.name}(${args.map(v => $mol_key(v)).join(',')})`;
|
|
1021
|
+
dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1022
|
+
if (dict) {
|
|
1023
|
+
const existen = dict.get(key);
|
|
1024
|
+
if (existen)
|
|
1025
|
+
return existen;
|
|
1026
|
+
}
|
|
1027
|
+
else {
|
|
1028
|
+
dict = (host ?? task)[field] = new Map();
|
|
1029
|
+
}
|
|
1030
|
+
fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
|
|
1031
|
+
dict.set(key, fiber);
|
|
1032
|
+
return fiber;
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
else {
|
|
1036
|
+
return function $mol_wire_fiber_persist_get(host, args) {
|
|
1037
|
+
const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1038
|
+
if (existen)
|
|
1039
|
+
return existen;
|
|
1040
|
+
const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
|
|
1041
|
+
const fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
|
|
1042
|
+
(host ?? task)[field] = fiber;
|
|
1043
|
+
return fiber;
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
recall(...args) {
|
|
1048
|
+
return this.put(this.task.call(this.host, ...args));
|
|
1049
|
+
}
|
|
1050
|
+
commit() { }
|
|
1051
|
+
destructor() {
|
|
1052
|
+
super.destructor();
|
|
1053
|
+
const prev = this.cache;
|
|
1054
|
+
if ($mol_owning_check(this, prev)) {
|
|
1055
|
+
prev.destructor();
|
|
1056
|
+
}
|
|
1057
|
+
if (this.pub_from === 0) {
|
|
1058
|
+
;
|
|
1059
|
+
(this.host ?? this.task)[this.field()] = null;
|
|
1060
|
+
}
|
|
1061
|
+
else {
|
|
1062
|
+
;
|
|
1063
|
+
(this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1055
1067
|
__decorate([
|
|
1056
1068
|
$mol_wire_method
|
|
1057
|
-
], $
|
|
1058
|
-
$.$
|
|
1069
|
+
], $mol_wire_fiber_persist.prototype, "recall", null);
|
|
1070
|
+
$.$mol_wire_fiber_persist = $mol_wire_fiber_persist;
|
|
1059
1071
|
})($ || ($ = {}));
|
|
1060
1072
|
//mol/wire/fiber/fiber.ts
|
|
1061
1073
|
;
|
|
@@ -1096,8 +1108,9 @@ var $;
|
|
|
1096
1108
|
const val = obj[field];
|
|
1097
1109
|
if (typeof val !== 'function')
|
|
1098
1110
|
return val;
|
|
1111
|
+
const temp = $mol_wire_fiber_temp.getter(val);
|
|
1099
1112
|
return function $mol_wire_sync(...args) {
|
|
1100
|
-
const fiber =
|
|
1113
|
+
const fiber = temp(obj, args);
|
|
1101
1114
|
return fiber.sync();
|
|
1102
1115
|
};
|
|
1103
1116
|
}
|
|
@@ -1117,9 +1130,10 @@ var $;
|
|
|
1117
1130
|
if (typeof val !== 'function')
|
|
1118
1131
|
return val;
|
|
1119
1132
|
let fiber;
|
|
1133
|
+
const temp = $mol_wire_fiber_temp.getter(val);
|
|
1120
1134
|
return function $mol_wire_async(...args) {
|
|
1121
1135
|
fiber?.destructor();
|
|
1122
|
-
fiber =
|
|
1136
|
+
fiber = temp(obj, args);
|
|
1123
1137
|
return fiber.async();
|
|
1124
1138
|
};
|
|
1125
1139
|
}
|
|
@@ -1184,7 +1198,7 @@ var $;
|
|
|
1184
1198
|
$.$mol_wire_mem = $mol_wire_mem;
|
|
1185
1199
|
function $mol_wire_mem_func(keys) {
|
|
1186
1200
|
return (func) => {
|
|
1187
|
-
const persist = $
|
|
1201
|
+
const persist = $mol_wire_fiber_persist.getter(func, keys);
|
|
1188
1202
|
const wrapper = function (...args) {
|
|
1189
1203
|
let atom = persist(this, args.slice(0, keys));
|
|
1190
1204
|
if (args.length <= keys || args[keys] === undefined)
|
|
@@ -1226,7 +1240,7 @@ var $;
|
|
|
1226
1240
|
if (!descr)
|
|
1227
1241
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
1228
1242
|
const _get = descr?.get || $mol_const(descr?.value);
|
|
1229
|
-
const persist = $
|
|
1243
|
+
const persist = $mol_wire_fiber_persist.getter(_get, 0);
|
|
1230
1244
|
const _set = descr?.set || function (next) {
|
|
1231
1245
|
persist(this, []).put(next);
|
|
1232
1246
|
};
|
|
@@ -1237,8 +1251,9 @@ var $;
|
|
|
1237
1251
|
function get() {
|
|
1238
1252
|
return persist(this, []).sync();
|
|
1239
1253
|
}
|
|
1254
|
+
const temp = $mol_wire_fiber_temp.getter(_set);
|
|
1240
1255
|
function set(next) {
|
|
1241
|
-
|
|
1256
|
+
temp(this, [next]).sync();
|
|
1242
1257
|
}
|
|
1243
1258
|
Object.defineProperty(get, 'name', { value: _get.name + '$' });
|
|
1244
1259
|
Object.defineProperty(set, 'name', { value: _set.name + '@' });
|