mol_jsx_lib 0.0.1333 → 0.0.1335

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/web.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/web.mjs CHANGED
@@ -446,6 +446,21 @@ var $;
446
446
  $.$mol_object2 = $mol_object2;
447
447
  })($ || ($ = {}));
448
448
 
449
+ ;
450
+ "use strict";
451
+ var $;
452
+ (function ($) {
453
+ function $mol_guid(length = 8, exists = () => false) {
454
+ for (;;) {
455
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
456
+ if (exists(id))
457
+ continue;
458
+ return id;
459
+ }
460
+ }
461
+ $.$mol_guid = $mol_guid;
462
+ })($ || ($ = {}));
463
+
449
464
  ;
450
465
  "use strict";
451
466
  var $;
@@ -464,6 +479,11 @@ var $;
464
479
  var $;
465
480
  (function ($) {
466
481
  class $mol_wire_pub extends Object {
482
+ constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
483
+ super();
484
+ this[Symbol.toStringTag] = id;
485
+ }
486
+ [Symbol.toStringTag];
467
487
  data = [];
468
488
  static get [Symbol.species]() {
469
489
  return Array;
@@ -879,7 +899,6 @@ var $;
879
899
  }
880
900
  }
881
901
  }
882
- [Symbol.toStringTag];
883
902
  cache = undefined;
884
903
  get args() {
885
904
  return this.data.slice(0, this.pub_from);
@@ -898,13 +917,12 @@ var $;
898
917
  return this.task.name + '()';
899
918
  }
900
919
  constructor(id, task, host, args) {
901
- super();
920
+ super(id);
902
921
  this.task = task;
903
922
  this.host = host;
904
923
  if (args)
905
924
  this.data.push(...args);
906
925
  this.pub_from = this.sub_from = args?.length ?? 0;
907
- this[Symbol.toStringTag] = id;
908
926
  }
909
927
  plan() {
910
928
  $mol_wire_fiber.planning.add(this);
@@ -1089,21 +1107,6 @@ var $;
1089
1107
  $.$mol_wire_fiber = $mol_wire_fiber;
1090
1108
  })($ || ($ = {}));
1091
1109
 
1092
- ;
1093
- "use strict";
1094
- var $;
1095
- (function ($) {
1096
- function $mol_guid(length = 8, exists = () => false) {
1097
- for (;;) {
1098
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1099
- if (exists(id))
1100
- continue;
1101
- return id;
1102
- }
1103
- }
1104
- $.$mol_guid = $mol_guid;
1105
- })($ || ($ = {}));
1106
-
1107
1110
  ;
1108
1111
  "use strict";
1109
1112
  var $;
@@ -2184,6 +2187,81 @@ var $;
2184
2187
  $.$mol_wire_set = $mol_wire_set;
2185
2188
  })($ || ($ = {}));
2186
2189
 
2190
+ ;
2191
+ "use strict";
2192
+ var $;
2193
+ (function ($) {
2194
+ const pubs = new WeakMap();
2195
+ function $mol_wire_proxy_pub(id, target) {
2196
+ let pub = pubs.get(target);
2197
+ if (!pub)
2198
+ pubs.set(target, pub = new $mol_wire_pub(id));
2199
+ return pub;
2200
+ }
2201
+ $.$mol_wire_proxy_pub = $mol_wire_proxy_pub;
2202
+ function $mol_wire_proxy(id, target) {
2203
+ if (!target)
2204
+ return target;
2205
+ const type = typeof target;
2206
+ if (type !== 'object' && type !== 'function')
2207
+ return target;
2208
+ return new Proxy(target, {
2209
+ get(target, property) {
2210
+ $mol_wire_proxy_pub(id, target).promote();
2211
+ const suffix = '.' + (typeof property === 'symbol' ? property.description : property);
2212
+ return $mol_wire_proxy(id + suffix, Reflect.get(target, property));
2213
+ },
2214
+ getOwnPropertyDescriptor(target, property) {
2215
+ $mol_wire_proxy_pub(id, target).promote();
2216
+ return Reflect.getOwnPropertyDescriptor(target, property);
2217
+ },
2218
+ ownKeys(target) {
2219
+ $mol_wire_proxy_pub(id, target).promote();
2220
+ return Reflect.ownKeys(target);
2221
+ },
2222
+ has(target, property) {
2223
+ $mol_wire_proxy_pub(id, target).promote();
2224
+ return Reflect.has(target, property);
2225
+ },
2226
+ getPrototypeOf(target) {
2227
+ $mol_wire_proxy_pub(id, target).promote();
2228
+ return $mol_wire_proxy(id, Reflect.getPrototypeOf(target));
2229
+ },
2230
+ isExtensible(target) {
2231
+ $mol_wire_proxy_pub(id, target).promote();
2232
+ return Reflect.isExtensible(target);
2233
+ },
2234
+ set(target, property, next) {
2235
+ const pub = pubs.get(target);
2236
+ if (pub) {
2237
+ const prev = Reflect.get(target, property);
2238
+ if ($mol_compare_deep(prev, next))
2239
+ return true;
2240
+ pub.emit();
2241
+ }
2242
+ return Reflect.set(target, property, next);
2243
+ },
2244
+ defineProperty(target, property, attributes) {
2245
+ pubs.get(target)?.emit();
2246
+ return Reflect.defineProperty(target, property, attributes);
2247
+ },
2248
+ deleteProperty(target, property) {
2249
+ pubs.get(target)?.emit();
2250
+ return Reflect.deleteProperty(target, property);
2251
+ },
2252
+ setPrototypeOf(target, proto) {
2253
+ pubs.get(target)?.emit();
2254
+ return Reflect.setPrototypeOf(target, proto);
2255
+ },
2256
+ preventExtensions(target) {
2257
+ pubs.get(target)?.emit();
2258
+ return Reflect.preventExtensions(target);
2259
+ },
2260
+ });
2261
+ }
2262
+ $.$mol_wire_proxy = $mol_wire_proxy;
2263
+ })($ || ($ = {}));
2264
+
2187
2265
  ;
2188
2266
  "use strict";
2189
2267
  var $;
package/web.test.js CHANGED
@@ -2273,6 +2273,73 @@ var $;
2273
2273
  });
2274
2274
  })($ || ($ = {}));
2275
2275
 
2276
+ ;
2277
+ "use strict";
2278
+ var $;
2279
+ (function ($_1) {
2280
+ var $$;
2281
+ (function ($$) {
2282
+ $mol_test({
2283
+ "Deep property change"($) {
2284
+ const source = $mol_wire_proxy('source', {
2285
+ foo: {
2286
+ bar: 123,
2287
+ }
2288
+ });
2289
+ const { res } = $mol_wire_let({
2290
+ res() { return source.foo.bar; }
2291
+ });
2292
+ $mol_assert_equal(res(), 123);
2293
+ source.foo.bar = 321;
2294
+ $mol_assert_equal(res(), 321);
2295
+ },
2296
+ "Deep property add/remove"($) {
2297
+ const source = $mol_wire_proxy('source', {
2298
+ foo: {
2299
+ bar: 123,
2300
+ }
2301
+ });
2302
+ const { exists, props } = $mol_wire_let({
2303
+ exists() { return 'bar' in source.foo; },
2304
+ props() { return Object.keys(source.foo); },
2305
+ });
2306
+ $mol_assert_equal(exists(), true);
2307
+ $mol_assert_equal(props(), ['bar']);
2308
+ delete source.foo.bar;
2309
+ $mol_assert_equal(exists(), false);
2310
+ $mol_assert_equal(props(), []);
2311
+ Object.defineProperty(source.foo, 'bar', { value: 'xxx', enumerable: true });
2312
+ $mol_assert_equal(exists(), true);
2313
+ $mol_assert_equal(props(), ['bar']);
2314
+ },
2315
+ "Deep property change to equal"($) {
2316
+ const source = $mol_wire_proxy('source', {
2317
+ foo: {
2318
+ bar: 123,
2319
+ }
2320
+ });
2321
+ let count = 0;
2322
+ const { res } = $mol_wire_let({
2323
+ res() {
2324
+ ++count;
2325
+ return source.foo.bar;
2326
+ }
2327
+ });
2328
+ res();
2329
+ $mol_assert_equal(count, 1);
2330
+ res();
2331
+ $mol_assert_equal(count, 1);
2332
+ source.foo = { bar: 123 };
2333
+ res();
2334
+ $mol_assert_equal(count, 1);
2335
+ source.foo = { bar: 321 };
2336
+ res();
2337
+ $mol_assert_equal(count, 2);
2338
+ },
2339
+ });
2340
+ })($$ = $_1.$$ || ($_1.$$ = {}));
2341
+ })($ || ($ = {}));
2342
+
2276
2343
  ;
2277
2344
  "use strict";
2278
2345
  var $;