mol_wire_dom 0.0.1662 → 0.0.1663

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
@@ -635,6 +635,14 @@ var $;
635
635
  $.$mol_func_name_from = $mol_func_name_from;
636
636
  })($ || ($ = {}));
637
637
 
638
+ ;
639
+ "use strict";
640
+ var $;
641
+ (function ($) {
642
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
643
+ $.$mol_key_store = new WeakMap();
644
+ })($ || ($ = {}));
645
+
638
646
  ;
639
647
  "use strict";
640
648
  var $;
@@ -671,6 +679,9 @@ var $;
671
679
  static toJSON() {
672
680
  return this.toString();
673
681
  }
682
+ static [$mol_key_handle]() {
683
+ return this.toString();
684
+ }
674
685
  destructor() { }
675
686
  static destructor() { }
676
687
  [Symbol.dispose]() {
@@ -984,46 +995,50 @@ var $;
984
995
  "use strict";
985
996
  var $;
986
997
  (function ($) {
987
- $.$mol_key_store = new WeakMap();
988
998
  const TypedArray = Object.getPrototypeOf(Uint8Array);
989
999
  function $mol_key(value) {
990
- if (typeof value === 'bigint')
991
- return value.toString() + 'n';
992
- if (typeof value === 'symbol')
993
- return value.description;
994
- if (!value)
995
- return JSON.stringify(value);
996
- if (typeof value !== 'object' && typeof value !== 'function')
997
- return JSON.stringify(value);
998
- return JSON.stringify(value, (field, value) => {
1000
+ primitives: {
999
1001
  if (typeof value === 'bigint')
1000
1002
  return value.toString() + 'n';
1001
1003
  if (typeof value === 'symbol')
1002
- return value.description;
1004
+ return `Symbol(${value.description})`;
1003
1005
  if (!value)
1004
- return value;
1006
+ return JSON.stringify(value);
1005
1007
  if (typeof value !== 'object' && typeof value !== 'function')
1006
- return value;
1008
+ return JSON.stringify(value);
1009
+ }
1010
+ caching: {
1011
+ let key = $mol_key_store.get(value);
1012
+ if (key)
1013
+ return key;
1014
+ }
1015
+ objects: {
1016
+ if (value instanceof TypedArray) {
1017
+ return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
1018
+ }
1007
1019
  if (Array.isArray(value))
1008
- return value;
1009
- const proto = Reflect.getPrototypeOf(value);
1010
- if (!proto)
1011
- return value;
1012
- if (Reflect.getPrototypeOf(proto) === null)
1013
- return value;
1014
- if ('toJSON' in value)
1015
- return value;
1020
+ return `[${value.map(v => $mol_key(v))}]`;
1016
1021
  if (value instanceof RegExp)
1017
1022
  return value.toString();
1018
- if (value instanceof TypedArray)
1019
- return [...value];
1020
- let key = $.$mol_key_store.get(value);
1021
- if (key)
1022
- return key;
1023
- key = $mol_guid();
1024
- $.$mol_key_store.set(value, key);
1023
+ if (value instanceof Date)
1024
+ return `Date(${value.valueOf()})`;
1025
+ }
1026
+ structures: {
1027
+ const proto = Reflect.getPrototypeOf(value);
1028
+ if (!proto || !Reflect.getPrototypeOf(proto)) {
1029
+ return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
1030
+ }
1031
+ }
1032
+ handlers: {
1033
+ if ($mol_key_handle in value) {
1034
+ return value[$mol_key_handle]();
1035
+ }
1036
+ }
1037
+ containers: {
1038
+ const key = JSON.stringify('#' + $mol_guid());
1039
+ $mol_key_store.set(value, key);
1025
1040
  return key;
1026
- });
1041
+ }
1027
1042
  }
1028
1043
  $.$mol_key = $mol_key;
1029
1044
  })($ || ($ = {}));
package/node.test.js CHANGED
@@ -626,6 +626,14 @@ var $;
626
626
  $.$mol_func_name_from = $mol_func_name_from;
627
627
  })($ || ($ = {}));
628
628
 
629
+ ;
630
+ "use strict";
631
+ var $;
632
+ (function ($) {
633
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
634
+ $.$mol_key_store = new WeakMap();
635
+ })($ || ($ = {}));
636
+
629
637
  ;
630
638
  "use strict";
631
639
  var $;
@@ -662,6 +670,9 @@ var $;
662
670
  static toJSON() {
663
671
  return this.toString();
664
672
  }
673
+ static [$mol_key_handle]() {
674
+ return this.toString();
675
+ }
665
676
  destructor() { }
666
677
  static destructor() { }
667
678
  [Symbol.dispose]() {
@@ -975,46 +986,50 @@ var $;
975
986
  "use strict";
976
987
  var $;
977
988
  (function ($) {
978
- $.$mol_key_store = new WeakMap();
979
989
  const TypedArray = Object.getPrototypeOf(Uint8Array);
980
990
  function $mol_key(value) {
981
- if (typeof value === 'bigint')
982
- return value.toString() + 'n';
983
- if (typeof value === 'symbol')
984
- return value.description;
985
- if (!value)
986
- return JSON.stringify(value);
987
- if (typeof value !== 'object' && typeof value !== 'function')
988
- return JSON.stringify(value);
989
- return JSON.stringify(value, (field, value) => {
991
+ primitives: {
990
992
  if (typeof value === 'bigint')
991
993
  return value.toString() + 'n';
992
994
  if (typeof value === 'symbol')
993
- return value.description;
995
+ return `Symbol(${value.description})`;
994
996
  if (!value)
995
- return value;
997
+ return JSON.stringify(value);
996
998
  if (typeof value !== 'object' && typeof value !== 'function')
997
- return value;
999
+ return JSON.stringify(value);
1000
+ }
1001
+ caching: {
1002
+ let key = $mol_key_store.get(value);
1003
+ if (key)
1004
+ return key;
1005
+ }
1006
+ objects: {
1007
+ if (value instanceof TypedArray) {
1008
+ return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
1009
+ }
998
1010
  if (Array.isArray(value))
999
- return value;
1000
- const proto = Reflect.getPrototypeOf(value);
1001
- if (!proto)
1002
- return value;
1003
- if (Reflect.getPrototypeOf(proto) === null)
1004
- return value;
1005
- if ('toJSON' in value)
1006
- return value;
1011
+ return `[${value.map(v => $mol_key(v))}]`;
1007
1012
  if (value instanceof RegExp)
1008
1013
  return value.toString();
1009
- if (value instanceof TypedArray)
1010
- return [...value];
1011
- let key = $.$mol_key_store.get(value);
1012
- if (key)
1013
- return key;
1014
- key = $mol_guid();
1015
- $.$mol_key_store.set(value, key);
1014
+ if (value instanceof Date)
1015
+ return `Date(${value.valueOf()})`;
1016
+ }
1017
+ structures: {
1018
+ const proto = Reflect.getPrototypeOf(value);
1019
+ if (!proto || !Reflect.getPrototypeOf(proto)) {
1020
+ return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
1021
+ }
1022
+ }
1023
+ handlers: {
1024
+ if ($mol_key_handle in value) {
1025
+ return value[$mol_key_handle]();
1026
+ }
1027
+ }
1028
+ containers: {
1029
+ const key = JSON.stringify('#' + $mol_guid());
1030
+ $mol_key_store.set(value, key);
1016
1031
  return key;
1017
- });
1032
+ }
1018
1033
  }
1019
1034
  $.$mol_key = $mol_key;
1020
1035
  })($ || ($ = {}));
@@ -4249,9 +4264,9 @@ var $;
4249
4264
  $mol_assert_equal($mol_key({ foo: [false] }), '{"foo":[false]}');
4250
4265
  },
4251
4266
  'Uint8Array'() {
4252
- $mol_assert_equal($mol_key(new Uint8Array([1, 2])), '[1,2]');
4253
- $mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[[1,2]]');
4254
- $mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":[1,2]}');
4267
+ $mol_assert_equal($mol_key(new Uint8Array([1, 2])), 'Uint8Array([1,2])');
4268
+ $mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[Uint8Array([1,2])]');
4269
+ $mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":Uint8Array([1,2])}');
4255
4270
  },
4256
4271
  'Function'() {
4257
4272
  const func = () => { };
@@ -4271,6 +4286,12 @@ var $;
4271
4286
  $mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
4272
4287
  },
4273
4288
  'Custom JSON representation'() {
4289
+ class User {
4290
+ toJSON() { return 'jin'; }
4291
+ }
4292
+ $mol_assert_unique([$mol_key(new User)], [$mol_key(new User)]);
4293
+ },
4294
+ 'Custom key handler'() {
4274
4295
  class User {
4275
4296
  name;
4276
4297
  age;
@@ -4278,15 +4299,15 @@ var $;
4278
4299
  this.name = name;
4279
4300
  this.age = age;
4280
4301
  }
4281
- toJSON() { return { name: this.name }; }
4302
+ [$mol_key_handle]() { return `User(${JSON.stringify(this.name)})`; }
4282
4303
  }
4283
- $mol_assert_equal($mol_key(new User('jin', 18)), '{"name":"jin"}');
4304
+ $mol_assert_equal($mol_key([new User('jin', 16)]), $mol_key([new User('jin', 18)]), '[User("jin")]');
4284
4305
  },
4285
4306
  'Special native classes'() {
4286
- $mol_assert_equal($mol_key(new Date('xyz')), 'null');
4287
- $mol_assert_equal($mol_key(new Date('2001-01-02T03:04:05.678Z')), '"2001-01-02T03:04:05.678Z"');
4288
- $mol_assert_equal($mol_key(/./), '"/./"');
4289
- $mol_assert_equal($mol_key(/\./gimsu), '"/\\\\./gimsu"');
4307
+ $mol_assert_equal($mol_key(new Date('xyz')), 'Date(NaN)');
4308
+ $mol_assert_equal($mol_key(new Date(12345)), 'Date(12345)');
4309
+ $mol_assert_equal($mol_key(/./), '/./');
4310
+ $mol_assert_equal($mol_key(/\./gimsu), '/\\./gimsu');
4290
4311
  },
4291
4312
  });
4292
4313
  })($ || ($ = {}));