mol_wire_lib 1.0.84 → 1.0.87
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 +9 -7
- package/node.deps.json +1 -1
- package/node.esm.js +35 -24
- package/node.esm.js.map +1 -1
- package/node.js +35 -24
- package/node.js.map +1 -1
- package/node.test.js +104 -117
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +9 -7
- package/web.deps.json +1 -1
- package/web.esm.js +35 -24
- package/web.esm.js.map +1 -1
- package/web.js +35 -24
- package/web.js.map +1 -1
- package/web.test.js +69 -93
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -84,8 +84,8 @@ var $;
|
|
|
84
84
|
promote() {
|
|
85
85
|
$mol_wire_auto()?.track_next(this);
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
refresh() { }
|
|
88
|
+
commit() { }
|
|
89
89
|
emit(quant = $mol_wire_cursor.stale) {
|
|
90
90
|
for (let i = this.sub_from; i < this.length; i += 2) {
|
|
91
91
|
;
|
|
@@ -287,7 +287,7 @@ var $;
|
|
|
287
287
|
}
|
|
288
288
|
for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
|
|
289
289
|
const pub = this[cursor];
|
|
290
|
-
pub.
|
|
290
|
+
pub.refresh();
|
|
291
291
|
}
|
|
292
292
|
this.cursor = $mol_wire_cursor.fresh;
|
|
293
293
|
}
|
|
@@ -330,6 +330,16 @@ var $;
|
|
|
330
330
|
}
|
|
331
331
|
this.sub_from = this.cursor;
|
|
332
332
|
}
|
|
333
|
+
commit() {
|
|
334
|
+
this.commit_pubs();
|
|
335
|
+
}
|
|
336
|
+
commit_pubs() {
|
|
337
|
+
const limit = this.cursor < 0 ? this.sub_from : this.cursor;
|
|
338
|
+
for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
|
|
339
|
+
const pub = this[cursor];
|
|
340
|
+
pub?.commit();
|
|
341
|
+
}
|
|
342
|
+
}
|
|
333
343
|
absorb(quant = $mol_wire_cursor.stale) {
|
|
334
344
|
if (this.cursor === $mol_wire_cursor.final)
|
|
335
345
|
return;
|
|
@@ -820,7 +830,7 @@ var $;
|
|
|
820
830
|
while (this.planning.length) {
|
|
821
831
|
const fibers = this.planning.splice(0, this.planning.length);
|
|
822
832
|
for (const fiber of fibers) {
|
|
823
|
-
fiber.
|
|
833
|
+
fiber.refresh();
|
|
824
834
|
}
|
|
825
835
|
}
|
|
826
836
|
while (this.reaping.length) {
|
|
@@ -836,14 +846,14 @@ var $;
|
|
|
836
846
|
get args() {
|
|
837
847
|
return this.slice(0, this.pub_from);
|
|
838
848
|
}
|
|
839
|
-
|
|
849
|
+
result() {
|
|
840
850
|
if (this.cache instanceof Promise)
|
|
841
851
|
return;
|
|
842
852
|
if (this.cache instanceof Error)
|
|
843
853
|
return;
|
|
844
854
|
return this.cache;
|
|
845
855
|
}
|
|
846
|
-
|
|
856
|
+
persistent() {
|
|
847
857
|
const id = this[Symbol.toStringTag];
|
|
848
858
|
return id[id.length - 2] !== '#';
|
|
849
859
|
}
|
|
@@ -865,7 +875,7 @@ var $;
|
|
|
865
875
|
if ($mol_owning_check(this, prev)) {
|
|
866
876
|
prev.destructor();
|
|
867
877
|
}
|
|
868
|
-
if (this.
|
|
878
|
+
if (this.persistent()) {
|
|
869
879
|
if (this.pub_from === 0) {
|
|
870
880
|
;
|
|
871
881
|
(this.host ?? this.task)[this.field()] = null;
|
|
@@ -908,12 +918,16 @@ var $;
|
|
|
908
918
|
else
|
|
909
919
|
super.emit(quant);
|
|
910
920
|
}
|
|
911
|
-
|
|
912
|
-
if (this.
|
|
921
|
+
commit() {
|
|
922
|
+
if (this.persistent())
|
|
913
923
|
return;
|
|
924
|
+
super.commit();
|
|
925
|
+
if (this.host instanceof $mol_wire_fiber) {
|
|
926
|
+
this.host.put(this.cache);
|
|
927
|
+
}
|
|
914
928
|
this.destructor();
|
|
915
929
|
}
|
|
916
|
-
|
|
930
|
+
refresh() {
|
|
917
931
|
if (this.cursor === $mol_wire_cursor.fresh)
|
|
918
932
|
return;
|
|
919
933
|
if (this.cursor === $mol_wire_cursor.final)
|
|
@@ -921,7 +935,7 @@ var $;
|
|
|
921
935
|
check: if (this.cursor === $mol_wire_cursor.doubt) {
|
|
922
936
|
for (let i = this.pub_from; i < this.sub_from; i += 2) {
|
|
923
937
|
;
|
|
924
|
-
this[i]?.
|
|
938
|
+
this[i]?.refresh();
|
|
925
939
|
if (this.cursor !== $mol_wire_cursor.doubt)
|
|
926
940
|
break check;
|
|
927
941
|
}
|
|
@@ -969,7 +983,7 @@ var $;
|
|
|
969
983
|
prev.destructor();
|
|
970
984
|
}
|
|
971
985
|
this.cache = next;
|
|
972
|
-
if (this.
|
|
986
|
+
if (this.persistent() && $mol_owning_catch(this, next)) {
|
|
973
987
|
try {
|
|
974
988
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
975
989
|
}
|
|
@@ -984,28 +998,25 @@ var $;
|
|
|
984
998
|
this.cursor = $mol_wire_cursor.fresh;
|
|
985
999
|
if (next instanceof Promise)
|
|
986
1000
|
return next;
|
|
987
|
-
if (this.
|
|
988
|
-
|
|
989
|
-
const pub = this[cursor];
|
|
990
|
-
pub?.down();
|
|
991
|
-
}
|
|
1001
|
+
if (this.persistent()) {
|
|
1002
|
+
this.commit_pubs();
|
|
992
1003
|
}
|
|
993
1004
|
else {
|
|
994
|
-
this.
|
|
995
|
-
|
|
996
|
-
|
|
1005
|
+
if (this.sub_empty) {
|
|
1006
|
+
this.commit();
|
|
1007
|
+
}
|
|
997
1008
|
}
|
|
998
1009
|
return next;
|
|
999
1010
|
}
|
|
1000
1011
|
recall(...args) {
|
|
1001
|
-
return this.
|
|
1012
|
+
return this.task.call(this.host, ...args);
|
|
1002
1013
|
}
|
|
1003
1014
|
sync() {
|
|
1004
1015
|
if (!$mol_wire_fiber.warm) {
|
|
1005
|
-
return this.result;
|
|
1016
|
+
return this.result();
|
|
1006
1017
|
}
|
|
1007
1018
|
this.promote();
|
|
1008
|
-
this.
|
|
1019
|
+
this.refresh();
|
|
1009
1020
|
if (this.cache instanceof Error) {
|
|
1010
1021
|
return $mol_fail_hidden(this.cache);
|
|
1011
1022
|
}
|
|
@@ -1016,7 +1027,7 @@ var $;
|
|
|
1016
1027
|
}
|
|
1017
1028
|
async async() {
|
|
1018
1029
|
while (true) {
|
|
1019
|
-
this.
|
|
1030
|
+
this.refresh();
|
|
1020
1031
|
if (this.cache instanceof Error) {
|
|
1021
1032
|
$mol_fail_hidden(this.cache);
|
|
1022
1033
|
}
|
|
@@ -2362,19 +2373,13 @@ var $;
|
|
|
2362
2373
|
static value(next = 1) {
|
|
2363
2374
|
return next + 1;
|
|
2364
2375
|
}
|
|
2365
|
-
static test() {
|
|
2366
|
-
$mol_assert_equal(App.value(), 2);
|
|
2367
|
-
App.value(2);
|
|
2368
|
-
$mol_assert_equal(App.value(), 3);
|
|
2369
|
-
}
|
|
2370
2376
|
}
|
|
2371
2377
|
__decorate([
|
|
2372
2378
|
$mol_wire_mem(0)
|
|
2373
2379
|
], App, "value", null);
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
App.test();
|
|
2380
|
+
$mol_assert_equal(App.value(), 2);
|
|
2381
|
+
App.value(2);
|
|
2382
|
+
$mol_assert_equal(App.value(), 3);
|
|
2378
2383
|
},
|
|
2379
2384
|
'Mem overrides mem'($) {
|
|
2380
2385
|
class Base extends $mol_object2 {
|
|
@@ -2398,19 +2403,13 @@ var $;
|
|
|
2398
2403
|
static value(next) {
|
|
2399
2404
|
return super.value(next) * 3;
|
|
2400
2405
|
}
|
|
2401
|
-
static test() {
|
|
2402
|
-
$mol_assert_equal(this.value(), 9);
|
|
2403
|
-
$mol_assert_equal(this.value(5), 21);
|
|
2404
|
-
$mol_assert_equal(this.value(), 21);
|
|
2405
|
-
}
|
|
2406
2406
|
}
|
|
2407
2407
|
__decorate([
|
|
2408
2408
|
$mol_wire_mem(0)
|
|
2409
2409
|
], App, "value", null);
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
App.test();
|
|
2410
|
+
$mol_assert_equal(App.value(), 9);
|
|
2411
|
+
$mol_assert_equal(App.value(5), 21);
|
|
2412
|
+
$mol_assert_equal(App.value(), 21);
|
|
2414
2413
|
},
|
|
2415
2414
|
'Auto recalculation of cached values'($) {
|
|
2416
2415
|
class App extends $mol_object2 {
|
|
@@ -2424,12 +2423,6 @@ var $;
|
|
|
2424
2423
|
static zzz() {
|
|
2425
2424
|
return this.yyy() + 1;
|
|
2426
2425
|
}
|
|
2427
|
-
static test() {
|
|
2428
|
-
$mol_assert_equal(App.yyy(), 2);
|
|
2429
|
-
$mol_assert_equal(App.zzz(), 3);
|
|
2430
|
-
App.xxx(5);
|
|
2431
|
-
$mol_assert_equal(App.zzz(), 7);
|
|
2432
|
-
}
|
|
2433
2426
|
}
|
|
2434
2427
|
__decorate([
|
|
2435
2428
|
$mol_wire_mem(0)
|
|
@@ -2440,10 +2433,10 @@ var $;
|
|
|
2440
2433
|
__decorate([
|
|
2441
2434
|
$mol_wire_mem(0)
|
|
2442
2435
|
], App, "zzz", null);
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
App.
|
|
2436
|
+
$mol_assert_equal(App.yyy(), 2);
|
|
2437
|
+
$mol_assert_equal(App.zzz(), 3);
|
|
2438
|
+
App.xxx(5);
|
|
2439
|
+
$mol_assert_equal(App.zzz(), 7);
|
|
2447
2440
|
},
|
|
2448
2441
|
'Skip recalculation when actually no dependency changes'($) {
|
|
2449
2442
|
const log = [];
|
|
@@ -2461,13 +2454,6 @@ var $;
|
|
|
2461
2454
|
log.push('zzz');
|
|
2462
2455
|
return this.yyy()[0] + 1;
|
|
2463
2456
|
}
|
|
2464
|
-
static test() {
|
|
2465
|
-
App.zzz();
|
|
2466
|
-
$mol_assert_like(log, ['zzz', 'yyy', 'xxx']);
|
|
2467
|
-
App.xxx(5);
|
|
2468
|
-
App.zzz();
|
|
2469
|
-
$mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
|
|
2470
|
-
}
|
|
2471
2457
|
}
|
|
2472
2458
|
__decorate([
|
|
2473
2459
|
$mol_wire_mem(0)
|
|
@@ -2478,10 +2464,12 @@ var $;
|
|
|
2478
2464
|
__decorate([
|
|
2479
2465
|
$mol_wire_mem(0)
|
|
2480
2466
|
], App, "zzz", null);
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2467
|
+
App.zzz();
|
|
2468
|
+
$mol_assert_like(log, ['zzz', 'yyy', 'xxx']);
|
|
2469
|
+
App.xxx(5);
|
|
2470
|
+
$mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx']);
|
|
2471
|
+
App.zzz();
|
|
2472
|
+
$mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
|
|
2485
2473
|
},
|
|
2486
2474
|
'Flow: Auto'($) {
|
|
2487
2475
|
class App extends $mol_object2 {
|
|
@@ -2526,13 +2514,6 @@ var $;
|
|
|
2526
2514
|
static bar() {
|
|
2527
2515
|
return { ...this.foo(), count: ++counter };
|
|
2528
2516
|
}
|
|
2529
|
-
static test() {
|
|
2530
|
-
$mol_assert_like(App.bar(), { numbs: [1], count: 1 });
|
|
2531
|
-
App.foo({ numbs: [1] });
|
|
2532
|
-
$mol_assert_like(App.bar(), { numbs: [1], count: 1 });
|
|
2533
|
-
App.foo({ numbs: [2] });
|
|
2534
|
-
$mol_assert_like(App.bar(), { numbs: [2], count: 2 });
|
|
2535
|
-
}
|
|
2536
2517
|
}
|
|
2537
2518
|
__decorate([
|
|
2538
2519
|
$mol_wire_mem(0)
|
|
@@ -2540,10 +2521,11 @@ var $;
|
|
|
2540
2521
|
__decorate([
|
|
2541
2522
|
$mol_wire_mem(0)
|
|
2542
2523
|
], App, "bar", null);
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
App.
|
|
2524
|
+
$mol_assert_like(App.bar(), { numbs: [1], count: 1 });
|
|
2525
|
+
App.foo({ numbs: [1] });
|
|
2526
|
+
$mol_assert_like(App.bar(), { numbs: [1], count: 1 });
|
|
2527
|
+
App.foo({ numbs: [2] });
|
|
2528
|
+
$mol_assert_like(App.bar(), { numbs: [2], count: 2 });
|
|
2547
2529
|
},
|
|
2548
2530
|
'Cycle: Fail'($) {
|
|
2549
2531
|
class App extends $mol_object2 {
|
|
@@ -2581,13 +2563,6 @@ var $;
|
|
|
2581
2563
|
static slow(next) {
|
|
2582
2564
|
return this.store(next);
|
|
2583
2565
|
}
|
|
2584
|
-
static test() {
|
|
2585
|
-
App.fast();
|
|
2586
|
-
$mol_assert_equal(App.slow(666), 666);
|
|
2587
|
-
$mol_assert_equal(App.fast(), App.slow(), 666);
|
|
2588
|
-
App.store(777);
|
|
2589
|
-
$mol_assert_equal(App.fast(), App.slow(), 777);
|
|
2590
|
-
}
|
|
2591
2566
|
}
|
|
2592
2567
|
__decorate([
|
|
2593
2568
|
$mol_wire_mem(0)
|
|
@@ -2598,10 +2573,11 @@ var $;
|
|
|
2598
2573
|
__decorate([
|
|
2599
2574
|
$mol_wire_mem(0)
|
|
2600
2575
|
], App, "slow", null);
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
App.
|
|
2576
|
+
App.fast();
|
|
2577
|
+
$mol_assert_equal(App.slow(666), 666);
|
|
2578
|
+
$mol_assert_equal(App.fast(), App.slow(), 666);
|
|
2579
|
+
App.store(777);
|
|
2580
|
+
$mol_assert_equal(App.fast(), App.slow(), 777);
|
|
2605
2581
|
},
|
|
2606
2582
|
'Actions inside invariant'($) {
|
|
2607
2583
|
class App extends $mol_object2 {
|
|
@@ -2618,11 +2594,6 @@ var $;
|
|
|
2618
2594
|
this.count(count + 1);
|
|
2619
2595
|
return count + 1;
|
|
2620
2596
|
}
|
|
2621
|
-
static test() {
|
|
2622
|
-
$mol_assert_like(App.res(), 1);
|
|
2623
|
-
App.count(5);
|
|
2624
|
-
$mol_assert_like(App.res(), 6);
|
|
2625
|
-
}
|
|
2626
2597
|
}
|
|
2627
2598
|
__decorate([
|
|
2628
2599
|
$mol_wire_mem(0)
|
|
@@ -2633,10 +2604,40 @@ var $;
|
|
|
2633
2604
|
__decorate([
|
|
2634
2605
|
$mol_wire_mem(0)
|
|
2635
2606
|
], App, "res", null);
|
|
2607
|
+
$mol_assert_like(App.res(), 1);
|
|
2608
|
+
App.count(5);
|
|
2609
|
+
$mol_assert_like(App.res(), 6);
|
|
2610
|
+
},
|
|
2611
|
+
async 'Toggle with async'($) {
|
|
2612
|
+
class App extends $mol_object2 {
|
|
2613
|
+
static $ = $;
|
|
2614
|
+
static checked(next = false) {
|
|
2615
|
+
$$.$mol_wait_timeout(0);
|
|
2616
|
+
return next;
|
|
2617
|
+
}
|
|
2618
|
+
static toggle() {
|
|
2619
|
+
const prev = this.checked();
|
|
2620
|
+
$mol_assert_unique(this.checked(!prev), prev);
|
|
2621
|
+
$mol_assert_equal(this.checked(), prev);
|
|
2622
|
+
}
|
|
2623
|
+
static res() {
|
|
2624
|
+
$mol_wire_solid();
|
|
2625
|
+
return this.checked();
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
__decorate([
|
|
2629
|
+
$mol_wire_mem(0)
|
|
2630
|
+
], App, "checked", null);
|
|
2636
2631
|
__decorate([
|
|
2637
2632
|
$mol_wire_method
|
|
2638
|
-
], App, "
|
|
2639
|
-
|
|
2633
|
+
], App, "toggle", null);
|
|
2634
|
+
__decorate([
|
|
2635
|
+
$mol_wire_mem(0)
|
|
2636
|
+
], App, "res", null);
|
|
2637
|
+
const app = $mol_wire_async(App);
|
|
2638
|
+
$mol_assert_equal(await app.res(), false);
|
|
2639
|
+
await app.toggle();
|
|
2640
|
+
$mol_assert_equal(await app.res(), true);
|
|
2640
2641
|
},
|
|
2641
2642
|
'Restore after error'($) {
|
|
2642
2643
|
class App extends $mol_object2 {
|
|
@@ -2807,9 +2808,6 @@ var $;
|
|
|
2807
2808
|
];
|
|
2808
2809
|
}
|
|
2809
2810
|
static test() {
|
|
2810
|
-
$mol_assert_like(this.user_names(), ['jin', 'john']);
|
|
2811
|
-
Team.user_name('jin', 'JIN');
|
|
2812
|
-
$mol_assert_like(this.user_names(), ['JIN', 'john']);
|
|
2813
2811
|
}
|
|
2814
2812
|
}
|
|
2815
2813
|
__decorate([
|
|
@@ -2821,7 +2819,9 @@ var $;
|
|
|
2821
2819
|
__decorate([
|
|
2822
2820
|
$mol_wire_method
|
|
2823
2821
|
], Team, "test", null);
|
|
2824
|
-
Team.
|
|
2822
|
+
$mol_assert_like(Team.user_names(), ['jin', 'john']);
|
|
2823
|
+
Team.user_name('jin', 'JIN');
|
|
2824
|
+
$mol_assert_like(Team.user_names(), ['JIN', 'john']);
|
|
2825
2825
|
},
|
|
2826
2826
|
'Memoize by single complex key'($) {
|
|
2827
2827
|
class Map extends $mol_object2 {
|
|
@@ -2898,21 +2898,15 @@ var $;
|
|
|
2898
2898
|
++this.sums;
|
|
2899
2899
|
return this.value(index - 1) + this.value(index - 2);
|
|
2900
2900
|
}
|
|
2901
|
-
static test() {
|
|
2902
|
-
$mol_assert_equal(this.value(4), 5);
|
|
2903
|
-
$mol_assert_equal(this.sums, 3);
|
|
2904
|
-
this.value(1, 2);
|
|
2905
|
-
$mol_assert_equal(this.value(4), 8);
|
|
2906
|
-
$mol_assert_equal(this.sums, 6);
|
|
2907
|
-
}
|
|
2908
2901
|
}
|
|
2909
2902
|
__decorate([
|
|
2910
2903
|
$mol_wire_mem(1)
|
|
2911
2904
|
], Fib, "value", null);
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
Fib.
|
|
2905
|
+
$mol_assert_equal(Fib.value(4), 5);
|
|
2906
|
+
$mol_assert_equal(Fib.sums, 3);
|
|
2907
|
+
Fib.value(1, 2);
|
|
2908
|
+
$mol_assert_equal(Fib.value(4), 8);
|
|
2909
|
+
$mol_assert_equal(Fib.sums, 6);
|
|
2916
2910
|
},
|
|
2917
2911
|
'Unsubscribe from temp pubs on complete'($) {
|
|
2918
2912
|
class Random extends $mol_object2 {
|
|
@@ -2927,12 +2921,6 @@ var $;
|
|
|
2927
2921
|
this.resets();
|
|
2928
2922
|
return this.seed();
|
|
2929
2923
|
}
|
|
2930
|
-
static test() {
|
|
2931
|
-
const first = this.value();
|
|
2932
|
-
this.resets(null);
|
|
2933
|
-
const second = this.value();
|
|
2934
|
-
$mol_assert_unique(first, second);
|
|
2935
|
-
}
|
|
2936
2924
|
}
|
|
2937
2925
|
__decorate([
|
|
2938
2926
|
$mol_wire_method
|
|
@@ -2943,10 +2931,9 @@ var $;
|
|
|
2943
2931
|
__decorate([
|
|
2944
2932
|
$mol_wire_mem(0)
|
|
2945
2933
|
], Random, "value", null);
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
Random.test();
|
|
2934
|
+
const first = Random.value();
|
|
2935
|
+
Random.resets(null);
|
|
2936
|
+
$mol_assert_unique(Random.value(), first);
|
|
2950
2937
|
},
|
|
2951
2938
|
});
|
|
2952
2939
|
})($ || ($ = {}));
|