mol_wire_lib 1.0.89 → 1.0.92
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/node.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) {
|
|
@@ -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 = [];
|
|
@@ -862,8 +816,7 @@ var $;
|
|
|
862
816
|
return this.cache;
|
|
863
817
|
}
|
|
864
818
|
persistent() {
|
|
865
|
-
|
|
866
|
-
return id[id.length - 2] !== '#';
|
|
819
|
+
return this instanceof $mol_wire_fiber_persist;
|
|
867
820
|
}
|
|
868
821
|
field() {
|
|
869
822
|
return this.task.name + '()';
|
|
@@ -883,7 +836,7 @@ var $;
|
|
|
883
836
|
if ($mol_owning_check(this, prev)) {
|
|
884
837
|
prev.destructor();
|
|
885
838
|
}
|
|
886
|
-
if (this
|
|
839
|
+
if (this instanceof $mol_wire_fiber_persist) {
|
|
887
840
|
if (this.pub_from === 0) {
|
|
888
841
|
;
|
|
889
842
|
(this.host ?? this.task)[this.field()] = null;
|
|
@@ -927,7 +880,7 @@ var $;
|
|
|
927
880
|
super.emit(quant);
|
|
928
881
|
}
|
|
929
882
|
commit() {
|
|
930
|
-
if (this
|
|
883
|
+
if (this instanceof $mol_wire_fiber_persist)
|
|
931
884
|
return;
|
|
932
885
|
super.commit();
|
|
933
886
|
if (this.host instanceof $mol_wire_fiber) {
|
|
@@ -953,7 +906,17 @@ var $;
|
|
|
953
906
|
const bu = this.track_on();
|
|
954
907
|
let result;
|
|
955
908
|
try {
|
|
956
|
-
|
|
909
|
+
switch (this.pub_from) {
|
|
910
|
+
case 0:
|
|
911
|
+
result = this.task.call(this.host);
|
|
912
|
+
break;
|
|
913
|
+
case 1:
|
|
914
|
+
result = this.task.call(this.host, this[0]);
|
|
915
|
+
break;
|
|
916
|
+
default:
|
|
917
|
+
result = this.task.call(this.host, ...this.slice(0, this.pub_from));
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
957
920
|
if (result instanceof Promise) {
|
|
958
921
|
const put = (res) => {
|
|
959
922
|
if (this.cache === result)
|
|
@@ -991,7 +954,7 @@ var $;
|
|
|
991
954
|
prev.destructor();
|
|
992
955
|
}
|
|
993
956
|
this.cache = next;
|
|
994
|
-
if (this
|
|
957
|
+
if (this instanceof $mol_wire_fiber_persist && $mol_owning_catch(this, next)) {
|
|
995
958
|
try {
|
|
996
959
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
997
960
|
}
|
|
@@ -1006,19 +969,19 @@ var $;
|
|
|
1006
969
|
this.cursor = $mol_wire_cursor.fresh;
|
|
1007
970
|
if (next instanceof Promise)
|
|
1008
971
|
return next;
|
|
1009
|
-
if (this
|
|
972
|
+
if (this instanceof $mol_wire_fiber_persist) {
|
|
1010
973
|
this.commit_pubs();
|
|
1011
974
|
}
|
|
1012
975
|
else {
|
|
1013
976
|
if (this.sub_empty) {
|
|
1014
977
|
this.commit();
|
|
1015
978
|
}
|
|
979
|
+
else {
|
|
980
|
+
this.commit_pubs();
|
|
981
|
+
}
|
|
1016
982
|
}
|
|
1017
983
|
return next;
|
|
1018
984
|
}
|
|
1019
|
-
recall(...args) {
|
|
1020
|
-
return this.task.call(this.host, ...args);
|
|
1021
|
-
}
|
|
1022
985
|
sync() {
|
|
1023
986
|
if (!$mol_wire_fiber.warm) {
|
|
1024
987
|
return this.result();
|
|
@@ -1048,10 +1011,68 @@ var $;
|
|
|
1048
1011
|
}
|
|
1049
1012
|
}
|
|
1050
1013
|
}
|
|
1014
|
+
$.$mol_wire_fiber = $mol_wire_fiber;
|
|
1015
|
+
class $mol_wire_fiber_temp extends $mol_wire_fiber {
|
|
1016
|
+
static getter(task) {
|
|
1017
|
+
return function $mol_wire_fiber_temp_get(host, args) {
|
|
1018
|
+
const existen = $mol_wire_auto()?.track_next();
|
|
1019
|
+
reuse: if (existen) {
|
|
1020
|
+
if (!(existen instanceof $mol_wire_fiber_temp))
|
|
1021
|
+
break reuse;
|
|
1022
|
+
if (existen.host !== host)
|
|
1023
|
+
break reuse;
|
|
1024
|
+
if (existen.task !== task)
|
|
1025
|
+
break reuse;
|
|
1026
|
+
if (!$mol_compare_deep(existen.args, args))
|
|
1027
|
+
break reuse;
|
|
1028
|
+
return existen;
|
|
1029
|
+
}
|
|
1030
|
+
return new $mol_wire_fiber_temp(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
$.$mol_wire_fiber_temp = $mol_wire_fiber_temp;
|
|
1035
|
+
class $mol_wire_fiber_persist extends $mol_wire_fiber {
|
|
1036
|
+
static getter(task, keys) {
|
|
1037
|
+
const field = task.name + '()';
|
|
1038
|
+
if (keys) {
|
|
1039
|
+
return function $mol_wire_fiber_persist_get(host, args) {
|
|
1040
|
+
let dict, key, fiber;
|
|
1041
|
+
key = `${host?.[Symbol.toStringTag] ?? host}.${task.name}(${args.map(v => $mol_key(v)).join(',')})`;
|
|
1042
|
+
dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1043
|
+
if (dict) {
|
|
1044
|
+
const existen = dict.get(key);
|
|
1045
|
+
if (existen)
|
|
1046
|
+
return existen;
|
|
1047
|
+
}
|
|
1048
|
+
else {
|
|
1049
|
+
dict = (host ?? task)[field] = new Map();
|
|
1050
|
+
}
|
|
1051
|
+
fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
|
|
1052
|
+
dict.set(key, fiber);
|
|
1053
|
+
return fiber;
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
else {
|
|
1057
|
+
return function $mol_wire_fiber_persist_get(host, args) {
|
|
1058
|
+
const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
1059
|
+
if (existen)
|
|
1060
|
+
return existen;
|
|
1061
|
+
const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
|
|
1062
|
+
const fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
|
|
1063
|
+
(host ?? task)[field] = fiber;
|
|
1064
|
+
return fiber;
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
recall(...args) {
|
|
1069
|
+
return this.task.call(this.host, ...args);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1051
1072
|
__decorate([
|
|
1052
1073
|
$mol_wire_method
|
|
1053
|
-
], $
|
|
1054
|
-
$.$
|
|
1074
|
+
], $mol_wire_fiber_persist.prototype, "recall", null);
|
|
1075
|
+
$.$mol_wire_fiber_persist = $mol_wire_fiber_persist;
|
|
1055
1076
|
})($ || ($ = {}));
|
|
1056
1077
|
//mol/wire/fiber/fiber.ts
|
|
1057
1078
|
;
|
|
@@ -1092,8 +1113,9 @@ var $;
|
|
|
1092
1113
|
const val = obj[field];
|
|
1093
1114
|
if (typeof val !== 'function')
|
|
1094
1115
|
return val;
|
|
1116
|
+
const temp = $mol_wire_fiber_temp.getter(val);
|
|
1095
1117
|
return function $mol_wire_sync(...args) {
|
|
1096
|
-
const fiber =
|
|
1118
|
+
const fiber = temp(obj, args);
|
|
1097
1119
|
return fiber.sync();
|
|
1098
1120
|
};
|
|
1099
1121
|
}
|
|
@@ -1113,9 +1135,10 @@ var $;
|
|
|
1113
1135
|
if (typeof val !== 'function')
|
|
1114
1136
|
return val;
|
|
1115
1137
|
let fiber;
|
|
1138
|
+
const temp = $mol_wire_fiber_temp.getter(val);
|
|
1116
1139
|
return function $mol_wire_async(...args) {
|
|
1117
1140
|
fiber?.destructor();
|
|
1118
|
-
fiber =
|
|
1141
|
+
fiber = temp(obj, args);
|
|
1119
1142
|
return fiber.async();
|
|
1120
1143
|
};
|
|
1121
1144
|
}
|
|
@@ -1180,7 +1203,7 @@ var $;
|
|
|
1180
1203
|
$.$mol_wire_mem = $mol_wire_mem;
|
|
1181
1204
|
function $mol_wire_mem_func(keys) {
|
|
1182
1205
|
return (func) => {
|
|
1183
|
-
const persist = $
|
|
1206
|
+
const persist = $mol_wire_fiber_persist.getter(func, keys);
|
|
1184
1207
|
const wrapper = function (...args) {
|
|
1185
1208
|
let atom = persist(this, args.slice(0, keys));
|
|
1186
1209
|
if (args.length <= keys || args[keys] === undefined)
|
|
@@ -1222,7 +1245,7 @@ var $;
|
|
|
1222
1245
|
if (!descr)
|
|
1223
1246
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
1224
1247
|
const _get = descr?.get || $mol_const(descr?.value);
|
|
1225
|
-
const persist = $
|
|
1248
|
+
const persist = $mol_wire_fiber_persist.getter(_get, 0);
|
|
1226
1249
|
const _set = descr?.set || function (next) {
|
|
1227
1250
|
persist(this, []).put(next);
|
|
1228
1251
|
};
|
|
@@ -1233,8 +1256,9 @@ var $;
|
|
|
1233
1256
|
function get() {
|
|
1234
1257
|
return persist(this, []).sync();
|
|
1235
1258
|
}
|
|
1259
|
+
const temp = $mol_wire_fiber_temp.getter(_set);
|
|
1236
1260
|
function set(next) {
|
|
1237
|
-
|
|
1261
|
+
temp(this, [next]).sync();
|
|
1238
1262
|
}
|
|
1239
1263
|
Object.defineProperty(get, 'name', { value: _get.name + '$' });
|
|
1240
1264
|
Object.defineProperty(set, 'name', { value: _set.name + '@' });
|