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/node.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) {
|
|
@@ -741,6 +564,183 @@ var $;
|
|
|
741
564
|
;
|
|
742
565
|
"use strict";
|
|
743
566
|
var $;
|
|
567
|
+
(function ($) {
|
|
568
|
+
$.$mol_compare_deep_cache = new WeakMap();
|
|
569
|
+
function $mol_compare_deep(left, right) {
|
|
570
|
+
if (Object.is(left, right))
|
|
571
|
+
return true;
|
|
572
|
+
if (left === null)
|
|
573
|
+
return false;
|
|
574
|
+
if (right === null)
|
|
575
|
+
return false;
|
|
576
|
+
if (typeof left !== 'object')
|
|
577
|
+
return false;
|
|
578
|
+
if (typeof right !== 'object')
|
|
579
|
+
return false;
|
|
580
|
+
const left_proto = Reflect.getPrototypeOf(left);
|
|
581
|
+
const right_proto = Reflect.getPrototypeOf(right);
|
|
582
|
+
if (left_proto !== right_proto)
|
|
583
|
+
return false;
|
|
584
|
+
if (left instanceof Boolean)
|
|
585
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
586
|
+
if (left instanceof Number)
|
|
587
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
588
|
+
if (left instanceof String)
|
|
589
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
590
|
+
if (left instanceof Date)
|
|
591
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
592
|
+
if (left instanceof RegExp)
|
|
593
|
+
return left.source === right['source'] && left.flags === right['flags'];
|
|
594
|
+
let left_cache = $.$mol_compare_deep_cache.get(left);
|
|
595
|
+
if (left_cache) {
|
|
596
|
+
const right_cache = left_cache.get(right);
|
|
597
|
+
if (typeof right_cache === 'boolean')
|
|
598
|
+
return right_cache;
|
|
599
|
+
}
|
|
600
|
+
else {
|
|
601
|
+
left_cache = new WeakMap([[right, true]]);
|
|
602
|
+
$.$mol_compare_deep_cache.set(left, left_cache);
|
|
603
|
+
}
|
|
604
|
+
let result;
|
|
605
|
+
try {
|
|
606
|
+
if (left_proto && !Reflect.getPrototypeOf(left_proto))
|
|
607
|
+
result = compare_pojo(left, right);
|
|
608
|
+
else if (Array.isArray(left))
|
|
609
|
+
result = compare_array(left, right);
|
|
610
|
+
else if (left instanceof Set)
|
|
611
|
+
result = compare_set(left, right);
|
|
612
|
+
else if (left instanceof Map)
|
|
613
|
+
result = compare_map(left, right);
|
|
614
|
+
else if (left instanceof Error)
|
|
615
|
+
result = left.stack === right.stack;
|
|
616
|
+
else if (ArrayBuffer.isView(left))
|
|
617
|
+
result = compare_buffer(left, right);
|
|
618
|
+
else if (Symbol.toPrimitive in left)
|
|
619
|
+
result = compare_primitive(left, right);
|
|
620
|
+
else
|
|
621
|
+
result = false;
|
|
622
|
+
}
|
|
623
|
+
finally {
|
|
624
|
+
left_cache.set(right, result);
|
|
625
|
+
}
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
628
|
+
$.$mol_compare_deep = $mol_compare_deep;
|
|
629
|
+
function compare_array(left, right) {
|
|
630
|
+
const len = left.length;
|
|
631
|
+
if (len !== right.length)
|
|
632
|
+
return false;
|
|
633
|
+
for (let i = 0; i < len; ++i) {
|
|
634
|
+
if (!$mol_compare_deep(left[i], right[i]))
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
function compare_buffer(left, right) {
|
|
640
|
+
const len = left.byteLength;
|
|
641
|
+
if (len !== right.byteLength)
|
|
642
|
+
return false;
|
|
643
|
+
for (let i = 0; i < len; ++i) {
|
|
644
|
+
if (left[i] !== right[i])
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
function compare_iterator(left, right, compare) {
|
|
650
|
+
while (true) {
|
|
651
|
+
const left_next = left.next();
|
|
652
|
+
const right_next = right.next();
|
|
653
|
+
if (left_next.done !== right_next.done)
|
|
654
|
+
return false;
|
|
655
|
+
if (left_next.done)
|
|
656
|
+
break;
|
|
657
|
+
if (!compare(left_next.value, right_next.value))
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
function compare_set(left, right) {
|
|
663
|
+
if (left.size !== right.size)
|
|
664
|
+
return false;
|
|
665
|
+
return compare_iterator(left.values(), right.values(), $mol_compare_deep);
|
|
666
|
+
}
|
|
667
|
+
function compare_map(left, right) {
|
|
668
|
+
if (left.size !== right.size)
|
|
669
|
+
return false;
|
|
670
|
+
return compare_iterator(left.keys(), right.keys(), Object.is)
|
|
671
|
+
&& compare_iterator(left.values(), right.values(), $mol_compare_deep);
|
|
672
|
+
}
|
|
673
|
+
function compare_pojo(left, right) {
|
|
674
|
+
const left_keys = Object.getOwnPropertyNames(left);
|
|
675
|
+
const right_keys = Object.getOwnPropertyNames(right);
|
|
676
|
+
if (left_keys.length !== right_keys.length)
|
|
677
|
+
return false;
|
|
678
|
+
for (let key of left_keys) {
|
|
679
|
+
if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
|
|
680
|
+
return false;
|
|
681
|
+
}
|
|
682
|
+
return true;
|
|
683
|
+
}
|
|
684
|
+
function compare_primitive(left, right) {
|
|
685
|
+
return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
|
|
686
|
+
}
|
|
687
|
+
})($ || ($ = {}));
|
|
688
|
+
//mol/compare/deep/deep.ts
|
|
689
|
+
;
|
|
690
|
+
"use strict";
|
|
691
|
+
var $;
|
|
692
|
+
(function ($) {
|
|
693
|
+
function $mol_guid(length = 8, exists = () => false) {
|
|
694
|
+
for (;;) {
|
|
695
|
+
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
696
|
+
if (exists(id))
|
|
697
|
+
continue;
|
|
698
|
+
return id;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
$.$mol_guid = $mol_guid;
|
|
702
|
+
})($ || ($ = {}));
|
|
703
|
+
//mol/guid/guid.ts
|
|
704
|
+
;
|
|
705
|
+
"use strict";
|
|
706
|
+
var $;
|
|
707
|
+
(function ($) {
|
|
708
|
+
$.$mol_key_store = new WeakMap();
|
|
709
|
+
function $mol_key(value) {
|
|
710
|
+
if (!value)
|
|
711
|
+
return JSON.stringify(value);
|
|
712
|
+
if (typeof value !== 'object' && typeof value !== 'function')
|
|
713
|
+
return JSON.stringify(value);
|
|
714
|
+
return JSON.stringify(value, (field, value) => {
|
|
715
|
+
if (!value)
|
|
716
|
+
return value;
|
|
717
|
+
if (typeof value !== 'object' && typeof value !== 'function')
|
|
718
|
+
return value;
|
|
719
|
+
if (Array.isArray(value))
|
|
720
|
+
return value;
|
|
721
|
+
const proto = Reflect.getPrototypeOf(value);
|
|
722
|
+
if (!proto)
|
|
723
|
+
return value;
|
|
724
|
+
if (Reflect.getPrototypeOf(proto) === null)
|
|
725
|
+
return value;
|
|
726
|
+
if ('toJSON' in value)
|
|
727
|
+
return value;
|
|
728
|
+
if (value instanceof RegExp)
|
|
729
|
+
return value.toString();
|
|
730
|
+
let key = $.$mol_key_store.get(value);
|
|
731
|
+
if (key)
|
|
732
|
+
return key;
|
|
733
|
+
key = $mol_guid();
|
|
734
|
+
$.$mol_key_store.set(value, key);
|
|
735
|
+
return key;
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
$.$mol_key = $mol_key;
|
|
739
|
+
})($ || ($ = {}));
|
|
740
|
+
//mol/key/key.ts
|
|
741
|
+
;
|
|
742
|
+
"use strict";
|
|
743
|
+
var $;
|
|
744
744
|
(function ($) {
|
|
745
745
|
function $mol_wire_method(host, field, descr) {
|
|
746
746
|
if (!descr)
|
|
@@ -750,8 +750,9 @@ var $;
|
|
|
750
750
|
if (typeof sup[field] === 'function') {
|
|
751
751
|
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
|
752
752
|
}
|
|
753
|
+
const temp = $mol_wire_fiber_temp.getter(orig);
|
|
753
754
|
const value = function (...args) {
|
|
754
|
-
const fiber =
|
|
755
|
+
const fiber = temp(this ?? null, args);
|
|
755
756
|
return fiber.sync();
|
|
756
757
|
};
|
|
757
758
|
Object.defineProperty(value, 'name', { value: orig.name + ' ' });
|
|
@@ -771,53 +772,6 @@ var $;
|
|
|
771
772
|
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
|
772
773
|
task;
|
|
773
774
|
host;
|
|
774
|
-
static temp(host, task, ...args) {
|
|
775
|
-
const existen = $mol_wire_auto()?.track_next();
|
|
776
|
-
reuse: if (existen) {
|
|
777
|
-
if (!(existen instanceof $mol_wire_fiber))
|
|
778
|
-
break reuse;
|
|
779
|
-
if (existen.host !== host)
|
|
780
|
-
break reuse;
|
|
781
|
-
if (existen.task !== task)
|
|
782
|
-
break reuse;
|
|
783
|
-
if (!$mol_compare_deep(existen.args, args))
|
|
784
|
-
break reuse;
|
|
785
|
-
return existen;
|
|
786
|
-
}
|
|
787
|
-
return new this(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
|
|
788
|
-
}
|
|
789
|
-
static persist(task, keys) {
|
|
790
|
-
const field = task.name + '()';
|
|
791
|
-
if (keys) {
|
|
792
|
-
return function $mol_wire_fiber_persist(host, args) {
|
|
793
|
-
let dict, key, fiber;
|
|
794
|
-
key = `${host?.[Symbol.toStringTag] ?? host}.${task.name}(${args.map(v => $mol_key(v)).join(',')})`;
|
|
795
|
-
dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
796
|
-
if (dict) {
|
|
797
|
-
const existen = dict.get(key);
|
|
798
|
-
if (existen)
|
|
799
|
-
return existen;
|
|
800
|
-
}
|
|
801
|
-
else {
|
|
802
|
-
dict = (host ?? task)[field] = new Map();
|
|
803
|
-
}
|
|
804
|
-
fiber = new $mol_wire_fiber(key, task, host, ...args);
|
|
805
|
-
dict.set(key, fiber);
|
|
806
|
-
return fiber;
|
|
807
|
-
};
|
|
808
|
-
}
|
|
809
|
-
else {
|
|
810
|
-
return function $mol_wire_fiber_persist(host, args) {
|
|
811
|
-
const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
812
|
-
if (existen)
|
|
813
|
-
return existen;
|
|
814
|
-
const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
|
|
815
|
-
const fiber = new $mol_wire_fiber(key, task, host, ...args);
|
|
816
|
-
(host ?? task)[field] = fiber;
|
|
817
|
-
return fiber;
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
775
|
static warm = true;
|
|
822
776
|
static planning = [];
|
|
823
777
|
static reaping = [];
|
|
@@ -861,10 +815,6 @@ var $;
|
|
|
861
815
|
return;
|
|
862
816
|
return this.cache;
|
|
863
817
|
}
|
|
864
|
-
persistent() {
|
|
865
|
-
const id = this[Symbol.toStringTag];
|
|
866
|
-
return id[id.length - 2] !== '#';
|
|
867
|
-
}
|
|
868
818
|
field() {
|
|
869
819
|
return this.task.name + '()';
|
|
870
820
|
}
|
|
@@ -877,23 +827,6 @@ var $;
|
|
|
877
827
|
this.pub_from = this.sub_from = args.length;
|
|
878
828
|
this[Symbol.toStringTag] = id;
|
|
879
829
|
}
|
|
880
|
-
destructor() {
|
|
881
|
-
super.destructor();
|
|
882
|
-
const prev = this.cache;
|
|
883
|
-
if ($mol_owning_check(this, prev)) {
|
|
884
|
-
prev.destructor();
|
|
885
|
-
}
|
|
886
|
-
if (this.persistent()) {
|
|
887
|
-
if (this.pub_from === 0) {
|
|
888
|
-
;
|
|
889
|
-
(this.host ?? this.task)[this.field()] = null;
|
|
890
|
-
}
|
|
891
|
-
else {
|
|
892
|
-
;
|
|
893
|
-
(this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
830
|
plan() {
|
|
898
831
|
$mol_wire_fiber.planning.push(this);
|
|
899
832
|
$mol_wire_fiber.plan();
|
|
@@ -926,15 +859,6 @@ var $;
|
|
|
926
859
|
else
|
|
927
860
|
super.emit(quant);
|
|
928
861
|
}
|
|
929
|
-
commit() {
|
|
930
|
-
if (this.persistent())
|
|
931
|
-
return;
|
|
932
|
-
super.commit();
|
|
933
|
-
if (this.host instanceof $mol_wire_fiber) {
|
|
934
|
-
this.host.put(this.cache);
|
|
935
|
-
}
|
|
936
|
-
this.destructor();
|
|
937
|
-
}
|
|
938
862
|
refresh() {
|
|
939
863
|
if (this.cursor === $mol_wire_cursor.fresh)
|
|
940
864
|
return;
|
|
@@ -953,7 +877,17 @@ var $;
|
|
|
953
877
|
const bu = this.track_on();
|
|
954
878
|
let result;
|
|
955
879
|
try {
|
|
956
|
-
|
|
880
|
+
switch (this.pub_from) {
|
|
881
|
+
case 0:
|
|
882
|
+
result = this.task.call(this.host);
|
|
883
|
+
break;
|
|
884
|
+
case 1:
|
|
885
|
+
result = this.task.call(this.host, this[0]);
|
|
886
|
+
break;
|
|
887
|
+
default:
|
|
888
|
+
result = this.task.call(this.host, ...this.slice(0, this.pub_from));
|
|
889
|
+
break;
|
|
890
|
+
}
|
|
957
891
|
if (result instanceof Promise) {
|
|
958
892
|
const put = (res) => {
|
|
959
893
|
if (this.cache === result)
|
|
@@ -991,7 +925,7 @@ var $;
|
|
|
991
925
|
prev.destructor();
|
|
992
926
|
}
|
|
993
927
|
this.cache = next;
|
|
994
|
-
if (this
|
|
928
|
+
if (this instanceof $mol_wire_fiber_persist && $mol_owning_catch(this, next)) {
|
|
995
929
|
try {
|
|
996
930
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
997
931
|
}
|
|
@@ -1006,19 +940,19 @@ var $;
|
|
|
1006
940
|
this.cursor = $mol_wire_cursor.fresh;
|
|
1007
941
|
if (next instanceof Promise)
|
|
1008
942
|
return next;
|
|
1009
|
-
if (this
|
|
943
|
+
if (this instanceof $mol_wire_fiber_persist) {
|
|
1010
944
|
this.commit_pubs();
|
|
1011
945
|
}
|
|
1012
946
|
else {
|
|
1013
947
|
if (this.sub_empty) {
|
|
1014
948
|
this.commit();
|
|
1015
949
|
}
|
|
950
|
+
else {
|
|
951
|
+
this.commit_pubs();
|
|
952
|
+
}
|
|
1016
953
|
}
|
|
1017
954
|
return next;
|
|
1018
955
|
}
|
|
1019
|
-
recall(...args) {
|
|
1020
|
-
return this.task.call(this.host, ...args);
|
|
1021
|
-
}
|
|
1022
956
|
sync() {
|
|
1023
957
|
if (!$mol_wire_fiber.warm) {
|
|
1024
958
|
return this.result();
|
|
@@ -1048,10 +982,88 @@ var $;
|
|
|
1048
982
|
}
|
|
1049
983
|
}
|
|
1050
984
|
}
|
|
985
|
+
$.$mol_wire_fiber = $mol_wire_fiber;
|
|
986
|
+
class $mol_wire_fiber_temp extends $mol_wire_fiber {
|
|
987
|
+
static getter(task) {
|
|
988
|
+
return function $mol_wire_fiber_temp_get(host, args) {
|
|
989
|
+
const existen = $mol_wire_auto()?.track_next();
|
|
990
|
+
reuse: if (existen) {
|
|
991
|
+
if (!(existen instanceof $mol_wire_fiber_temp))
|
|
992
|
+
break reuse;
|
|
993
|
+
if (existen.host !== host)
|
|
994
|
+
break reuse;
|
|
995
|
+
if (existen.task !== task)
|
|
996
|
+
break reuse;
|
|
997
|
+
if (!$mol_compare_deep(existen.args, args))
|
|
998
|
+
break reuse;
|
|
999
|
+
return existen;
|
|
1000
|
+
}
|
|
1001
|
+
return new $mol_wire_fiber_temp(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
commit() {
|
|
1005
|
+
super.commit();
|
|
1006
|
+
this.destructor();
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
$.$mol_wire_fiber_temp = $mol_wire_fiber_temp;
|
|
1010
|
+
class $mol_wire_fiber_persist extends $mol_wire_fiber {
|
|
1011
|
+
static getter(task, keys) {
|
|
1012
|
+
const field = task.name + '()';
|
|
1013
|
+
if (keys) {
|
|
1014
|
+
return function $mol_wire_fiber_persist_get(host, args) {
|
|
1015
|
+
let dict, key, fiber;
|
|
1016
|
+
key = `${host?.[Symbol.toStringTag] ?? host}.${task.name}(${args.map(v => $mol_key(v)).join(',')})`;
|
|
1017
|
+
dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1018
|
+
if (dict) {
|
|
1019
|
+
const existen = dict.get(key);
|
|
1020
|
+
if (existen)
|
|
1021
|
+
return existen;
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
1024
|
+
dict = (host ?? task)[field] = new Map();
|
|
1025
|
+
}
|
|
1026
|
+
fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
|
|
1027
|
+
dict.set(key, fiber);
|
|
1028
|
+
return fiber;
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
else {
|
|
1032
|
+
return function $mol_wire_fiber_persist_get(host, args) {
|
|
1033
|
+
const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1034
|
+
if (existen)
|
|
1035
|
+
return existen;
|
|
1036
|
+
const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
|
|
1037
|
+
const fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
|
|
1038
|
+
(host ?? task)[field] = fiber;
|
|
1039
|
+
return fiber;
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
recall(...args) {
|
|
1044
|
+
return this.put(this.task.call(this.host, ...args));
|
|
1045
|
+
}
|
|
1046
|
+
commit() { }
|
|
1047
|
+
destructor() {
|
|
1048
|
+
super.destructor();
|
|
1049
|
+
const prev = this.cache;
|
|
1050
|
+
if ($mol_owning_check(this, prev)) {
|
|
1051
|
+
prev.destructor();
|
|
1052
|
+
}
|
|
1053
|
+
if (this.pub_from === 0) {
|
|
1054
|
+
;
|
|
1055
|
+
(this.host ?? this.task)[this.field()] = null;
|
|
1056
|
+
}
|
|
1057
|
+
else {
|
|
1058
|
+
;
|
|
1059
|
+
(this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1051
1063
|
__decorate([
|
|
1052
1064
|
$mol_wire_method
|
|
1053
|
-
], $
|
|
1054
|
-
$.$
|
|
1065
|
+
], $mol_wire_fiber_persist.prototype, "recall", null);
|
|
1066
|
+
$.$mol_wire_fiber_persist = $mol_wire_fiber_persist;
|
|
1055
1067
|
})($ || ($ = {}));
|
|
1056
1068
|
//mol/wire/fiber/fiber.ts
|
|
1057
1069
|
;
|
|
@@ -1092,8 +1104,9 @@ var $;
|
|
|
1092
1104
|
const val = obj[field];
|
|
1093
1105
|
if (typeof val !== 'function')
|
|
1094
1106
|
return val;
|
|
1107
|
+
const temp = $mol_wire_fiber_temp.getter(val);
|
|
1095
1108
|
return function $mol_wire_sync(...args) {
|
|
1096
|
-
const fiber =
|
|
1109
|
+
const fiber = temp(obj, args);
|
|
1097
1110
|
return fiber.sync();
|
|
1098
1111
|
};
|
|
1099
1112
|
}
|
|
@@ -1113,9 +1126,10 @@ var $;
|
|
|
1113
1126
|
if (typeof val !== 'function')
|
|
1114
1127
|
return val;
|
|
1115
1128
|
let fiber;
|
|
1129
|
+
const temp = $mol_wire_fiber_temp.getter(val);
|
|
1116
1130
|
return function $mol_wire_async(...args) {
|
|
1117
1131
|
fiber?.destructor();
|
|
1118
|
-
fiber =
|
|
1132
|
+
fiber = temp(obj, args);
|
|
1119
1133
|
return fiber.async();
|
|
1120
1134
|
};
|
|
1121
1135
|
}
|
|
@@ -1180,7 +1194,7 @@ var $;
|
|
|
1180
1194
|
$.$mol_wire_mem = $mol_wire_mem;
|
|
1181
1195
|
function $mol_wire_mem_func(keys) {
|
|
1182
1196
|
return (func) => {
|
|
1183
|
-
const persist = $
|
|
1197
|
+
const persist = $mol_wire_fiber_persist.getter(func, keys);
|
|
1184
1198
|
const wrapper = function (...args) {
|
|
1185
1199
|
let atom = persist(this, args.slice(0, keys));
|
|
1186
1200
|
if (args.length <= keys || args[keys] === undefined)
|
|
@@ -1222,7 +1236,7 @@ var $;
|
|
|
1222
1236
|
if (!descr)
|
|
1223
1237
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
1224
1238
|
const _get = descr?.get || $mol_const(descr?.value);
|
|
1225
|
-
const persist = $
|
|
1239
|
+
const persist = $mol_wire_fiber_persist.getter(_get, 0);
|
|
1226
1240
|
const _set = descr?.set || function (next) {
|
|
1227
1241
|
persist(this, []).put(next);
|
|
1228
1242
|
};
|
|
@@ -1233,8 +1247,9 @@ var $;
|
|
|
1233
1247
|
function get() {
|
|
1234
1248
|
return persist(this, []).sync();
|
|
1235
1249
|
}
|
|
1250
|
+
const temp = $mol_wire_fiber_temp.getter(_set);
|
|
1236
1251
|
function set(next) {
|
|
1237
|
-
|
|
1252
|
+
temp(this, [next]).sync();
|
|
1238
1253
|
}
|
|
1239
1254
|
Object.defineProperty(get, 'name', { value: _get.name + '$' });
|
|
1240
1255
|
Object.defineProperty(set, 'name', { value: _set.name + '@' });
|