@solidjs/signals 0.2.2 → 0.2.4

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/dist/dev.js CHANGED
@@ -138,60 +138,6 @@ function runEffectQueue(queue) {
138
138
  function isUndefined(value) {
139
139
  return typeof value === "undefined";
140
140
  }
141
- function flatten(children, options) {
142
- if (typeof children === "function" && !children.length) {
143
- if (options?.doNotUnwrap)
144
- return children;
145
- do {
146
- children = children();
147
- } while (typeof children === "function" && !children.length);
148
- }
149
- if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
150
- return;
151
- if (Array.isArray(children)) {
152
- let results = [];
153
- if (flattenArray(children, results, options)) {
154
- return () => {
155
- let nested = [];
156
- flattenArray(results, nested, { ...options, doNotUnwrap: false });
157
- return nested;
158
- };
159
- }
160
- return results;
161
- }
162
- return children;
163
- }
164
- function flattenArray(children, results = [], options) {
165
- let notReady = null;
166
- let needsUnwrap = false;
167
- for (let i = 0; i < children.length; i++) {
168
- try {
169
- let child = children[i];
170
- if (typeof child === "function" && !child.length) {
171
- if (options?.doNotUnwrap) {
172
- results.push(child);
173
- needsUnwrap = true;
174
- continue;
175
- }
176
- do {
177
- child = child();
178
- } while (typeof child === "function" && !child.length);
179
- }
180
- if (Array.isArray(child)) {
181
- needsUnwrap = flattenArray(child, results, options);
182
- } else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
183
- } else
184
- results.push(child);
185
- } catch (e) {
186
- if (!(e instanceof NotReadyError))
187
- throw e;
188
- notReady = e;
189
- }
190
- }
191
- if (notReady)
192
- throw notReady;
193
- return needsUnwrap;
194
- }
195
141
 
196
142
  // src/core/owner.ts
197
143
  var currentOwner = null;
@@ -754,6 +700,68 @@ function compute(owner, fn, observer) {
754
700
  notStale = prevNotStale;
755
701
  }
756
702
  }
703
+ function flatten(children, options) {
704
+ try {
705
+ if (typeof children === "function" && !children.length) {
706
+ if (options?.doNotUnwrap)
707
+ return children;
708
+ do {
709
+ children = children();
710
+ } while (typeof children === "function" && !children.length);
711
+ }
712
+ if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
713
+ return;
714
+ if (Array.isArray(children)) {
715
+ let results = [];
716
+ if (flattenArray(children, results, options)) {
717
+ return () => {
718
+ let nested = [];
719
+ flattenArray(results, nested, { ...options, doNotUnwrap: false });
720
+ return nested;
721
+ };
722
+ }
723
+ return results;
724
+ }
725
+ return children;
726
+ } catch (e) {
727
+ if (options?.skipNonRendered && e instanceof NotReadyError) {
728
+ newFlags |= LOADING_BIT;
729
+ return void 0;
730
+ }
731
+ throw e;
732
+ }
733
+ }
734
+ function flattenArray(children, results = [], options) {
735
+ let notReady = null;
736
+ let needsUnwrap = false;
737
+ for (let i = 0; i < children.length; i++) {
738
+ try {
739
+ let child = children[i];
740
+ if (typeof child === "function" && !child.length) {
741
+ if (options?.doNotUnwrap) {
742
+ results.push(child);
743
+ needsUnwrap = true;
744
+ continue;
745
+ }
746
+ do {
747
+ child = child();
748
+ } while (typeof child === "function" && !child.length);
749
+ }
750
+ if (Array.isArray(child)) {
751
+ needsUnwrap = flattenArray(child, results, options);
752
+ } else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
753
+ } else
754
+ results.push(child);
755
+ } catch (e) {
756
+ if (!(e instanceof NotReadyError))
757
+ throw e;
758
+ notReady = e;
759
+ }
760
+ }
761
+ if (notReady)
762
+ throw notReady;
763
+ return needsUnwrap;
764
+ }
757
765
  function createBoundary(fn, queue) {
758
766
  const owner = new Owner();
759
767
  const parentQueue = owner._queue;
@@ -777,7 +785,7 @@ var Effect = class extends Computation {
777
785
  this._prevValue = initialValue;
778
786
  this._type = options?.render ? EFFECT_RENDER : EFFECT_USER;
779
787
  if (this._type === EFFECT_RENDER) {
780
- this._compute = (p) => getClock() > this._queue.created ? latest(() => compute2(p)) : compute2(p);
788
+ this._compute = (p) => getClock() > this._queue.created && !(this._stateFlags & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
781
789
  }
782
790
  this._updateIfNecessary();
783
791
  !options?.defer && (this._type === EFFECT_USER ? this._queue.enqueue(this._type, this) : this._runEffect());
@@ -808,9 +816,9 @@ var Effect = class extends Computation {
808
816
  _setError(error) {
809
817
  this._cleanup?.();
810
818
  if (this._stateFlags & LOADING_BIT) {
811
- this._stateFlags = 0;
812
819
  this._queue._update?.(this);
813
820
  }
821
+ this._stateFlags = ERROR_BIT;
814
822
  if (this._type === EFFECT_USER) {
815
823
  try {
816
824
  return this._onerror ? this._cleanup = this._onerror(error) : console.error(new EffectError(this._effect, error));
@@ -1109,12 +1117,15 @@ function resolve(fn) {
1109
1117
 
1110
1118
  // src/store/projection.ts
1111
1119
  function createProjection(fn, initialValue = {}) {
1112
- const [store, setStore] = createStore(initialValue);
1120
+ const [store] = createStore(fn, initialValue);
1121
+ return store;
1122
+ }
1123
+ function wrapProjection(fn, store, setStore) {
1113
1124
  const node = new ProjectionComputation(() => {
1114
1125
  setStore(fn);
1115
1126
  });
1116
1127
  const wrapped = /* @__PURE__ */ new WeakMap();
1117
- return wrap(store, node, wrapped);
1128
+ return [wrap(store, node, wrapped), setStore];
1118
1129
  }
1119
1130
  function wrap(source, node, wrapped) {
1120
1131
  if (wrapped.has(source))
@@ -1312,10 +1323,8 @@ function setProperty(state, property, value, deleting = false) {
1312
1323
  }
1313
1324
  function createStore(first, second) {
1314
1325
  const derived = typeof first === "function", store = derived ? second : first;
1315
- if (derived)
1316
- return createProjection(first, store);
1317
1326
  const unwrappedStore = unwrap(store, false);
1318
- const wrappedStore = wrap2(unwrappedStore);
1327
+ let wrappedStore = wrap2(unwrappedStore);
1319
1328
  const setStore = (fn) => {
1320
1329
  try {
1321
1330
  Writing.add(unwrappedStore);
@@ -1324,6 +1333,8 @@ function createStore(first, second) {
1324
1333
  Writing.clear();
1325
1334
  }
1326
1335
  };
1336
+ if (derived)
1337
+ return wrapProjection(first, wrappedStore, setStore);
1327
1338
  return [wrappedStore, setStore];
1328
1339
  }
1329
1340
 
@@ -1439,7 +1450,7 @@ function reconcile(value, key) {
1439
1450
  };
1440
1451
  }
1441
1452
 
1442
- // src/store/utilities.ts
1453
+ // src/store/utils.ts
1443
1454
  function trueFn() {
1444
1455
  return true;
1445
1456
  }
@@ -1710,15 +1721,18 @@ function repeat(count, map, options) {
1710
1721
  return updateRepeat.bind({
1711
1722
  _owner: new Owner(),
1712
1723
  _len: 0,
1724
+ _offset: 0,
1713
1725
  _count: count,
1714
1726
  _map: map,
1715
1727
  _nodes: [],
1716
1728
  _mappings: [],
1729
+ _from: options?.from,
1717
1730
  _fallback: options?.fallback
1718
1731
  });
1719
1732
  }
1720
1733
  function updateRepeat() {
1721
1734
  const newLen = this._count();
1735
+ const from = this._from?.() || 0;
1722
1736
  runWithOwner(this._owner, () => {
1723
1737
  if (newLen === 0) {
1724
1738
  if (this._len !== 0) {
@@ -1734,21 +1748,47 @@ function updateRepeat() {
1734
1748
  null
1735
1749
  );
1736
1750
  }
1737
- } else {
1738
- if (this._len === 0 && this._nodes[0])
1739
- this._nodes[0].dispose();
1740
- for (let i = this._len; i < newLen; i++) {
1741
- this._mappings[i] = compute(
1742
- this._nodes[i] = new Owner(),
1743
- () => this._map(i),
1751
+ return;
1752
+ }
1753
+ const to = from + newLen;
1754
+ const prevTo = this._offset + this._len;
1755
+ if (this._len === 0 && this._nodes[0])
1756
+ this._nodes[0].dispose();
1757
+ for (let i = to; i < prevTo; i++)
1758
+ this._nodes[i - this._offset].dispose();
1759
+ if (this._offset < from) {
1760
+ let i = this._offset;
1761
+ while (i < from && i < this._len)
1762
+ this._nodes[i++].dispose();
1763
+ this._nodes.splice(0, from - this._offset);
1764
+ this._mappings.splice(0, from - this._offset);
1765
+ } else if (this._offset > from) {
1766
+ let i = prevTo - this._offset - 1;
1767
+ let difference = this._offset - from;
1768
+ this._nodes.length = this._mappings.length = newLen;
1769
+ while (i >= difference) {
1770
+ this._nodes[i] = this._nodes[i - difference];
1771
+ this._mappings[i] = this._mappings[i - difference];
1772
+ i--;
1773
+ }
1774
+ for (let i2 = 0; i2 < difference; i2++) {
1775
+ this._mappings[i2] = compute(
1776
+ this._nodes[i2] = new Owner(),
1777
+ () => this._map(i2 + from),
1744
1778
  null
1745
1779
  );
1746
1780
  }
1747
- for (let i = newLen; i < this._len; i++)
1748
- this._nodes[i].dispose();
1749
- this._mappings = this._mappings.slice(0, newLen);
1750
- this._len = newLen;
1751
1781
  }
1782
+ for (let i = prevTo; i < to; i++) {
1783
+ this._mappings[i - from] = compute(
1784
+ this._nodes[i - from] = new Owner(),
1785
+ () => this._map(i),
1786
+ null
1787
+ );
1788
+ }
1789
+ this._mappings = this._mappings.slice(0, newLen);
1790
+ this._offset = from;
1791
+ this._len = newLen;
1752
1792
  });
1753
1793
  return this._mappings;
1754
1794
  }