mol_wire_lib 1.0.1229 → 1.0.1231

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
@@ -618,7 +618,7 @@ var $;
618
618
  "use strict";
619
619
  var $;
620
620
  (function ($) {
621
- const handled = new WeakSet();
621
+ const wrappers = new WeakMap();
622
622
  class $mol_wire_fiber extends $mol_wire_pub_sub {
623
623
  task;
624
624
  host;
@@ -753,13 +753,21 @@ var $;
753
753
  result = this.task.call(this.host, ...this.args);
754
754
  break;
755
755
  }
756
- if ($mol_promise_like(result) && !handled.has(result)) {
757
- const put = (res) => {
758
- if (this.cache === result)
759
- this.put(res);
760
- return res;
761
- };
762
- result = result.then(put, put);
756
+ if ($mol_promise_like(result)) {
757
+ if (wrappers.has(result)) {
758
+ result = wrappers.get(result).then(a => a);
759
+ }
760
+ else {
761
+ const put = (res) => {
762
+ if (this.cache === result)
763
+ this.put(res);
764
+ return res;
765
+ };
766
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
767
+ wrappers.set(result, result);
768
+ const error = new Error(`Promise in ${this}`);
769
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
770
+ }
763
771
  }
764
772
  }
765
773
  catch (error) {
@@ -769,21 +777,20 @@ var $;
769
777
  else {
770
778
  result = new Error(String(error), { cause: error });
771
779
  }
772
- if ($mol_promise_like(result) && !handled.has(result)) {
773
- result = result.finally(() => {
774
- if (this.cache === result)
775
- this.absorb();
776
- });
780
+ if ($mol_promise_like(result)) {
781
+ if (wrappers.has(result)) {
782
+ result = wrappers.get(result);
783
+ }
784
+ else {
785
+ wrappers.set(result, result = Object.assign(result.finally(() => {
786
+ if (this.cache === result)
787
+ this.absorb();
788
+ }), { destructor: result.destructor || (() => { }) }));
789
+ const error = new Error(`Promise in ${this}`);
790
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
791
+ }
777
792
  }
778
793
  }
779
- if ($mol_promise_like(result) && !handled.has(result)) {
780
- result = Object.assign(result, {
781
- destructor: result['destructor'] ?? (() => { })
782
- });
783
- handled.add(result);
784
- const error = new Error(`Promise in ${this}`);
785
- Object.defineProperty(result, 'stack', { get: () => error.stack });
786
- }
787
794
  if (!$mol_promise_like(result)) {
788
795
  this.track_cut();
789
796
  }
@@ -1125,6 +1132,7 @@ var $;
1125
1132
  var $;
1126
1133
  (function ($) {
1127
1134
  $.$mol_key_store = new WeakMap();
1135
+ const TypedArray = Object.getPrototypeOf(Uint8Array);
1128
1136
  function $mol_key(value) {
1129
1137
  if (typeof value === 'bigint')
1130
1138
  return value.toString() + 'n';
@@ -1154,7 +1162,7 @@ var $;
1154
1162
  return value;
1155
1163
  if (value instanceof RegExp)
1156
1164
  return value.toString();
1157
- if (value instanceof Uint8Array)
1165
+ if (value instanceof TypedArray)
1158
1166
  return [...value];
1159
1167
  let key = $.$mol_key_store.get(value);
1160
1168
  if (key)