mol_plot_all 1.2.1646 → 1.2.1647

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.mjs CHANGED
@@ -437,6 +437,14 @@ var $;
437
437
  $.$mol_func_name_from = $mol_func_name_from;
438
438
  })($ || ($ = {}));
439
439
 
440
+ ;
441
+ "use strict";
442
+ var $;
443
+ (function ($) {
444
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
445
+ $.$mol_key_store = new WeakMap();
446
+ })($ || ($ = {}));
447
+
440
448
  ;
441
449
  "use strict";
442
450
  var $;
@@ -473,6 +481,9 @@ var $;
473
481
  static toJSON() {
474
482
  return this.toString();
475
483
  }
484
+ static [$mol_key_handle]() {
485
+ return this.toString();
486
+ }
476
487
  destructor() { }
477
488
  static destructor() { }
478
489
  [Symbol.dispose]() {
@@ -1254,46 +1265,50 @@ var $;
1254
1265
  "use strict";
1255
1266
  var $;
1256
1267
  (function ($) {
1257
- $.$mol_key_store = new WeakMap();
1258
1268
  const TypedArray = Object.getPrototypeOf(Uint8Array);
1259
1269
  function $mol_key(value) {
1260
- if (typeof value === 'bigint')
1261
- return value.toString() + 'n';
1262
- if (typeof value === 'symbol')
1263
- return value.description;
1264
- if (!value)
1265
- return JSON.stringify(value);
1266
- if (typeof value !== 'object' && typeof value !== 'function')
1267
- return JSON.stringify(value);
1268
- return JSON.stringify(value, (field, value) => {
1270
+ primitives: {
1269
1271
  if (typeof value === 'bigint')
1270
1272
  return value.toString() + 'n';
1271
1273
  if (typeof value === 'symbol')
1272
- return value.description;
1274
+ return `Symbol(${value.description})`;
1273
1275
  if (!value)
1274
- return value;
1276
+ return JSON.stringify(value);
1275
1277
  if (typeof value !== 'object' && typeof value !== 'function')
1276
- return value;
1278
+ return JSON.stringify(value);
1279
+ }
1280
+ caching: {
1281
+ let key = $mol_key_store.get(value);
1282
+ if (key)
1283
+ return key;
1284
+ }
1285
+ objects: {
1286
+ if (value instanceof TypedArray) {
1287
+ return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
1288
+ }
1277
1289
  if (Array.isArray(value))
1278
- return value;
1279
- const proto = Reflect.getPrototypeOf(value);
1280
- if (!proto)
1281
- return value;
1282
- if (Reflect.getPrototypeOf(proto) === null)
1283
- return value;
1284
- if ('toJSON' in value)
1285
- return value;
1290
+ return `[${value.map(v => $mol_key(v))}]`;
1286
1291
  if (value instanceof RegExp)
1287
1292
  return value.toString();
1288
- if (value instanceof TypedArray)
1289
- return [...value];
1290
- let key = $.$mol_key_store.get(value);
1291
- if (key)
1292
- return key;
1293
- key = $mol_guid();
1294
- $.$mol_key_store.set(value, key);
1293
+ if (value instanceof Date)
1294
+ return `Date(${value.valueOf()})`;
1295
+ }
1296
+ structures: {
1297
+ const proto = Reflect.getPrototypeOf(value);
1298
+ if (!proto || !Reflect.getPrototypeOf(proto)) {
1299
+ return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
1300
+ }
1301
+ }
1302
+ handlers: {
1303
+ if ($mol_key_handle in value) {
1304
+ return value[$mol_key_handle]();
1305
+ }
1306
+ }
1307
+ containers: {
1308
+ const key = JSON.stringify('#' + $mol_guid());
1309
+ $mol_key_store.set(value, key);
1295
1310
  return key;
1296
- });
1311
+ }
1297
1312
  }
1298
1313
  $.$mol_key = $mol_key;
1299
1314
  })($ || ($ = {}));
@@ -1813,8 +1828,15 @@ var $;
1813
1828
  (this.host ?? this.task)[this.field()] = null;
1814
1829
  }
1815
1830
  else {
1816
- ;
1817
- (this.host ?? this.task)[this.field()].delete($mol_key(this.args[0]));
1831
+ const key = $mol_key(this.args[0]);
1832
+ const map = (this.host ?? this.task)[this.field()];
1833
+ if (!map.has(key))
1834
+ this.$.$mol_log3_warn({
1835
+ place: this,
1836
+ message: 'Absent key on destruction',
1837
+ hint: 'Check for $mol_key(key) is not changed',
1838
+ });
1839
+ map.delete(key);
1818
1840
  }
1819
1841
  }
1820
1842
  put(next) {
package/web.test.js CHANGED
@@ -1903,9 +1903,9 @@ var $;
1903
1903
  $mol_assert_equal($mol_key({ foo: [false] }), '{"foo":[false]}');
1904
1904
  },
1905
1905
  'Uint8Array'() {
1906
- $mol_assert_equal($mol_key(new Uint8Array([1, 2])), '[1,2]');
1907
- $mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[[1,2]]');
1908
- $mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":[1,2]}');
1906
+ $mol_assert_equal($mol_key(new Uint8Array([1, 2])), 'Uint8Array([1,2])');
1907
+ $mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[Uint8Array([1,2])]');
1908
+ $mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":Uint8Array([1,2])}');
1909
1909
  },
1910
1910
  'Function'() {
1911
1911
  const func = () => { };
@@ -1925,6 +1925,12 @@ var $;
1925
1925
  $mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
1926
1926
  },
1927
1927
  'Custom JSON representation'() {
1928
+ class User {
1929
+ toJSON() { return 'jin'; }
1930
+ }
1931
+ $mol_assert_unique([$mol_key(new User)], [$mol_key(new User)]);
1932
+ },
1933
+ 'Custom key handler'() {
1928
1934
  class User {
1929
1935
  name;
1930
1936
  age;
@@ -1932,15 +1938,15 @@ var $;
1932
1938
  this.name = name;
1933
1939
  this.age = age;
1934
1940
  }
1935
- toJSON() { return { name: this.name }; }
1941
+ [$mol_key_handle]() { return `User(${JSON.stringify(this.name)})`; }
1936
1942
  }
1937
- $mol_assert_equal($mol_key(new User('jin', 18)), '{"name":"jin"}');
1943
+ $mol_assert_equal($mol_key([new User('jin', 16)]), $mol_key([new User('jin', 18)]), '[User("jin")]');
1938
1944
  },
1939
1945
  'Special native classes'() {
1940
- $mol_assert_equal($mol_key(new Date('xyz')), 'null');
1941
- $mol_assert_equal($mol_key(new Date('2001-01-02T03:04:05.678Z')), '"2001-01-02T03:04:05.678Z"');
1942
- $mol_assert_equal($mol_key(/./), '"/./"');
1943
- $mol_assert_equal($mol_key(/\./gimsu), '"/\\\\./gimsu"');
1946
+ $mol_assert_equal($mol_key(new Date('xyz')), 'Date(NaN)');
1947
+ $mol_assert_equal($mol_key(new Date(12345)), 'Date(12345)');
1948
+ $mol_assert_equal($mol_key(/./), '/./');
1949
+ $mol_assert_equal($mol_key(/\./gimsu), '/\\./gimsu');
1944
1950
  },
1945
1951
  });
1946
1952
  })($ || ($ = {}));