@solidjs/signals 0.2.3 → 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
@@ -1117,12 +1117,15 @@ function resolve(fn) {
1117
1117
 
1118
1118
  // src/store/projection.ts
1119
1119
  function createProjection(fn, initialValue = {}) {
1120
- const [store, setStore] = createStore(initialValue);
1120
+ const [store] = createStore(fn, initialValue);
1121
+ return store;
1122
+ }
1123
+ function wrapProjection(fn, store, setStore) {
1121
1124
  const node = new ProjectionComputation(() => {
1122
1125
  setStore(fn);
1123
1126
  });
1124
1127
  const wrapped = /* @__PURE__ */ new WeakMap();
1125
- return wrap(store, node, wrapped);
1128
+ return [wrap(store, node, wrapped), setStore];
1126
1129
  }
1127
1130
  function wrap(source, node, wrapped) {
1128
1131
  if (wrapped.has(source))
@@ -1320,10 +1323,8 @@ function setProperty(state, property, value, deleting = false) {
1320
1323
  }
1321
1324
  function createStore(first, second) {
1322
1325
  const derived = typeof first === "function", store = derived ? second : first;
1323
- if (derived)
1324
- return createProjection(first, store);
1325
1326
  const unwrappedStore = unwrap(store, false);
1326
- const wrappedStore = wrap2(unwrappedStore);
1327
+ let wrappedStore = wrap2(unwrappedStore);
1327
1328
  const setStore = (fn) => {
1328
1329
  try {
1329
1330
  Writing.add(unwrappedStore);
@@ -1332,6 +1333,8 @@ function createStore(first, second) {
1332
1333
  Writing.clear();
1333
1334
  }
1334
1335
  };
1336
+ if (derived)
1337
+ return wrapProjection(first, wrappedStore, setStore);
1335
1338
  return [wrappedStore, setStore];
1336
1339
  }
1337
1340
 
@@ -1718,15 +1721,18 @@ function repeat(count, map, options) {
1718
1721
  return updateRepeat.bind({
1719
1722
  _owner: new Owner(),
1720
1723
  _len: 0,
1724
+ _offset: 0,
1721
1725
  _count: count,
1722
1726
  _map: map,
1723
1727
  _nodes: [],
1724
1728
  _mappings: [],
1729
+ _from: options?.from,
1725
1730
  _fallback: options?.fallback
1726
1731
  });
1727
1732
  }
1728
1733
  function updateRepeat() {
1729
1734
  const newLen = this._count();
1735
+ const from = this._from?.() || 0;
1730
1736
  runWithOwner(this._owner, () => {
1731
1737
  if (newLen === 0) {
1732
1738
  if (this._len !== 0) {
@@ -1742,21 +1748,47 @@ function updateRepeat() {
1742
1748
  null
1743
1749
  );
1744
1750
  }
1745
- } else {
1746
- if (this._len === 0 && this._nodes[0])
1747
- this._nodes[0].dispose();
1748
- for (let i = this._len; i < newLen; i++) {
1749
- this._mappings[i] = compute(
1750
- this._nodes[i] = new Owner(),
1751
- () => 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),
1752
1778
  null
1753
1779
  );
1754
1780
  }
1755
- for (let i = newLen; i < this._len; i++)
1756
- this._nodes[i].dispose();
1757
- this._mappings = this._mappings.slice(0, newLen);
1758
- this._len = newLen;
1759
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;
1760
1792
  });
1761
1793
  return this._mappings;
1762
1794
  }