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/node.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
  }
@@ -592,7 +592,7 @@ var $;
592
592
  continue;
593
593
  if (fiber.cursor === $mol_wire_cursor.final)
594
594
  continue;
595
- fiber.refresh();
595
+ fiber.fresh();
596
596
  }
597
597
  }
598
598
  while (this.reaping.size) {
@@ -660,7 +660,7 @@ var $;
660
660
  else
661
661
  super.emit(quant);
662
662
  }
663
- refresh() {
663
+ fresh() {
664
664
  if (this.cursor === $mol_wire_cursor.fresh)
665
665
  return;
666
666
  if (this.cursor === $mol_wire_cursor.final)
@@ -668,7 +668,7 @@ var $;
668
668
  check: if (this.cursor === $mol_wire_cursor.doubt) {
669
669
  for (let i = this.pub_from; i < this.sub_from; i += 2) {
670
670
  ;
671
- this.data[i]?.refresh();
671
+ this.data[i]?.fresh();
672
672
  if (this.cursor !== $mol_wire_cursor.doubt)
673
673
  break check;
674
674
  }
@@ -724,12 +724,16 @@ var $;
724
724
  this.track_off(bu);
725
725
  this.put(result);
726
726
  }
727
+ refresh() {
728
+ this.cursor = $mol_wire_cursor.stale;
729
+ this.fresh();
730
+ }
727
731
  sync() {
728
732
  if (!$mol_wire_fiber.warm) {
729
733
  return this.result();
730
734
  }
731
735
  this.promote();
732
- this.refresh();
736
+ this.fresh();
733
737
  if (this.cache instanceof Error) {
734
738
  return $mol_fail_hidden(this.cache);
735
739
  }
@@ -740,7 +744,7 @@ var $;
740
744
  }
741
745
  async async() {
742
746
  while (true) {
743
- this.refresh();
747
+ this.fresh();
744
748
  if (this.cache instanceof Error) {
745
749
  $mol_fail_hidden(this.cache);
746
750
  }
@@ -1042,6 +1046,22 @@ var $;
1042
1046
  };
1043
1047
  }
1044
1048
  }
1049
+ static watching = new Set();
1050
+ static watch() {
1051
+ new $mol_after_frame($mol_wire_atom.watch);
1052
+ for (const atom of $mol_wire_atom.watching) {
1053
+ if (atom.cursor === $mol_wire_cursor.final) {
1054
+ $mol_wire_atom.watching.delete(atom);
1055
+ }
1056
+ else {
1057
+ atom.cursor = $mol_wire_cursor.stale;
1058
+ atom.fresh();
1059
+ }
1060
+ }
1061
+ }
1062
+ watch() {
1063
+ $mol_wire_atom.watching.add(this);
1064
+ }
1045
1065
  resync(args) {
1046
1066
  return this.put(this.task.call(this.host, ...args));
1047
1067
  }
@@ -1096,6 +1116,7 @@ var $;
1096
1116
  $mol_wire_method
1097
1117
  ], $mol_wire_atom.prototype, "once", null);
1098
1118
  $.$mol_wire_atom = $mol_wire_atom;
1119
+ $mol_wire_atom.watch();
1099
1120
  })($ || ($ = {}));
1100
1121
  //mol/wire/atom/atom.ts
1101
1122
  ;
@@ -1129,6 +1150,22 @@ var $;
1129
1150
  ;
1130
1151
  "use strict";
1131
1152
  var $;
1153
+ (function ($) {
1154
+ function $mol_wire_watch() {
1155
+ const atom = $mol_wire_auto();
1156
+ if (atom instanceof $mol_wire_atom) {
1157
+ atom.watch();
1158
+ }
1159
+ else {
1160
+ $mol_fail(new Error('Atom is equired for watching'));
1161
+ }
1162
+ }
1163
+ $.$mol_wire_watch = $mol_wire_watch;
1164
+ })($ || ($ = {}));
1165
+ //mol/wire/watch/watch.ts
1166
+ ;
1167
+ "use strict";
1168
+ var $;
1132
1169
  (function ($) {
1133
1170
  function $mol_wire_sync(obj) {
1134
1171
  return new Proxy(obj, {
@@ -1268,6 +1305,39 @@ var $;
1268
1305
  ;
1269
1306
  "use strict";
1270
1307
  var $;
1308
+ (function ($) {
1309
+ function $mol_wire_patch(obj) {
1310
+ for (const field of Reflect.ownKeys(obj)) {
1311
+ const descr = Reflect.getOwnPropertyDescriptor(obj, field);
1312
+ if (!descr.configurable)
1313
+ continue;
1314
+ if (!descr.get)
1315
+ continue;
1316
+ const get = descr.get ?? (() => descr.value);
1317
+ const set = descr.set ?? (next => descr.value = next);
1318
+ const persist = $mol_wire_atom.getter(get, 0);
1319
+ Reflect.defineProperty(obj, field, {
1320
+ configurable: true,
1321
+ enumerable: descr.enumerable,
1322
+ get() {
1323
+ const atom = persist(obj, []);
1324
+ atom.watch();
1325
+ return atom.sync();
1326
+ },
1327
+ set(next) {
1328
+ const atom = persist(obj, []);
1329
+ set.call(this, next);
1330
+ atom.refresh();
1331
+ },
1332
+ });
1333
+ }
1334
+ }
1335
+ $.$mol_wire_patch = $mol_wire_patch;
1336
+ })($ || ($ = {}));
1337
+ //mol/wire/patch/patch.ts
1338
+ ;
1339
+ "use strict";
1340
+ var $;
1271
1341
  (function ($) {
1272
1342
  class $mol_wire_set extends Set {
1273
1343
  pub = new $mol_wire_pub;