@solidjs/signals 0.0.1 → 0.0.3

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
@@ -624,13 +624,8 @@ function runPureQueue(queue) {
624
624
  }
625
625
  }
626
626
  function runEffectQueue(queue) {
627
- for (let i = 0; i < queue.length; i++) {
628
- if (queue[i]._modified && queue[i]._state !== STATE_DISPOSED) {
629
- queue[i]._effect(queue[i]._value, queue[i]._prevValue);
630
- queue[i]._modified = false;
631
- queue[i]._prevValue = queue[i]._value;
632
- }
633
- }
627
+ for (let i = 0; i < queue.length; i++)
628
+ queue[i]._runEffect();
634
629
  }
635
630
 
636
631
  // src/core/effect.ts
@@ -646,8 +641,8 @@ var Effect = class extends Computation {
646
641
  this._prevValue = initialValue;
647
642
  this._type = options?.render ? EFFECT_RENDER : EFFECT_USER;
648
643
  this._queue = getOwner()?._queue || globalQueue;
649
- this._queue.enqueue(this._type, this);
650
644
  this._updateIfNecessary();
645
+ this._type === EFFECT_USER ? this._queue.enqueue(this._type, this) : this._runEffect();
651
646
  }
652
647
  write(value, flags = 0) {
653
648
  const currentFlags = this._stateFlags;
@@ -676,6 +671,13 @@ var Effect = class extends Computation {
676
671
  this._prevValue = void 0;
677
672
  super._disposeNode();
678
673
  }
674
+ _runEffect() {
675
+ if (this._modified && this._state !== STATE_DISPOSED) {
676
+ this._effect(this._value, this._prevValue);
677
+ this._prevValue = this._value;
678
+ this._modified = false;
679
+ }
680
+ }
679
681
  };
680
682
  var EagerComputation = class extends Computation {
681
683
  _queue;
@@ -850,15 +852,22 @@ var STORE_NODE = "n";
850
852
  var STORE_HAS = "h";
851
853
  function wrap(value) {
852
854
  let p = value[$PROXY];
853
- if (!p)
855
+ if (!p) {
856
+ let target;
857
+ if (Array.isArray(value)) {
858
+ target = [];
859
+ target.v = value;
860
+ } else
861
+ target = { v: value };
854
862
  Object.defineProperty(value, $PROXY, {
855
- value: p = new Proxy({ v: value }, proxyTraps),
863
+ value: p = new Proxy(target, proxyTraps),
856
864
  writable: true
857
865
  });
866
+ }
858
867
  return p;
859
868
  }
860
869
  function isWrappable(obj) {
861
- return obj != null && typeof obj === "object";
870
+ return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
862
871
  }
863
872
  function unwrap(item, deep = true, set) {
864
873
  let result, unwrapped, v, prop;
@@ -910,8 +919,10 @@ function getNode(nodes, property, value, equals = isEqual) {
910
919
  });
911
920
  }
912
921
  function proxyDescriptor(target, property) {
922
+ if (property === $PROXY)
923
+ return { value: target[$PROXY], writable: true, configurable: true };
913
924
  const desc = Reflect.getOwnPropertyDescriptor(target[STORE_VALUE], property);
914
- if (!desc || desc.get || !desc.configurable || property === $PROXY)
925
+ if (!desc || desc.get || !desc.configurable)
915
926
  return desc;
916
927
  delete desc.value;
917
928
  delete desc.writable;
@@ -977,7 +988,10 @@ var proxyTraps = {
977
988
  return true;
978
989
  },
979
990
  ownKeys,
980
- getOwnPropertyDescriptor: proxyDescriptor
991
+ getOwnPropertyDescriptor: proxyDescriptor,
992
+ getPrototypeOf(target) {
993
+ return Object.getPrototypeOf(target[STORE_VALUE]);
994
+ }
981
995
  };
982
996
  function setProperty(state, property, value, deleting = false) {
983
997
  const prev = state[property];
@@ -1131,6 +1145,7 @@ function reconcile(value, key) {
1131
1145
  if (keyFn(value) !== keyFn(state))
1132
1146
  throw new Error("Cannot reconcile states with different identity");
1133
1147
  applyState(value, state, keyFn);
1148
+ return state;
1134
1149
  };
1135
1150
  }
1136
1151
 
@@ -1171,7 +1186,7 @@ function resolveSource(s) {
1171
1186
  }
1172
1187
  var $SOURCES = Symbol("MERGE_SOURCE" );
1173
1188
  function merge(...sources) {
1174
- if (sources.length === 1)
1189
+ if (sources.length === 1 && typeof sources[0] !== "function")
1175
1190
  return sources[0];
1176
1191
  let proxy = false;
1177
1192
  const flattened = [];
@@ -1285,24 +1300,19 @@ function omit(props, ...keys) {
1285
1300
  // src/map.ts
1286
1301
  function mapArray(list, map, options) {
1287
1302
  const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
1288
- return Computation.prototype.read.bind(
1289
- new Computation(
1290
- [],
1291
- updateKeyedMap.bind({
1292
- _owner: new Owner(),
1293
- _len: 0,
1294
- _list: list,
1295
- _items: [],
1296
- _map: map,
1297
- _mappings: [],
1298
- _nodes: [],
1299
- _key: keyFn,
1300
- _rows: keyFn || options?.keyed === false ? [] : void 0,
1301
- _indexes: map.length > 1 ? [] : void 0
1302
- }),
1303
- options
1304
- )
1305
- );
1303
+ return updateKeyedMap.bind({
1304
+ _owner: new Owner(),
1305
+ _len: 0,
1306
+ _list: list,
1307
+ _items: [],
1308
+ _map: map,
1309
+ _mappings: [],
1310
+ _nodes: [],
1311
+ _key: keyFn,
1312
+ _rows: keyFn || options?.keyed === false ? [] : void 0,
1313
+ _indexes: map.length > 1 ? [] : void 0,
1314
+ _fallback: options?.fallback
1315
+ });
1306
1316
  }
1307
1317
  function updateKeyedMap() {
1308
1318
  const newItems = this._list() || [], newLen = newItems.length;
@@ -1333,7 +1343,12 @@ function updateKeyedMap() {
1333
1343
  this._rows && (this._rows = []);
1334
1344
  this._indexes && (this._indexes = []);
1335
1345
  }
1346
+ if (this._fallback && !this._mappings[0]) {
1347
+ this._mappings[0] = compute(this._nodes[0] = new Owner(), this._fallback, null);
1348
+ }
1336
1349
  } else if (this._len === 0) {
1350
+ if (this._nodes[0])
1351
+ this._nodes[0].dispose();
1337
1352
  this._mappings = new Array(newLen);
1338
1353
  for (j = 0; j < newLen; j++) {
1339
1354
  this._items[j] = newItems[j];
@@ -1401,4 +1416,4 @@ function compare(key, a, b) {
1401
1416
  return key ? key(a) === key(b) : true;
1402
1417
  }
1403
1418
 
1404
- export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, catchError, createAsync, createBoundary, createContext, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, runWithOwner, setContext, untrack, unwrap };
1419
+ export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, runWithOwner, setContext, untrack, unwrap };