mol_jsx_lib 0.0.1665 → 0.0.1667

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
@@ -503,10 +503,12 @@ var $;
503
503
  $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
504
504
  /** Some of (transitive) pub update required. */
505
505
  $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
506
+ /** Doubt check in progress, so any incoming quant is noticeable. */
507
+ $mol_wire_cursor[$mol_wire_cursor["check"] = -3] = "check";
506
508
  /** Actual state but may be dropped. */
507
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
509
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -4] = "fresh";
508
510
  /** State will never be changed. */
509
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
511
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -5] = "final";
510
512
  })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
511
513
  })($ || ($ = {}));
512
514
 
@@ -585,6 +587,12 @@ var $;
585
587
  * Enforce actualization. Should not throw errors.
586
588
  */
587
589
  fresh() { }
590
+ /**
591
+ * Lives inside single calculation of subscriber or not.
592
+ */
593
+ get temp() {
594
+ return false;
595
+ }
588
596
  /**
589
597
  * Allow to put data to caches in the subtree.
590
598
  */
@@ -890,9 +898,6 @@ var $;
890
898
  class $mol_wire_pub_sub extends $mol_wire_pub {
891
899
  pub_from = 0; // 4B
892
900
  cursor = $mol_wire_cursor.stale; // 4B
893
- get temp() {
894
- return false;
895
- }
896
901
  get pub_list() {
897
902
  const res = [];
898
903
  const max = this.cursor >= 0 ? this.cursor : this.sub_from;
@@ -912,6 +917,9 @@ var $;
912
917
  if (this.cursor >= this.pub_from) {
913
918
  $mol_fail(new Error('Circular subscription'));
914
919
  }
920
+ if (this.cursor === $mol_wire_cursor.check) {
921
+ $mol_fail(new Error('Circular checking'));
922
+ }
915
923
  super.promote();
916
924
  }
917
925
  track_next(pub) {
@@ -953,7 +961,8 @@ var $;
953
961
  }
954
962
  for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
955
963
  const pub = this.data[cursor];
956
- pub.fresh();
964
+ // Slot may be cleared by pub_off when a temp was destroyed mid-calc.
965
+ pub?.fresh();
957
966
  }
958
967
  this.cursor = $mol_wire_cursor.fresh;
959
968
  }
@@ -962,6 +971,10 @@ var $;
962
971
  this.data[sub_pos + 1] = undefined;
963
972
  }
964
973
  destructor() {
974
+ // Mid-calc destroy (absorb restarts a temp): stop promoting into this
975
+ // fiber so track_next does not throw 'Promo to non begun sub'.
976
+ if ($mol_wire_auto() === this)
977
+ $mol_wire_auto(null);
965
978
  for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
966
979
  const sub = this.data[cursor];
967
980
  const pos = this.data[cursor + 1];
@@ -1007,20 +1020,21 @@ var $;
1007
1020
  return;
1008
1021
  this.cursor = quant;
1009
1022
  this.emit($mol_wire_cursor.doubt);
1010
- // if( pos >= 0 && pos < this.sub_from - 2 ) {
1011
- // const pub = this.data[ pos ] as $mol_wire_pub
1012
- // if( pub instanceof $mol_wire_task ) return
1013
- // for(
1014
- // let cursor = this.pub_from;
1015
- // cursor < this.sub_from;
1016
- // cursor += 2
1017
- // ) {
1018
- // const pub = this.data[ cursor ] as $mol_wire_pub
1019
- // if( pub instanceof $mol_wire_task ) {
1020
- // pub.destructor()
1021
- // }
1022
- // }
1023
- // }
1023
+ if (quant !== $mol_wire_cursor.stale)
1024
+ return;
1025
+ if (!this.incompleted)
1026
+ return;
1027
+ // Notice from own task resumes the same calculation, but from a regular
1028
+ // pub it makes awaited tasks based on outdated data, so restart them.
1029
+ const pub = this.data[pos];
1030
+ if (pub?.temp)
1031
+ return;
1032
+ for (let cursor = this.pub_from; cursor < this.sub_from; cursor += 2) {
1033
+ const pub = this.data[cursor];
1034
+ if (pub?.temp) {
1035
+ pub.destructor();
1036
+ }
1037
+ }
1024
1038
  }
1025
1039
  [$mol_dev_format_head]() {
1026
1040
  return $mol_dev_format_native(this);
@@ -1175,7 +1189,8 @@ var $;
1175
1189
  [$mol_dev_format_head]() {
1176
1190
  const cursor = {
1177
1191
  [$mol_wire_cursor.stale]: '🔴',
1178
- [$mol_wire_cursor.doubt]: '🟡',
1192
+ [$mol_wire_cursor.doubt]: '🟠',
1193
+ [$mol_wire_cursor.check]: '🟡',
1179
1194
  [$mol_wire_cursor.fresh]: '🟢',
1180
1195
  [$mol_wire_cursor.final]: '🔵',
1181
1196
  }[this.cursor] ?? this.cursor.toString();
@@ -1199,10 +1214,11 @@ var $;
1199
1214
  if (this.cursor === $mol_wire_cursor.final)
1200
1215
  return;
1201
1216
  check: if (this.cursor === $mol_wire_cursor.doubt) {
1217
+ this.cursor = $mol_wire_cursor.check;
1202
1218
  for (let i = this.pub_from; i < this.sub_from; i += 2) {
1203
1219
  ;
1204
1220
  this.data[i]?.fresh();
1205
- if (this.cursor !== $mol_wire_cursor.doubt)
1221
+ if (this.cursor !== $mol_wire_cursor.check)
1206
1222
  break check;
1207
1223
  }
1208
1224
  this.cursor = $mol_wire_cursor.fresh;
@@ -1211,62 +1227,74 @@ var $;
1211
1227
  const bu = this.track_on();
1212
1228
  let result;
1213
1229
  try {
1214
- switch (this.pub_from) {
1215
- case 0:
1216
- result = this.task.call(this.host);
1217
- break;
1218
- case 1:
1219
- result = this.task.call(this.host, this.data[0]);
1220
- break;
1221
- default:
1222
- result = this.task.call(this.host, ...this.args);
1223
- break;
1224
- }
1225
- if ($mol_promise_like(result)) {
1226
- if (wrappers.has(result)) {
1227
- result = wrappers.get(result).then(a => a);
1230
+ try {
1231
+ switch (this.pub_from) {
1232
+ case 0:
1233
+ result = this.task.call(this.host);
1234
+ break;
1235
+ case 1:
1236
+ result = this.task.call(this.host, this.data[0]);
1237
+ break;
1238
+ default:
1239
+ result = this.task.call(this.host, ...this.args);
1240
+ break;
1228
1241
  }
1229
- else {
1230
- const put = (res) => {
1231
- if (this.cache === result)
1232
- this.put(res);
1233
- return res;
1234
- };
1235
- wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1236
- wrappers.set(result, result);
1237
- const error = new Error(`Promise in ${this}`);
1238
- Object.defineProperty(result, 'stack', { get: () => error.stack });
1242
+ if ($mol_promise_like(result)) {
1243
+ if (wrappers.has(result)) {
1244
+ result = wrappers.get(result).then(a => a);
1245
+ }
1246
+ else {
1247
+ const put = (res) => {
1248
+ if (this.cache === result)
1249
+ this.put(res);
1250
+ return res;
1251
+ };
1252
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1253
+ wrappers.set(result, result);
1254
+ const error = new Error(`Promise in ${this}`);
1255
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1256
+ }
1239
1257
  }
1240
1258
  }
1241
- }
1242
- catch (error) {
1243
- if (error instanceof Error || $mol_promise_like(error)) {
1244
- result = error;
1245
- }
1246
- else {
1247
- result = new Error(String(error), { cause: error });
1248
- }
1249
- if ($mol_promise_like(result)) {
1250
- if (wrappers.has(result)) {
1251
- result = wrappers.get(result);
1259
+ catch (error) {
1260
+ if (error instanceof Error || $mol_promise_like(error)) {
1261
+ result = error;
1252
1262
  }
1253
1263
  else {
1254
- const put = (v) => {
1255
- if (this.cache === result)
1256
- this.absorb();
1257
- return v;
1258
- };
1259
- wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1260
- const error = new Error(`Promise in ${this}`);
1261
- Object.defineProperty(result, 'stack', { get: () => error.stack });
1264
+ result = new Error(String(error), { cause: error });
1262
1265
  }
1266
+ if ($mol_promise_like(result)) {
1267
+ if (wrappers.has(result)) {
1268
+ result = wrappers.get(result);
1269
+ }
1270
+ else {
1271
+ const put = (v) => {
1272
+ if (this.cache === result)
1273
+ this.absorb();
1274
+ return v;
1275
+ };
1276
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1277
+ const error = new Error(`Promise in ${this}`);
1278
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1279
+ }
1280
+ }
1281
+ }
1282
+ // Temp destroyed mid-calc (absorb restart): cut/off would throw.
1283
+ if (this.cursor < this.pub_from)
1284
+ return this;
1285
+ if (!$mol_promise_like(result)) {
1286
+ this.track_cut();
1263
1287
  }
1288
+ this.track_off(bu);
1289
+ this.put(result);
1264
1290
  }
1265
- if (!$mol_promise_like(result)) {
1266
- this.track_cut();
1291
+ finally {
1292
+ // If cut threw or destructor nulled auto — put outer back
1293
+ // (else once()/onclose → Promo to non begun sub).
1294
+ if ($mol_wire_auto() === this || !$mol_wire_auto()) {
1295
+ $mol_wire_auto(bu);
1296
+ }
1267
1297
  }
1268
- this.track_off(bu);
1269
- this.put(result);
1270
1298
  return this;
1271
1299
  }
1272
1300
  refresh() {