mol_plot_all 1.2.1646 → 1.2.1648

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.mjs CHANGED
@@ -371,6 +371,14 @@ var $;
371
371
  ;
372
372
  "use strict";
373
373
 
374
+ ;
375
+ "use strict";
376
+ var $;
377
+ (function ($) {
378
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
379
+ $.$mol_key_store = new WeakMap();
380
+ })($ || ($ = {}));
381
+
374
382
  ;
375
383
  "use strict";
376
384
  var $;
@@ -407,6 +415,9 @@ var $;
407
415
  static toJSON() {
408
416
  return this.toString();
409
417
  }
418
+ static [$mol_key_handle]() {
419
+ return this.toString();
420
+ }
410
421
  destructor() { }
411
422
  static destructor() { }
412
423
  [Symbol.dispose]() {
@@ -2398,46 +2409,50 @@ var $;
2398
2409
  "use strict";
2399
2410
  var $;
2400
2411
  (function ($) {
2401
- $.$mol_key_store = new WeakMap();
2402
2412
  const TypedArray = Object.getPrototypeOf(Uint8Array);
2403
2413
  function $mol_key(value) {
2404
- if (typeof value === 'bigint')
2405
- return value.toString() + 'n';
2406
- if (typeof value === 'symbol')
2407
- return value.description;
2408
- if (!value)
2409
- return JSON.stringify(value);
2410
- if (typeof value !== 'object' && typeof value !== 'function')
2411
- return JSON.stringify(value);
2412
- return JSON.stringify(value, (field, value) => {
2414
+ primitives: {
2413
2415
  if (typeof value === 'bigint')
2414
2416
  return value.toString() + 'n';
2415
2417
  if (typeof value === 'symbol')
2416
- return value.description;
2418
+ return `Symbol(${value.description})`;
2417
2419
  if (!value)
2418
- return value;
2420
+ return JSON.stringify(value);
2419
2421
  if (typeof value !== 'object' && typeof value !== 'function')
2420
- return value;
2422
+ return JSON.stringify(value);
2423
+ }
2424
+ caching: {
2425
+ let key = $mol_key_store.get(value);
2426
+ if (key)
2427
+ return key;
2428
+ }
2429
+ objects: {
2430
+ if (value instanceof TypedArray) {
2431
+ return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
2432
+ }
2421
2433
  if (Array.isArray(value))
2422
- return value;
2423
- const proto = Reflect.getPrototypeOf(value);
2424
- if (!proto)
2425
- return value;
2426
- if (Reflect.getPrototypeOf(proto) === null)
2427
- return value;
2428
- if ('toJSON' in value)
2429
- return value;
2434
+ return `[${value.map(v => $mol_key(v))}]`;
2430
2435
  if (value instanceof RegExp)
2431
2436
  return value.toString();
2432
- if (value instanceof TypedArray)
2433
- return [...value];
2434
- let key = $.$mol_key_store.get(value);
2435
- if (key)
2436
- return key;
2437
- key = $mol_guid();
2438
- $.$mol_key_store.set(value, key);
2437
+ if (value instanceof Date)
2438
+ return `Date(${value.valueOf()})`;
2439
+ }
2440
+ structures: {
2441
+ const proto = Reflect.getPrototypeOf(value);
2442
+ if (!proto || !Reflect.getPrototypeOf(proto)) {
2443
+ return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
2444
+ }
2445
+ }
2446
+ handlers: {
2447
+ if ($mol_key_handle in value) {
2448
+ return value[$mol_key_handle]();
2449
+ }
2450
+ }
2451
+ containers: {
2452
+ const key = JSON.stringify('#' + $mol_guid());
2453
+ $mol_key_store.set(value, key);
2439
2454
  return key;
2440
- });
2455
+ }
2441
2456
  }
2442
2457
  $.$mol_key = $mol_key;
2443
2458
  })($ || ($ = {}));
@@ -2596,8 +2611,15 @@ var $;
2596
2611
  (this.host ?? this.task)[this.field()] = null;
2597
2612
  }
2598
2613
  else {
2599
- ;
2600
- (this.host ?? this.task)[this.field()].delete($mol_key(this.args[0]));
2614
+ const key = $mol_key(this.args[0]);
2615
+ const map = (this.host ?? this.task)[this.field()];
2616
+ if (!map.has(key))
2617
+ this.$.$mol_log3_warn({
2618
+ place: this,
2619
+ message: 'Absent key on destruction',
2620
+ hint: 'Check for $mol_key(key) is not changed',
2621
+ });
2622
+ map.delete(key);
2601
2623
  }
2602
2624
  }
2603
2625
  put(next) {
package/node.test.js CHANGED
@@ -362,6 +362,14 @@ var $;
362
362
  ;
363
363
  "use strict";
364
364
 
365
+ ;
366
+ "use strict";
367
+ var $;
368
+ (function ($) {
369
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
370
+ $.$mol_key_store = new WeakMap();
371
+ })($ || ($ = {}));
372
+
365
373
  ;
366
374
  "use strict";
367
375
  var $;
@@ -398,6 +406,9 @@ var $;
398
406
  static toJSON() {
399
407
  return this.toString();
400
408
  }
409
+ static [$mol_key_handle]() {
410
+ return this.toString();
411
+ }
401
412
  destructor() { }
402
413
  static destructor() { }
403
414
  [Symbol.dispose]() {
@@ -2389,46 +2400,50 @@ var $;
2389
2400
  "use strict";
2390
2401
  var $;
2391
2402
  (function ($) {
2392
- $.$mol_key_store = new WeakMap();
2393
2403
  const TypedArray = Object.getPrototypeOf(Uint8Array);
2394
2404
  function $mol_key(value) {
2395
- if (typeof value === 'bigint')
2396
- return value.toString() + 'n';
2397
- if (typeof value === 'symbol')
2398
- return value.description;
2399
- if (!value)
2400
- return JSON.stringify(value);
2401
- if (typeof value !== 'object' && typeof value !== 'function')
2402
- return JSON.stringify(value);
2403
- return JSON.stringify(value, (field, value) => {
2405
+ primitives: {
2404
2406
  if (typeof value === 'bigint')
2405
2407
  return value.toString() + 'n';
2406
2408
  if (typeof value === 'symbol')
2407
- return value.description;
2409
+ return `Symbol(${value.description})`;
2408
2410
  if (!value)
2409
- return value;
2411
+ return JSON.stringify(value);
2410
2412
  if (typeof value !== 'object' && typeof value !== 'function')
2411
- return value;
2413
+ return JSON.stringify(value);
2414
+ }
2415
+ caching: {
2416
+ let key = $mol_key_store.get(value);
2417
+ if (key)
2418
+ return key;
2419
+ }
2420
+ objects: {
2421
+ if (value instanceof TypedArray) {
2422
+ return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
2423
+ }
2412
2424
  if (Array.isArray(value))
2413
- return value;
2414
- const proto = Reflect.getPrototypeOf(value);
2415
- if (!proto)
2416
- return value;
2417
- if (Reflect.getPrototypeOf(proto) === null)
2418
- return value;
2419
- if ('toJSON' in value)
2420
- return value;
2425
+ return `[${value.map(v => $mol_key(v))}]`;
2421
2426
  if (value instanceof RegExp)
2422
2427
  return value.toString();
2423
- if (value instanceof TypedArray)
2424
- return [...value];
2425
- let key = $.$mol_key_store.get(value);
2426
- if (key)
2427
- return key;
2428
- key = $mol_guid();
2429
- $.$mol_key_store.set(value, key);
2428
+ if (value instanceof Date)
2429
+ return `Date(${value.valueOf()})`;
2430
+ }
2431
+ structures: {
2432
+ const proto = Reflect.getPrototypeOf(value);
2433
+ if (!proto || !Reflect.getPrototypeOf(proto)) {
2434
+ return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
2435
+ }
2436
+ }
2437
+ handlers: {
2438
+ if ($mol_key_handle in value) {
2439
+ return value[$mol_key_handle]();
2440
+ }
2441
+ }
2442
+ containers: {
2443
+ const key = JSON.stringify('#' + $mol_guid());
2444
+ $mol_key_store.set(value, key);
2430
2445
  return key;
2431
- });
2446
+ }
2432
2447
  }
2433
2448
  $.$mol_key = $mol_key;
2434
2449
  })($ || ($ = {}));
@@ -2587,8 +2602,15 @@ var $;
2587
2602
  (this.host ?? this.task)[this.field()] = null;
2588
2603
  }
2589
2604
  else {
2590
- ;
2591
- (this.host ?? this.task)[this.field()].delete($mol_key(this.args[0]));
2605
+ const key = $mol_key(this.args[0]);
2606
+ const map = (this.host ?? this.task)[this.field()];
2607
+ if (!map.has(key))
2608
+ this.$.$mol_log3_warn({
2609
+ place: this,
2610
+ message: 'Absent key on destruction',
2611
+ hint: 'Check for $mol_key(key) is not changed',
2612
+ });
2613
+ map.delete(key);
2592
2614
  }
2593
2615
  }
2594
2616
  put(next) {
@@ -10043,9 +10065,9 @@ var $;
10043
10065
  $mol_assert_equal($mol_key({ foo: [false] }), '{"foo":[false]}');
10044
10066
  },
10045
10067
  'Uint8Array'() {
10046
- $mol_assert_equal($mol_key(new Uint8Array([1, 2])), '[1,2]');
10047
- $mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[[1,2]]');
10048
- $mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":[1,2]}');
10068
+ $mol_assert_equal($mol_key(new Uint8Array([1, 2])), 'Uint8Array([1,2])');
10069
+ $mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[Uint8Array([1,2])]');
10070
+ $mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":Uint8Array([1,2])}');
10049
10071
  },
10050
10072
  'Function'() {
10051
10073
  const func = () => { };
@@ -10065,6 +10087,12 @@ var $;
10065
10087
  $mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
10066
10088
  },
10067
10089
  'Custom JSON representation'() {
10090
+ class User {
10091
+ toJSON() { return 'jin'; }
10092
+ }
10093
+ $mol_assert_unique([$mol_key(new User)], [$mol_key(new User)]);
10094
+ },
10095
+ 'Custom key handler'() {
10068
10096
  class User {
10069
10097
  name;
10070
10098
  age;
@@ -10072,15 +10100,15 @@ var $;
10072
10100
  this.name = name;
10073
10101
  this.age = age;
10074
10102
  }
10075
- toJSON() { return { name: this.name }; }
10103
+ [$mol_key_handle]() { return `User(${JSON.stringify(this.name)})`; }
10076
10104
  }
10077
- $mol_assert_equal($mol_key(new User('jin', 18)), '{"name":"jin"}');
10105
+ $mol_assert_equal($mol_key([new User('jin', 16)]), $mol_key([new User('jin', 18)]), '[User("jin")]');
10078
10106
  },
10079
10107
  'Special native classes'() {
10080
- $mol_assert_equal($mol_key(new Date('xyz')), 'null');
10081
- $mol_assert_equal($mol_key(new Date('2001-01-02T03:04:05.678Z')), '"2001-01-02T03:04:05.678Z"');
10082
- $mol_assert_equal($mol_key(/./), '"/./"');
10083
- $mol_assert_equal($mol_key(/\./gimsu), '"/\\\\./gimsu"');
10108
+ $mol_assert_equal($mol_key(new Date('xyz')), 'Date(NaN)');
10109
+ $mol_assert_equal($mol_key(new Date(12345)), 'Date(12345)');
10110
+ $mol_assert_equal($mol_key(/./), '/./');
10111
+ $mol_assert_equal($mol_key(/\./gimsu), '/\\./gimsu');
10084
10112
  },
10085
10113
  });
10086
10114
  })($ || ($ = {}));