mol_wire_lib 1.0.90 → 1.0.91
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 +22 -18
- package/node.deps.json +1 -1
- package/node.esm.js +266 -242
- package/node.esm.js.map +1 -1
- package/node.js +266 -242
- package/node.js.map +1 -1
- package/node.test.js +284 -290
- package/node.test.js.map +1 -1
- package/package.json +5 -5
- package/web.d.ts +22 -18
- package/web.deps.json +1 -1
- package/web.esm.js +266 -242
- package/web.esm.js.map +1 -1
- package/web.js +266 -242
- package/web.js.map +1 -1
- package/web.test.js +18 -48
- 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 = [];
|
|
@@ -866,8 +820,7 @@ var $;
|
|
|
866
820
|
return this.cache;
|
|
867
821
|
}
|
|
868
822
|
persistent() {
|
|
869
|
-
|
|
870
|
-
return id[id.length - 2] !== '#';
|
|
823
|
+
return this instanceof $mol_wire_fiber_persist;
|
|
871
824
|
}
|
|
872
825
|
field() {
|
|
873
826
|
return this.task.name + '()';
|
|
@@ -887,7 +840,7 @@ var $;
|
|
|
887
840
|
if ($mol_owning_check(this, prev)) {
|
|
888
841
|
prev.destructor();
|
|
889
842
|
}
|
|
890
|
-
if (this
|
|
843
|
+
if (this instanceof $mol_wire_fiber_persist) {
|
|
891
844
|
if (this.pub_from === 0) {
|
|
892
845
|
;
|
|
893
846
|
(this.host ?? this.task)[this.field()] = null;
|
|
@@ -931,7 +884,7 @@ var $;
|
|
|
931
884
|
super.emit(quant);
|
|
932
885
|
}
|
|
933
886
|
commit() {
|
|
934
|
-
if (this
|
|
887
|
+
if (this instanceof $mol_wire_fiber_persist)
|
|
935
888
|
return;
|
|
936
889
|
super.commit();
|
|
937
890
|
if (this.host instanceof $mol_wire_fiber) {
|
|
@@ -957,7 +910,17 @@ var $;
|
|
|
957
910
|
const bu = this.track_on();
|
|
958
911
|
let result;
|
|
959
912
|
try {
|
|
960
|
-
|
|
913
|
+
switch (this.pub_from) {
|
|
914
|
+
case 0:
|
|
915
|
+
result = this.task.call(this.host);
|
|
916
|
+
break;
|
|
917
|
+
case 1:
|
|
918
|
+
result = this.task.call(this.host, this[0]);
|
|
919
|
+
break;
|
|
920
|
+
default:
|
|
921
|
+
result = this.task.call(this.host, ...this.slice(0, this.pub_from));
|
|
922
|
+
break;
|
|
923
|
+
}
|
|
961
924
|
if (result instanceof Promise) {
|
|
962
925
|
const put = (res) => {
|
|
963
926
|
if (this.cache === result)
|
|
@@ -995,7 +958,7 @@ var $;
|
|
|
995
958
|
prev.destructor();
|
|
996
959
|
}
|
|
997
960
|
this.cache = next;
|
|
998
|
-
if (this
|
|
961
|
+
if (this instanceof $mol_wire_fiber_persist && $mol_owning_catch(this, next)) {
|
|
999
962
|
try {
|
|
1000
963
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
1001
964
|
}
|
|
@@ -1010,19 +973,19 @@ var $;
|
|
|
1010
973
|
this.cursor = $mol_wire_cursor.fresh;
|
|
1011
974
|
if (next instanceof Promise)
|
|
1012
975
|
return next;
|
|
1013
|
-
if (this
|
|
976
|
+
if (this instanceof $mol_wire_fiber_persist) {
|
|
1014
977
|
this.commit_pubs();
|
|
1015
978
|
}
|
|
1016
979
|
else {
|
|
1017
980
|
if (this.sub_empty) {
|
|
1018
981
|
this.commit();
|
|
1019
982
|
}
|
|
983
|
+
else {
|
|
984
|
+
this.commit_pubs();
|
|
985
|
+
}
|
|
1020
986
|
}
|
|
1021
987
|
return next;
|
|
1022
988
|
}
|
|
1023
|
-
recall(...args) {
|
|
1024
|
-
return this.task.call(this.host, ...args);
|
|
1025
|
-
}
|
|
1026
989
|
sync() {
|
|
1027
990
|
if (!$mol_wire_fiber.warm) {
|
|
1028
991
|
return this.result();
|
|
@@ -1052,10 +1015,68 @@ var $;
|
|
|
1052
1015
|
}
|
|
1053
1016
|
}
|
|
1054
1017
|
}
|
|
1018
|
+
$.$mol_wire_fiber = $mol_wire_fiber;
|
|
1019
|
+
class $mol_wire_fiber_temp extends $mol_wire_fiber {
|
|
1020
|
+
static getter(task) {
|
|
1021
|
+
return function $mol_wire_fiber_temp_get(host, args) {
|
|
1022
|
+
const existen = $mol_wire_auto()?.track_next();
|
|
1023
|
+
reuse: if (existen) {
|
|
1024
|
+
if (!(existen instanceof $mol_wire_fiber_temp))
|
|
1025
|
+
break reuse;
|
|
1026
|
+
if (existen.host !== host)
|
|
1027
|
+
break reuse;
|
|
1028
|
+
if (existen.task !== task)
|
|
1029
|
+
break reuse;
|
|
1030
|
+
if (!$mol_compare_deep(existen.args, args))
|
|
1031
|
+
break reuse;
|
|
1032
|
+
return existen;
|
|
1033
|
+
}
|
|
1034
|
+
return new $mol_wire_fiber_temp(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
$.$mol_wire_fiber_temp = $mol_wire_fiber_temp;
|
|
1039
|
+
class $mol_wire_fiber_persist extends $mol_wire_fiber {
|
|
1040
|
+
static getter(task, keys) {
|
|
1041
|
+
const field = task.name + '()';
|
|
1042
|
+
if (keys) {
|
|
1043
|
+
return function $mol_wire_fiber_persist_get(host, args) {
|
|
1044
|
+
let dict, key, fiber;
|
|
1045
|
+
key = `${host?.[Symbol.toStringTag] ?? host}.${task.name}(${args.map(v => $mol_key(v)).join(',')})`;
|
|
1046
|
+
dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1047
|
+
if (dict) {
|
|
1048
|
+
const existen = dict.get(key);
|
|
1049
|
+
if (existen)
|
|
1050
|
+
return existen;
|
|
1051
|
+
}
|
|
1052
|
+
else {
|
|
1053
|
+
dict = (host ?? task)[field] = new Map();
|
|
1054
|
+
}
|
|
1055
|
+
fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
|
|
1056
|
+
dict.set(key, fiber);
|
|
1057
|
+
return fiber;
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
else {
|
|
1061
|
+
return function $mol_wire_fiber_persist_get(host, args) {
|
|
1062
|
+
const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1063
|
+
if (existen)
|
|
1064
|
+
return existen;
|
|
1065
|
+
const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
|
|
1066
|
+
const fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
|
|
1067
|
+
(host ?? task)[field] = fiber;
|
|
1068
|
+
return fiber;
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
recall(...args) {
|
|
1073
|
+
return this.task.call(this.host, ...args);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1055
1076
|
__decorate([
|
|
1056
1077
|
$mol_wire_method
|
|
1057
|
-
], $
|
|
1058
|
-
$.$
|
|
1078
|
+
], $mol_wire_fiber_persist.prototype, "recall", null);
|
|
1079
|
+
$.$mol_wire_fiber_persist = $mol_wire_fiber_persist;
|
|
1059
1080
|
})($ || ($ = {}));
|
|
1060
1081
|
//mol/wire/fiber/fiber.ts
|
|
1061
1082
|
;
|
|
@@ -1096,8 +1117,9 @@ var $;
|
|
|
1096
1117
|
const val = obj[field];
|
|
1097
1118
|
if (typeof val !== 'function')
|
|
1098
1119
|
return val;
|
|
1120
|
+
const temp = $mol_wire_fiber_temp.getter(val);
|
|
1099
1121
|
return function $mol_wire_sync(...args) {
|
|
1100
|
-
const fiber =
|
|
1122
|
+
const fiber = temp(obj, args);
|
|
1101
1123
|
return fiber.sync();
|
|
1102
1124
|
};
|
|
1103
1125
|
}
|
|
@@ -1117,9 +1139,10 @@ var $;
|
|
|
1117
1139
|
if (typeof val !== 'function')
|
|
1118
1140
|
return val;
|
|
1119
1141
|
let fiber;
|
|
1142
|
+
const temp = $mol_wire_fiber_temp.getter(val);
|
|
1120
1143
|
return function $mol_wire_async(...args) {
|
|
1121
1144
|
fiber?.destructor();
|
|
1122
|
-
fiber =
|
|
1145
|
+
fiber = temp(obj, args);
|
|
1123
1146
|
return fiber.async();
|
|
1124
1147
|
};
|
|
1125
1148
|
}
|
|
@@ -1184,7 +1207,7 @@ var $;
|
|
|
1184
1207
|
$.$mol_wire_mem = $mol_wire_mem;
|
|
1185
1208
|
function $mol_wire_mem_func(keys) {
|
|
1186
1209
|
return (func) => {
|
|
1187
|
-
const persist = $
|
|
1210
|
+
const persist = $mol_wire_fiber_persist.getter(func, keys);
|
|
1188
1211
|
const wrapper = function (...args) {
|
|
1189
1212
|
let atom = persist(this, args.slice(0, keys));
|
|
1190
1213
|
if (args.length <= keys || args[keys] === undefined)
|
|
@@ -1226,7 +1249,7 @@ var $;
|
|
|
1226
1249
|
if (!descr)
|
|
1227
1250
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
1228
1251
|
const _get = descr?.get || $mol_const(descr?.value);
|
|
1229
|
-
const persist = $
|
|
1252
|
+
const persist = $mol_wire_fiber_persist.getter(_get, 0);
|
|
1230
1253
|
const _set = descr?.set || function (next) {
|
|
1231
1254
|
persist(this, []).put(next);
|
|
1232
1255
|
};
|
|
@@ -1237,8 +1260,9 @@ var $;
|
|
|
1237
1260
|
function get() {
|
|
1238
1261
|
return persist(this, []).sync();
|
|
1239
1262
|
}
|
|
1263
|
+
const temp = $mol_wire_fiber_temp.getter(_set);
|
|
1240
1264
|
function set(next) {
|
|
1241
|
-
|
|
1265
|
+
temp(this, [next]).sync();
|
|
1242
1266
|
}
|
|
1243
1267
|
Object.defineProperty(get, 'name', { value: _get.name + '$' });
|
|
1244
1268
|
Object.defineProperty(set, 'name', { value: _set.name + '@' });
|