mol_wire_lib 1.0.178 → 1.0.179

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.js CHANGED
@@ -93,7 +93,7 @@ var $;
93
93
  promote() {
94
94
  $mol_wire_auto()?.track_next(this);
95
95
  }
96
- refresh() { }
96
+ fresh() { }
97
97
  complete() { }
98
98
  emit(quant = $mol_wire_cursor.stale) {
99
99
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -296,7 +296,7 @@ var $;
296
296
  }
297
297
  for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
298
298
  const pub = this.data[cursor];
299
- pub.refresh();
299
+ pub.fresh();
300
300
  }
301
301
  this.cursor = $mol_wire_cursor.fresh;
302
302
  }
@@ -532,18 +532,20 @@ var $;
532
532
  class $mol_after_frame extends $mol_object2 {
533
533
  task;
534
534
  static _promise = null;
535
- static _timeout = null;
536
535
  static get promise() {
537
536
  if (this._promise)
538
537
  return this._promise;
539
538
  return this._promise = new Promise(done => {
540
539
  const complete = () => {
541
540
  this._promise = null;
542
- clearTimeout(this._timeout);
543
541
  done();
544
542
  };
545
- requestAnimationFrame(complete);
546
- this._timeout = setTimeout(complete, 100);
543
+ if (typeof requestAnimationFrame === 'function') {
544
+ requestAnimationFrame(complete);
545
+ }
546
+ else {
547
+ setTimeout(complete, 16);
548
+ }
547
549
  });
548
550
  }
549
551
  cancelled = false;
@@ -596,7 +598,7 @@ var $;
596
598
  continue;
597
599
  if (fiber.cursor === $mol_wire_cursor.final)
598
600
  continue;
599
- fiber.refresh();
601
+ fiber.fresh();
600
602
  }
601
603
  }
602
604
  while (this.reaping.size) {
@@ -664,7 +666,7 @@ var $;
664
666
  else
665
667
  super.emit(quant);
666
668
  }
667
- refresh() {
669
+ fresh() {
668
670
  if (this.cursor === $mol_wire_cursor.fresh)
669
671
  return;
670
672
  if (this.cursor === $mol_wire_cursor.final)
@@ -672,7 +674,7 @@ var $;
672
674
  check: if (this.cursor === $mol_wire_cursor.doubt) {
673
675
  for (let i = this.pub_from; i < this.sub_from; i += 2) {
674
676
  ;
675
- this.data[i]?.refresh();
677
+ this.data[i]?.fresh();
676
678
  if (this.cursor !== $mol_wire_cursor.doubt)
677
679
  break check;
678
680
  }
@@ -728,12 +730,16 @@ var $;
728
730
  this.track_off(bu);
729
731
  this.put(result);
730
732
  }
733
+ refresh() {
734
+ this.cursor = $mol_wire_cursor.stale;
735
+ this.fresh();
736
+ }
731
737
  sync() {
732
738
  if (!$mol_wire_fiber.warm) {
733
739
  return this.result();
734
740
  }
735
741
  this.promote();
736
- this.refresh();
742
+ this.fresh();
737
743
  if (this.cache instanceof Error) {
738
744
  return $mol_fail_hidden(this.cache);
739
745
  }
@@ -744,7 +750,7 @@ var $;
744
750
  }
745
751
  async async() {
746
752
  while (true) {
747
- this.refresh();
753
+ this.fresh();
748
754
  if (this.cache instanceof Error) {
749
755
  $mol_fail_hidden(this.cache);
750
756
  }
@@ -1046,6 +1052,22 @@ var $;
1046
1052
  };
1047
1053
  }
1048
1054
  }
1055
+ static watching = new Set();
1056
+ static watch() {
1057
+ new $mol_after_frame($mol_wire_atom.watch);
1058
+ for (const atom of $mol_wire_atom.watching) {
1059
+ if (atom.cursor === $mol_wire_cursor.final) {
1060
+ $mol_wire_atom.watching.delete(atom);
1061
+ }
1062
+ else {
1063
+ atom.cursor = $mol_wire_cursor.stale;
1064
+ atom.fresh();
1065
+ }
1066
+ }
1067
+ }
1068
+ watch() {
1069
+ $mol_wire_atom.watching.add(this);
1070
+ }
1049
1071
  resync(args) {
1050
1072
  return this.put(this.task.call(this.host, ...args));
1051
1073
  }
@@ -1100,6 +1122,7 @@ var $;
1100
1122
  $mol_wire_method
1101
1123
  ], $mol_wire_atom.prototype, "once", null);
1102
1124
  $.$mol_wire_atom = $mol_wire_atom;
1125
+ $mol_wire_atom.watch();
1103
1126
  })($ || ($ = {}));
1104
1127
  //mol/wire/atom/atom.ts
1105
1128
  ;
@@ -1133,6 +1156,22 @@ var $;
1133
1156
  ;
1134
1157
  "use strict";
1135
1158
  var $;
1159
+ (function ($) {
1160
+ function $mol_wire_watch() {
1161
+ const atom = $mol_wire_auto();
1162
+ if (atom instanceof $mol_wire_atom) {
1163
+ atom.watch();
1164
+ }
1165
+ else {
1166
+ $mol_fail(new Error('Atom is equired for watching'));
1167
+ }
1168
+ }
1169
+ $.$mol_wire_watch = $mol_wire_watch;
1170
+ })($ || ($ = {}));
1171
+ //mol/wire/watch/watch.ts
1172
+ ;
1173
+ "use strict";
1174
+ var $;
1136
1175
  (function ($) {
1137
1176
  function $mol_wire_sync(obj) {
1138
1177
  return new Proxy(obj, {
@@ -1272,6 +1311,39 @@ var $;
1272
1311
  ;
1273
1312
  "use strict";
1274
1313
  var $;
1314
+ (function ($) {
1315
+ function $mol_wire_patch(obj) {
1316
+ for (const field of Reflect.ownKeys(obj)) {
1317
+ const descr = Reflect.getOwnPropertyDescriptor(obj, field);
1318
+ if (!descr.configurable)
1319
+ continue;
1320
+ if (!descr.get)
1321
+ continue;
1322
+ const get = descr.get ?? (() => descr.value);
1323
+ const set = descr.set ?? (next => descr.value = next);
1324
+ const persist = $mol_wire_atom.getter(get, 0);
1325
+ Reflect.defineProperty(obj, field, {
1326
+ configurable: true,
1327
+ enumerable: descr.enumerable,
1328
+ get() {
1329
+ const atom = persist(obj, []);
1330
+ atom.watch();
1331
+ return atom.sync();
1332
+ },
1333
+ set(next) {
1334
+ const atom = persist(obj, []);
1335
+ set.call(this, next);
1336
+ atom.refresh();
1337
+ },
1338
+ });
1339
+ }
1340
+ }
1341
+ $.$mol_wire_patch = $mol_wire_patch;
1342
+ })($ || ($ = {}));
1343
+ //mol/wire/patch/patch.ts
1344
+ ;
1345
+ "use strict";
1346
+ var $;
1275
1347
  (function ($) {
1276
1348
  class $mol_wire_set extends Set {
1277
1349
  pub = new $mol_wire_pub;