mol_view_tree2_lib 1.0.136 → 1.0.137

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
@@ -187,6 +187,14 @@ var $;
187
187
  $.$mol_func_name_from = $mol_func_name_from;
188
188
  })($ || ($ = {}));
189
189
 
190
+ ;
191
+ "use strict";
192
+ var $;
193
+ (function ($) {
194
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
195
+ $.$mol_key_store = new WeakMap();
196
+ })($ || ($ = {}));
197
+
190
198
  ;
191
199
  "use strict";
192
200
  var $;
@@ -223,6 +231,9 @@ var $;
223
231
  static toJSON() {
224
232
  return this.toString();
225
233
  }
234
+ static [$mol_key_handle]() {
235
+ return this.toString();
236
+ }
226
237
  destructor() { }
227
238
  static destructor() { }
228
239
  [Symbol.dispose]() {
@@ -3056,46 +3067,50 @@ var $;
3056
3067
  "use strict";
3057
3068
  var $;
3058
3069
  (function ($) {
3059
- $.$mol_key_store = new WeakMap();
3060
3070
  const TypedArray = Object.getPrototypeOf(Uint8Array);
3061
3071
  function $mol_key(value) {
3062
- if (typeof value === 'bigint')
3063
- return value.toString() + 'n';
3064
- if (typeof value === 'symbol')
3065
- return value.description;
3066
- if (!value)
3067
- return JSON.stringify(value);
3068
- if (typeof value !== 'object' && typeof value !== 'function')
3069
- return JSON.stringify(value);
3070
- return JSON.stringify(value, (field, value) => {
3072
+ primitives: {
3071
3073
  if (typeof value === 'bigint')
3072
3074
  return value.toString() + 'n';
3073
3075
  if (typeof value === 'symbol')
3074
- return value.description;
3076
+ return `Symbol(${value.description})`;
3075
3077
  if (!value)
3076
- return value;
3078
+ return JSON.stringify(value);
3077
3079
  if (typeof value !== 'object' && typeof value !== 'function')
3078
- return value;
3080
+ return JSON.stringify(value);
3081
+ }
3082
+ caching: {
3083
+ let key = $mol_key_store.get(value);
3084
+ if (key)
3085
+ return key;
3086
+ }
3087
+ objects: {
3088
+ if (value instanceof TypedArray) {
3089
+ return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
3090
+ }
3079
3091
  if (Array.isArray(value))
3080
- return value;
3081
- const proto = Reflect.getPrototypeOf(value);
3082
- if (!proto)
3083
- return value;
3084
- if (Reflect.getPrototypeOf(proto) === null)
3085
- return value;
3086
- if ('toJSON' in value)
3087
- return value;
3092
+ return `[${value.map(v => $mol_key(v))}]`;
3088
3093
  if (value instanceof RegExp)
3089
3094
  return value.toString();
3090
- if (value instanceof TypedArray)
3091
- return [...value];
3092
- let key = $.$mol_key_store.get(value);
3093
- if (key)
3094
- return key;
3095
- key = $mol_guid();
3096
- $.$mol_key_store.set(value, key);
3095
+ if (value instanceof Date)
3096
+ return `Date(${value.valueOf()})`;
3097
+ }
3098
+ structures: {
3099
+ const proto = Reflect.getPrototypeOf(value);
3100
+ if (!proto || !Reflect.getPrototypeOf(proto)) {
3101
+ return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
3102
+ }
3103
+ }
3104
+ handlers: {
3105
+ if ($mol_key_handle in value) {
3106
+ return value[$mol_key_handle]();
3107
+ }
3108
+ }
3109
+ containers: {
3110
+ const key = JSON.stringify('#' + $mol_guid());
3111
+ $mol_key_store.set(value, key);
3097
3112
  return key;
3098
- });
3113
+ }
3099
3114
  }
3100
3115
  $.$mol_key = $mol_key;
3101
3116
  })($ || ($ = {}));
@@ -3620,8 +3635,15 @@ var $;
3620
3635
  (this.host ?? this.task)[this.field()] = null;
3621
3636
  }
3622
3637
  else {
3623
- ;
3624
- (this.host ?? this.task)[this.field()].delete($mol_key(this.args[0]));
3638
+ const key = $mol_key(this.args[0]);
3639
+ const map = (this.host ?? this.task)[this.field()];
3640
+ if (!map.has(key))
3641
+ this.$.$mol_log3_warn({
3642
+ place: this,
3643
+ message: 'Absent key on destruction',
3644
+ hint: 'Check for $mol_key(key) is not changed',
3645
+ });
3646
+ map.delete(key);
3625
3647
  }
3626
3648
  }
3627
3649
  put(next) {
package/node.test.js CHANGED
@@ -178,6 +178,14 @@ var $;
178
178
  $.$mol_func_name_from = $mol_func_name_from;
179
179
  })($ || ($ = {}));
180
180
 
181
+ ;
182
+ "use strict";
183
+ var $;
184
+ (function ($) {
185
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
186
+ $.$mol_key_store = new WeakMap();
187
+ })($ || ($ = {}));
188
+
181
189
  ;
182
190
  "use strict";
183
191
  var $;
@@ -214,6 +222,9 @@ var $;
214
222
  static toJSON() {
215
223
  return this.toString();
216
224
  }
225
+ static [$mol_key_handle]() {
226
+ return this.toString();
227
+ }
217
228
  destructor() { }
218
229
  static destructor() { }
219
230
  [Symbol.dispose]() {
@@ -3047,46 +3058,50 @@ var $;
3047
3058
  "use strict";
3048
3059
  var $;
3049
3060
  (function ($) {
3050
- $.$mol_key_store = new WeakMap();
3051
3061
  const TypedArray = Object.getPrototypeOf(Uint8Array);
3052
3062
  function $mol_key(value) {
3053
- if (typeof value === 'bigint')
3054
- return value.toString() + 'n';
3055
- if (typeof value === 'symbol')
3056
- return value.description;
3057
- if (!value)
3058
- return JSON.stringify(value);
3059
- if (typeof value !== 'object' && typeof value !== 'function')
3060
- return JSON.stringify(value);
3061
- return JSON.stringify(value, (field, value) => {
3063
+ primitives: {
3062
3064
  if (typeof value === 'bigint')
3063
3065
  return value.toString() + 'n';
3064
3066
  if (typeof value === 'symbol')
3065
- return value.description;
3067
+ return `Symbol(${value.description})`;
3066
3068
  if (!value)
3067
- return value;
3069
+ return JSON.stringify(value);
3068
3070
  if (typeof value !== 'object' && typeof value !== 'function')
3069
- return value;
3071
+ return JSON.stringify(value);
3072
+ }
3073
+ caching: {
3074
+ let key = $mol_key_store.get(value);
3075
+ if (key)
3076
+ return key;
3077
+ }
3078
+ objects: {
3079
+ if (value instanceof TypedArray) {
3080
+ return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
3081
+ }
3070
3082
  if (Array.isArray(value))
3071
- return value;
3072
- const proto = Reflect.getPrototypeOf(value);
3073
- if (!proto)
3074
- return value;
3075
- if (Reflect.getPrototypeOf(proto) === null)
3076
- return value;
3077
- if ('toJSON' in value)
3078
- return value;
3083
+ return `[${value.map(v => $mol_key(v))}]`;
3079
3084
  if (value instanceof RegExp)
3080
3085
  return value.toString();
3081
- if (value instanceof TypedArray)
3082
- return [...value];
3083
- let key = $.$mol_key_store.get(value);
3084
- if (key)
3085
- return key;
3086
- key = $mol_guid();
3087
- $.$mol_key_store.set(value, key);
3086
+ if (value instanceof Date)
3087
+ return `Date(${value.valueOf()})`;
3088
+ }
3089
+ structures: {
3090
+ const proto = Reflect.getPrototypeOf(value);
3091
+ if (!proto || !Reflect.getPrototypeOf(proto)) {
3092
+ return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
3093
+ }
3094
+ }
3095
+ handlers: {
3096
+ if ($mol_key_handle in value) {
3097
+ return value[$mol_key_handle]();
3098
+ }
3099
+ }
3100
+ containers: {
3101
+ const key = JSON.stringify('#' + $mol_guid());
3102
+ $mol_key_store.set(value, key);
3088
3103
  return key;
3089
- });
3104
+ }
3090
3105
  }
3091
3106
  $.$mol_key = $mol_key;
3092
3107
  })($ || ($ = {}));
@@ -3611,8 +3626,15 @@ var $;
3611
3626
  (this.host ?? this.task)[this.field()] = null;
3612
3627
  }
3613
3628
  else {
3614
- ;
3615
- (this.host ?? this.task)[this.field()].delete($mol_key(this.args[0]));
3629
+ const key = $mol_key(this.args[0]);
3630
+ const map = (this.host ?? this.task)[this.field()];
3631
+ if (!map.has(key))
3632
+ this.$.$mol_log3_warn({
3633
+ place: this,
3634
+ message: 'Absent key on destruction',
3635
+ hint: 'Check for $mol_key(key) is not changed',
3636
+ });
3637
+ map.delete(key);
3616
3638
  }
3617
3639
  }
3618
3640
  put(next) {
@@ -8989,9 +9011,9 @@ var $;
8989
9011
  $mol_assert_equal($mol_key({ foo: [false] }), '{"foo":[false]}');
8990
9012
  },
8991
9013
  'Uint8Array'() {
8992
- $mol_assert_equal($mol_key(new Uint8Array([1, 2])), '[1,2]');
8993
- $mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[[1,2]]');
8994
- $mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":[1,2]}');
9014
+ $mol_assert_equal($mol_key(new Uint8Array([1, 2])), 'Uint8Array([1,2])');
9015
+ $mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[Uint8Array([1,2])]');
9016
+ $mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":Uint8Array([1,2])}');
8995
9017
  },
8996
9018
  'Function'() {
8997
9019
  const func = () => { };
@@ -9011,6 +9033,12 @@ var $;
9011
9033
  $mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
9012
9034
  },
9013
9035
  'Custom JSON representation'() {
9036
+ class User {
9037
+ toJSON() { return 'jin'; }
9038
+ }
9039
+ $mol_assert_unique([$mol_key(new User)], [$mol_key(new User)]);
9040
+ },
9041
+ 'Custom key handler'() {
9014
9042
  class User {
9015
9043
  name;
9016
9044
  age;
@@ -9018,15 +9046,15 @@ var $;
9018
9046
  this.name = name;
9019
9047
  this.age = age;
9020
9048
  }
9021
- toJSON() { return { name: this.name }; }
9049
+ [$mol_key_handle]() { return `User(${JSON.stringify(this.name)})`; }
9022
9050
  }
9023
- $mol_assert_equal($mol_key(new User('jin', 18)), '{"name":"jin"}');
9051
+ $mol_assert_equal($mol_key([new User('jin', 16)]), $mol_key([new User('jin', 18)]), '[User("jin")]');
9024
9052
  },
9025
9053
  'Special native classes'() {
9026
- $mol_assert_equal($mol_key(new Date('xyz')), 'null');
9027
- $mol_assert_equal($mol_key(new Date('2001-01-02T03:04:05.678Z')), '"2001-01-02T03:04:05.678Z"');
9028
- $mol_assert_equal($mol_key(/./), '"/./"');
9029
- $mol_assert_equal($mol_key(/\./gimsu), '"/\\\\./gimsu"');
9054
+ $mol_assert_equal($mol_key(new Date('xyz')), 'Date(NaN)');
9055
+ $mol_assert_equal($mol_key(new Date(12345)), 'Date(12345)');
9056
+ $mol_assert_equal($mol_key(/./), '/./');
9057
+ $mol_assert_equal($mol_key(/\./gimsu), '/\\./gimsu');
9030
9058
  },
9031
9059
  });
9032
9060
  })($ || ($ = {}));