mol_wire_lib 1.0.1469 → 1.0.1470

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.meta.tree CHANGED
@@ -36,6 +36,7 @@
36
36
  include \/mol/wire/patch
37
37
  include \/mol/wire/let
38
38
  include \/mol/wire/set
39
+ include \/mol/wire/proxy
39
40
  include \/mol/wire/dict
40
41
  include \/mol/wait/timeout
41
42
  include \/mol/wire/log
package/node.mjs CHANGED
@@ -28,6 +28,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
28
28
  var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
29
29
  $.$$ = $
30
30
 
31
+ ;
32
+ "use strict";
33
+ var $;
34
+ (function ($) {
35
+ function $mol_guid(length = 8, exists = () => false) {
36
+ for (;;) {
37
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
38
+ if (exists(id))
39
+ continue;
40
+ return id;
41
+ }
42
+ }
43
+ $.$mol_guid = $mol_guid;
44
+ })($ || ($ = {}));
45
+
31
46
  ;
32
47
  "use strict";
33
48
  var $;
@@ -56,6 +71,11 @@ var $;
56
71
  var $;
57
72
  (function ($) {
58
73
  class $mol_wire_pub extends Object {
74
+ constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
75
+ super();
76
+ this[Symbol.toStringTag] = id;
77
+ }
78
+ [Symbol.toStringTag];
59
79
  data = [];
60
80
  static get [Symbol.species]() {
61
81
  return Array;
@@ -649,7 +669,6 @@ var $;
649
669
  }
650
670
  }
651
671
  }
652
- [Symbol.toStringTag];
653
672
  cache = undefined;
654
673
  get args() {
655
674
  return this.data.slice(0, this.pub_from);
@@ -668,13 +687,12 @@ var $;
668
687
  return this.task.name + '()';
669
688
  }
670
689
  constructor(id, task, host, args) {
671
- super();
690
+ super(id);
672
691
  this.task = task;
673
692
  this.host = host;
674
693
  if (args)
675
694
  this.data.push(...args);
676
695
  this.pub_from = this.sub_from = args?.length ?? 0;
677
- this[Symbol.toStringTag] = id;
678
696
  }
679
697
  plan() {
680
698
  $mol_wire_fiber.planning.add(this);
@@ -1602,21 +1620,6 @@ var $;
1602
1620
  $.$mol_wire_task = $mol_wire_task;
1603
1621
  })($ || ($ = {}));
1604
1622
 
1605
- ;
1606
- "use strict";
1607
- var $;
1608
- (function ($) {
1609
- function $mol_guid(length = 8, exists = () => false) {
1610
- for (;;) {
1611
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1612
- if (exists(id))
1613
- continue;
1614
- return id;
1615
- }
1616
- }
1617
- $.$mol_guid = $mol_guid;
1618
- })($ || ($ = {}));
1619
-
1620
1623
  ;
1621
1624
  "use strict";
1622
1625
  var $;
@@ -2374,6 +2377,81 @@ var $;
2374
2377
  $.$mol_wire_set = $mol_wire_set;
2375
2378
  })($ || ($ = {}));
2376
2379
 
2380
+ ;
2381
+ "use strict";
2382
+ var $;
2383
+ (function ($) {
2384
+ const pubs = new WeakMap();
2385
+ function $mol_wire_proxy_pub(id, target) {
2386
+ let pub = pubs.get(target);
2387
+ if (!pub)
2388
+ pubs.set(target, pub = new $mol_wire_pub(id));
2389
+ return pub;
2390
+ }
2391
+ $.$mol_wire_proxy_pub = $mol_wire_proxy_pub;
2392
+ function $mol_wire_proxy(id, target) {
2393
+ if (!target)
2394
+ return target;
2395
+ const type = typeof target;
2396
+ if (type !== 'object' && type !== 'function')
2397
+ return target;
2398
+ return new Proxy(target, {
2399
+ get(target, property) {
2400
+ $mol_wire_proxy_pub(id, target).promote();
2401
+ const suffix = '.' + (typeof property === 'symbol' ? property.description : property);
2402
+ return $mol_wire_proxy(id + suffix, Reflect.get(target, property));
2403
+ },
2404
+ getOwnPropertyDescriptor(target, property) {
2405
+ $mol_wire_proxy_pub(id, target).promote();
2406
+ return Reflect.getOwnPropertyDescriptor(target, property);
2407
+ },
2408
+ ownKeys(target) {
2409
+ $mol_wire_proxy_pub(id, target).promote();
2410
+ return Reflect.ownKeys(target);
2411
+ },
2412
+ has(target, property) {
2413
+ $mol_wire_proxy_pub(id, target).promote();
2414
+ return Reflect.has(target, property);
2415
+ },
2416
+ getPrototypeOf(target) {
2417
+ $mol_wire_proxy_pub(id, target).promote();
2418
+ return $mol_wire_proxy(id, Reflect.getPrototypeOf(target));
2419
+ },
2420
+ isExtensible(target) {
2421
+ $mol_wire_proxy_pub(id, target).promote();
2422
+ return Reflect.isExtensible(target);
2423
+ },
2424
+ set(target, property, next) {
2425
+ const pub = pubs.get(target);
2426
+ if (pub) {
2427
+ const prev = Reflect.get(target, property);
2428
+ if ($mol_compare_deep(prev, next))
2429
+ return true;
2430
+ pub.emit();
2431
+ }
2432
+ return Reflect.set(target, property, next);
2433
+ },
2434
+ defineProperty(target, property, attributes) {
2435
+ pubs.get(target)?.emit();
2436
+ return Reflect.defineProperty(target, property, attributes);
2437
+ },
2438
+ deleteProperty(target, property) {
2439
+ pubs.get(target)?.emit();
2440
+ return Reflect.deleteProperty(target, property);
2441
+ },
2442
+ setPrototypeOf(target, proto) {
2443
+ pubs.get(target)?.emit();
2444
+ return Reflect.setPrototypeOf(target, proto);
2445
+ },
2446
+ preventExtensions(target) {
2447
+ pubs.get(target)?.emit();
2448
+ return Reflect.preventExtensions(target);
2449
+ },
2450
+ });
2451
+ }
2452
+ $.$mol_wire_proxy = $mol_wire_proxy;
2453
+ })($ || ($ = {}));
2454
+
2377
2455
  ;
2378
2456
  "use strict";
2379
2457
  var $;
package/node.test.js CHANGED
@@ -19,6 +19,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
19
19
  var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
20
20
  $.$$ = $
21
21
 
22
+ ;
23
+ "use strict";
24
+ var $;
25
+ (function ($) {
26
+ function $mol_guid(length = 8, exists = () => false) {
27
+ for (;;) {
28
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
29
+ if (exists(id))
30
+ continue;
31
+ return id;
32
+ }
33
+ }
34
+ $.$mol_guid = $mol_guid;
35
+ })($ || ($ = {}));
36
+
22
37
  ;
23
38
  "use strict";
24
39
  var $;
@@ -47,6 +62,11 @@ var $;
47
62
  var $;
48
63
  (function ($) {
49
64
  class $mol_wire_pub extends Object {
65
+ constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
66
+ super();
67
+ this[Symbol.toStringTag] = id;
68
+ }
69
+ [Symbol.toStringTag];
50
70
  data = [];
51
71
  static get [Symbol.species]() {
52
72
  return Array;
@@ -640,7 +660,6 @@ var $;
640
660
  }
641
661
  }
642
662
  }
643
- [Symbol.toStringTag];
644
663
  cache = undefined;
645
664
  get args() {
646
665
  return this.data.slice(0, this.pub_from);
@@ -659,13 +678,12 @@ var $;
659
678
  return this.task.name + '()';
660
679
  }
661
680
  constructor(id, task, host, args) {
662
- super();
681
+ super(id);
663
682
  this.task = task;
664
683
  this.host = host;
665
684
  if (args)
666
685
  this.data.push(...args);
667
686
  this.pub_from = this.sub_from = args?.length ?? 0;
668
- this[Symbol.toStringTag] = id;
669
687
  }
670
688
  plan() {
671
689
  $mol_wire_fiber.planning.add(this);
@@ -1593,21 +1611,6 @@ var $;
1593
1611
  $.$mol_wire_task = $mol_wire_task;
1594
1612
  })($ || ($ = {}));
1595
1613
 
1596
- ;
1597
- "use strict";
1598
- var $;
1599
- (function ($) {
1600
- function $mol_guid(length = 8, exists = () => false) {
1601
- for (;;) {
1602
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1603
- if (exists(id))
1604
- continue;
1605
- return id;
1606
- }
1607
- }
1608
- $.$mol_guid = $mol_guid;
1609
- })($ || ($ = {}));
1610
-
1611
1614
  ;
1612
1615
  "use strict";
1613
1616
  var $;
@@ -2365,6 +2368,81 @@ var $;
2365
2368
  $.$mol_wire_set = $mol_wire_set;
2366
2369
  })($ || ($ = {}));
2367
2370
 
2371
+ ;
2372
+ "use strict";
2373
+ var $;
2374
+ (function ($) {
2375
+ const pubs = new WeakMap();
2376
+ function $mol_wire_proxy_pub(id, target) {
2377
+ let pub = pubs.get(target);
2378
+ if (!pub)
2379
+ pubs.set(target, pub = new $mol_wire_pub(id));
2380
+ return pub;
2381
+ }
2382
+ $.$mol_wire_proxy_pub = $mol_wire_proxy_pub;
2383
+ function $mol_wire_proxy(id, target) {
2384
+ if (!target)
2385
+ return target;
2386
+ const type = typeof target;
2387
+ if (type !== 'object' && type !== 'function')
2388
+ return target;
2389
+ return new Proxy(target, {
2390
+ get(target, property) {
2391
+ $mol_wire_proxy_pub(id, target).promote();
2392
+ const suffix = '.' + (typeof property === 'symbol' ? property.description : property);
2393
+ return $mol_wire_proxy(id + suffix, Reflect.get(target, property));
2394
+ },
2395
+ getOwnPropertyDescriptor(target, property) {
2396
+ $mol_wire_proxy_pub(id, target).promote();
2397
+ return Reflect.getOwnPropertyDescriptor(target, property);
2398
+ },
2399
+ ownKeys(target) {
2400
+ $mol_wire_proxy_pub(id, target).promote();
2401
+ return Reflect.ownKeys(target);
2402
+ },
2403
+ has(target, property) {
2404
+ $mol_wire_proxy_pub(id, target).promote();
2405
+ return Reflect.has(target, property);
2406
+ },
2407
+ getPrototypeOf(target) {
2408
+ $mol_wire_proxy_pub(id, target).promote();
2409
+ return $mol_wire_proxy(id, Reflect.getPrototypeOf(target));
2410
+ },
2411
+ isExtensible(target) {
2412
+ $mol_wire_proxy_pub(id, target).promote();
2413
+ return Reflect.isExtensible(target);
2414
+ },
2415
+ set(target, property, next) {
2416
+ const pub = pubs.get(target);
2417
+ if (pub) {
2418
+ const prev = Reflect.get(target, property);
2419
+ if ($mol_compare_deep(prev, next))
2420
+ return true;
2421
+ pub.emit();
2422
+ }
2423
+ return Reflect.set(target, property, next);
2424
+ },
2425
+ defineProperty(target, property, attributes) {
2426
+ pubs.get(target)?.emit();
2427
+ return Reflect.defineProperty(target, property, attributes);
2428
+ },
2429
+ deleteProperty(target, property) {
2430
+ pubs.get(target)?.emit();
2431
+ return Reflect.deleteProperty(target, property);
2432
+ },
2433
+ setPrototypeOf(target, proto) {
2434
+ pubs.get(target)?.emit();
2435
+ return Reflect.setPrototypeOf(target, proto);
2436
+ },
2437
+ preventExtensions(target) {
2438
+ pubs.get(target)?.emit();
2439
+ return Reflect.preventExtensions(target);
2440
+ },
2441
+ });
2442
+ }
2443
+ $.$mol_wire_proxy = $mol_wire_proxy;
2444
+ })($ || ($ = {}));
2445
+
2368
2446
  ;
2369
2447
  "use strict";
2370
2448
  var $;
@@ -5473,6 +5551,73 @@ var $;
5473
5551
  });
5474
5552
  })($ || ($ = {}));
5475
5553
 
5554
+ ;
5555
+ "use strict";
5556
+ var $;
5557
+ (function ($_1) {
5558
+ var $$;
5559
+ (function ($$) {
5560
+ $mol_test({
5561
+ "Deep property change"($) {
5562
+ const source = $mol_wire_proxy('source', {
5563
+ foo: {
5564
+ bar: 123,
5565
+ }
5566
+ });
5567
+ const { res } = $mol_wire_let({
5568
+ res() { return source.foo.bar; }
5569
+ });
5570
+ $mol_assert_equal(res(), 123);
5571
+ source.foo.bar = 321;
5572
+ $mol_assert_equal(res(), 321);
5573
+ },
5574
+ "Deep property add/remove"($) {
5575
+ const source = $mol_wire_proxy('source', {
5576
+ foo: {
5577
+ bar: 123,
5578
+ }
5579
+ });
5580
+ const { exists, props } = $mol_wire_let({
5581
+ exists() { return 'bar' in source.foo; },
5582
+ props() { return Object.keys(source.foo); },
5583
+ });
5584
+ $mol_assert_equal(exists(), true);
5585
+ $mol_assert_equal(props(), ['bar']);
5586
+ delete source.foo.bar;
5587
+ $mol_assert_equal(exists(), false);
5588
+ $mol_assert_equal(props(), []);
5589
+ Object.defineProperty(source.foo, 'bar', { value: 'xxx', enumerable: true });
5590
+ $mol_assert_equal(exists(), true);
5591
+ $mol_assert_equal(props(), ['bar']);
5592
+ },
5593
+ "Deep property change to equal"($) {
5594
+ const source = $mol_wire_proxy('source', {
5595
+ foo: {
5596
+ bar: 123,
5597
+ }
5598
+ });
5599
+ let count = 0;
5600
+ const { res } = $mol_wire_let({
5601
+ res() {
5602
+ ++count;
5603
+ return source.foo.bar;
5604
+ }
5605
+ });
5606
+ res();
5607
+ $mol_assert_equal(count, 1);
5608
+ res();
5609
+ $mol_assert_equal(count, 1);
5610
+ source.foo = { bar: 123 };
5611
+ res();
5612
+ $mol_assert_equal(count, 1);
5613
+ source.foo = { bar: 321 };
5614
+ res();
5615
+ $mol_assert_equal(count, 2);
5616
+ },
5617
+ });
5618
+ })($$ = $_1.$$ || ($_1.$$ = {}));
5619
+ })($ || ($ = {}));
5620
+
5476
5621
  ;
5477
5622
  "use strict";
5478
5623
  var $;