@solidjs/signals 0.0.1 → 0.0.2

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;
@@ -1171,7 +1173,7 @@ function resolveSource(s) {
1171
1173
  }
1172
1174
  var $SOURCES = Symbol("MERGE_SOURCE" );
1173
1175
  function merge(...sources) {
1174
- if (sources.length === 1)
1176
+ if (sources.length === 1 && typeof sources[0] !== "function")
1175
1177
  return sources[0];
1176
1178
  let proxy = false;
1177
1179
  const flattened = [];
package/dist/node.cjs CHANGED
@@ -198,32 +198,32 @@ var Computation = class extends Owner {
198
198
  b = null;
199
199
  c = null;
200
200
  d;
201
- C;
201
+ D;
202
202
  // Used in __DEV__ mode, hopefully removed in production
203
- U;
203
+ V;
204
204
  // Using false is an optimization as an alternative to _equals: () => false
205
205
  // which could enable more efficient DIRTY notification
206
- D = isEqual;
206
+ E = isEqual;
207
207
  N;
208
208
  /** Whether the computation is an error or has ancestors that are unresolved */
209
209
  i = 0;
210
210
  /** Which flags raised by sources are handled, vs. being passed through. */
211
211
  A = DEFAULT_FLAGS;
212
- E = null;
213
212
  F = null;
214
- G = -1;
213
+ G = null;
214
+ H = -1;
215
215
  constructor(initialValue, compute2, options) {
216
216
  super(compute2 === null);
217
- this.C = compute2;
217
+ this.D = compute2;
218
218
  this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
219
219
  this.d = initialValue;
220
220
  if ((options == null ? void 0 : options.equals) !== void 0)
221
- this.D = options.equals;
221
+ this.E = options.equals;
222
222
  if (options == null ? void 0 : options.unobserved)
223
223
  this.N = options == null ? void 0 : options.unobserved;
224
224
  }
225
225
  O() {
226
- if (this.C)
226
+ if (this.D)
227
227
  this.r();
228
228
  if (!this.b || this.b.length)
229
229
  track(this);
@@ -262,30 +262,30 @@ var Computation = class extends Owner {
262
262
  * loading state changes
263
263
  */
264
264
  loading() {
265
- if (this.F === null) {
266
- this.F = loadingState(this);
265
+ if (this.G === null) {
266
+ this.G = loadingState(this);
267
267
  }
268
- return this.F.read();
268
+ return this.G.read();
269
269
  }
270
270
  /**
271
271
  * Return true if the computation is the computation threw an error
272
272
  * Triggers re-execution of the computation when the error state changes
273
273
  */
274
274
  error() {
275
- if (this.E === null) {
276
- this.E = errorState(this);
275
+ if (this.F === null) {
276
+ this.F = errorState(this);
277
277
  }
278
- return this.E.read();
278
+ return this.F.read();
279
279
  }
280
280
  /** Update the computation with a new value. */
281
281
  write(value, flags = 0, raw = false) {
282
282
  const newValue = !raw && typeof value === "function" ? value(this.d) : value;
283
- const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.D === false || !this.D(this.d, newValue));
283
+ const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.E === false || !this.E(this.d, newValue));
284
284
  if (valueChanged)
285
285
  this.d = newValue;
286
286
  const changedFlagsMask = this.i ^ flags, changedFlags = changedFlagsMask & flags;
287
287
  this.i = flags;
288
- this.G = clock + 1;
288
+ this.H = clock + 1;
289
289
  if (this.c) {
290
290
  for (let i = 0; i < this.c.length; i++) {
291
291
  if (valueChanged) {
@@ -425,7 +425,7 @@ function track(computation) {
425
425
  newSources.push(computation);
426
426
  }
427
427
  if (updateCheck) {
428
- updateCheck.d = computation.G > currentObserver.G;
428
+ updateCheck.d = computation.H > currentObserver.H;
429
429
  }
430
430
  }
431
431
  }
@@ -437,7 +437,7 @@ function update(node) {
437
437
  try {
438
438
  node.dispose(false);
439
439
  node.emptyDisposal();
440
- const result = compute(node, node.C, node);
440
+ const result = compute(node, node.D, node);
441
441
  node.write(result, newFlags, true);
442
442
  } catch (error) {
443
443
  if (error instanceof NotReadyError) {
@@ -549,7 +549,7 @@ function schedule() {
549
549
  queueMicrotask(flushSync);
550
550
  }
551
551
  var Queue = class {
552
- H = false;
552
+ I = false;
553
553
  t = [[], [], []];
554
554
  y = [];
555
555
  enqueue(type, node) {
@@ -574,16 +574,16 @@ var Queue = class {
574
574
  }
575
575
  }
576
576
  flush() {
577
- if (this.H)
577
+ if (this.I)
578
578
  return;
579
- this.H = true;
579
+ this.I = true;
580
580
  try {
581
581
  this.run(EFFECT_PURE);
582
582
  incrementClock();
583
583
  this.run(EFFECT_RENDER);
584
584
  this.run(EFFECT_USER);
585
585
  } finally {
586
- this.H = false;
586
+ this.I = false;
587
587
  }
588
588
  }
589
589
  addChild(child) {
@@ -626,50 +626,45 @@ function runPureQueue(queue) {
626
626
  }
627
627
  }
628
628
  function runEffectQueue(queue) {
629
- for (let i = 0; i < queue.length; i++) {
630
- if (queue[i].I && queue[i].a !== STATE_DISPOSED) {
631
- queue[i].J(queue[i].d, queue[i].B);
632
- queue[i].I = false;
633
- queue[i].B = queue[i].d;
634
- }
635
- }
629
+ for (let i = 0; i < queue.length; i++)
630
+ queue[i].R();
636
631
  }
637
632
 
638
633
  // src/core/effect.ts
639
634
  var Effect = class extends Computation {
640
635
  J;
641
- I = false;
636
+ K = false;
642
637
  B;
643
- K;
638
+ C;
644
639
  e;
645
640
  constructor(initialValue, compute2, effect, options) {
646
641
  var _a;
647
642
  super(initialValue, compute2, options);
648
643
  this.J = effect;
649
644
  this.B = initialValue;
650
- this.K = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
645
+ this.C = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
651
646
  this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
652
- this.e.enqueue(this.K, this);
653
647
  this.r();
648
+ this.C === EFFECT_USER ? this.e.enqueue(this.C, this) : this.R();
654
649
  }
655
650
  write(value, flags = 0) {
656
651
  var _a, _b;
657
652
  const currentFlags = this.i;
658
653
  this.i = flags;
659
654
  if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
660
- (_b = (_a = this.e).S) == null ? void 0 : _b.call(_a, this);
655
+ (_b = (_a = this.e).T) == null ? void 0 : _b.call(_a, this);
661
656
  }
662
657
  if (value === UNCHANGED)
663
658
  return this.d;
664
659
  this.d = value;
665
- this.I = true;
660
+ this.K = true;
666
661
  return value;
667
662
  }
668
663
  s(state) {
669
664
  if (this.a >= state)
670
665
  return;
671
666
  if (this.a === STATE_CLEAN)
672
- this.e.enqueue(this.K, this);
667
+ this.e.enqueue(this.C, this);
673
668
  this.a = state;
674
669
  }
675
670
  Q(error) {
@@ -680,6 +675,13 @@ var Effect = class extends Computation {
680
675
  this.B = void 0;
681
676
  super.w();
682
677
  }
678
+ R() {
679
+ if (this.K && this.a !== STATE_DISPOSED) {
680
+ this.J(this.d, this.B);
681
+ this.B = this.d;
682
+ this.K = false;
683
+ }
684
+ }
683
685
  };
684
686
  var EagerComputation = class extends Computation {
685
687
  e;
@@ -708,7 +710,7 @@ var SuspenseQueue = class extends Queue {
708
710
  return;
709
711
  super.run(type);
710
712
  }
711
- S(node) {
713
+ T(node) {
712
714
  if (node.i & LOADING_BIT) {
713
715
  this.k.add(node);
714
716
  if (!this.z) {
@@ -1179,7 +1181,7 @@ function resolveSource(s) {
1179
1181
  }
1180
1182
  var $SOURCES = Symbol(0);
1181
1183
  function merge(...sources) {
1182
- if (sources.length === 1)
1184
+ if (sources.length === 1 && typeof sources[0] !== "function")
1183
1185
  return sources[0];
1184
1186
  let proxy = false;
1185
1187
  const flattened = [];
@@ -1297,9 +1299,9 @@ function mapArray(list, map, options) {
1297
1299
  new Computation(
1298
1300
  [],
1299
1301
  updateKeyedMap.bind({
1300
- R: new Owner(),
1302
+ S: new Owner(),
1301
1303
  u: 0,
1302
- T: list,
1304
+ U: list,
1303
1305
  p: [],
1304
1306
  M: map,
1305
1307
  n: [],
@@ -1313,9 +1315,9 @@ function mapArray(list, map, options) {
1313
1315
  );
1314
1316
  }
1315
1317
  function updateKeyedMap() {
1316
- const newItems = this.T() || [], newLen = newItems.length;
1318
+ const newItems = this.U() || [], newLen = newItems.length;
1317
1319
  newItems[$TRACK];
1318
- runWithOwner(this.R, () => {
1320
+ runWithOwner(this.S, () => {
1319
1321
  let i, j, mapper = this.f ? () => {
1320
1322
  this.f[j] = new Computation(newItems[j], null);
1321
1323
  this.j[j] = new Computation(j, null);
@@ -1333,7 +1335,7 @@ function updateKeyedMap() {
1333
1335
  };
1334
1336
  if (newLen === 0) {
1335
1337
  if (this.u !== 0) {
1336
- this.R.dispose(false);
1338
+ this.S.dispose(false);
1337
1339
  this.k = [];
1338
1340
  this.p = [];
1339
1341
  this.n = [];
package/dist/prod.js CHANGED
@@ -196,32 +196,32 @@ var Computation = class extends Owner {
196
196
  b = null;
197
197
  c = null;
198
198
  d;
199
- C;
199
+ D;
200
200
  // Used in __DEV__ mode, hopefully removed in production
201
- U;
201
+ V;
202
202
  // Using false is an optimization as an alternative to _equals: () => false
203
203
  // which could enable more efficient DIRTY notification
204
- D = isEqual;
204
+ E = isEqual;
205
205
  N;
206
206
  /** Whether the computation is an error or has ancestors that are unresolved */
207
207
  i = 0;
208
208
  /** Which flags raised by sources are handled, vs. being passed through. */
209
209
  A = DEFAULT_FLAGS;
210
- E = null;
211
210
  F = null;
212
- G = -1;
211
+ G = null;
212
+ H = -1;
213
213
  constructor(initialValue, compute2, options) {
214
214
  super(compute2 === null);
215
- this.C = compute2;
215
+ this.D = compute2;
216
216
  this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
217
217
  this.d = initialValue;
218
218
  if (options?.equals !== void 0)
219
- this.D = options.equals;
219
+ this.E = options.equals;
220
220
  if (options?.unobserved)
221
221
  this.N = options?.unobserved;
222
222
  }
223
223
  O() {
224
- if (this.C)
224
+ if (this.D)
225
225
  this.r();
226
226
  if (!this.b || this.b.length)
227
227
  track(this);
@@ -260,30 +260,30 @@ var Computation = class extends Owner {
260
260
  * loading state changes
261
261
  */
262
262
  loading() {
263
- if (this.F === null) {
264
- this.F = loadingState(this);
263
+ if (this.G === null) {
264
+ this.G = loadingState(this);
265
265
  }
266
- return this.F.read();
266
+ return this.G.read();
267
267
  }
268
268
  /**
269
269
  * Return true if the computation is the computation threw an error
270
270
  * Triggers re-execution of the computation when the error state changes
271
271
  */
272
272
  error() {
273
- if (this.E === null) {
274
- this.E = errorState(this);
273
+ if (this.F === null) {
274
+ this.F = errorState(this);
275
275
  }
276
- return this.E.read();
276
+ return this.F.read();
277
277
  }
278
278
  /** Update the computation with a new value. */
279
279
  write(value, flags = 0, raw = false) {
280
280
  const newValue = !raw && typeof value === "function" ? value(this.d) : value;
281
- const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.D === false || !this.D(this.d, newValue));
281
+ const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.E === false || !this.E(this.d, newValue));
282
282
  if (valueChanged)
283
283
  this.d = newValue;
284
284
  const changedFlagsMask = this.i ^ flags, changedFlags = changedFlagsMask & flags;
285
285
  this.i = flags;
286
- this.G = clock + 1;
286
+ this.H = clock + 1;
287
287
  if (this.c) {
288
288
  for (let i = 0; i < this.c.length; i++) {
289
289
  if (valueChanged) {
@@ -423,7 +423,7 @@ function track(computation) {
423
423
  newSources.push(computation);
424
424
  }
425
425
  if (updateCheck) {
426
- updateCheck.d = computation.G > currentObserver.G;
426
+ updateCheck.d = computation.H > currentObserver.H;
427
427
  }
428
428
  }
429
429
  }
@@ -435,7 +435,7 @@ function update(node) {
435
435
  try {
436
436
  node.dispose(false);
437
437
  node.emptyDisposal();
438
- const result = compute(node, node.C, node);
438
+ const result = compute(node, node.D, node);
439
439
  node.write(result, newFlags, true);
440
440
  } catch (error) {
441
441
  if (error instanceof NotReadyError) {
@@ -546,7 +546,7 @@ function schedule() {
546
546
  queueMicrotask(flushSync);
547
547
  }
548
548
  var Queue = class {
549
- H = false;
549
+ I = false;
550
550
  t = [[], [], []];
551
551
  y = [];
552
552
  enqueue(type, node) {
@@ -571,16 +571,16 @@ var Queue = class {
571
571
  }
572
572
  }
573
573
  flush() {
574
- if (this.H)
574
+ if (this.I)
575
575
  return;
576
- this.H = true;
576
+ this.I = true;
577
577
  try {
578
578
  this.run(EFFECT_PURE);
579
579
  incrementClock();
580
580
  this.run(EFFECT_RENDER);
581
581
  this.run(EFFECT_USER);
582
582
  } finally {
583
- this.H = false;
583
+ this.I = false;
584
584
  }
585
585
  }
586
586
  addChild(child) {
@@ -623,48 +623,43 @@ function runPureQueue(queue) {
623
623
  }
624
624
  }
625
625
  function runEffectQueue(queue) {
626
- for (let i = 0; i < queue.length; i++) {
627
- if (queue[i].I && queue[i].a !== STATE_DISPOSED) {
628
- queue[i].J(queue[i].d, queue[i].B);
629
- queue[i].I = false;
630
- queue[i].B = queue[i].d;
631
- }
632
- }
626
+ for (let i = 0; i < queue.length; i++)
627
+ queue[i].R();
633
628
  }
634
629
 
635
630
  // src/core/effect.ts
636
631
  var Effect = class extends Computation {
637
632
  J;
638
- I = false;
633
+ K = false;
639
634
  B;
640
- K;
635
+ C;
641
636
  e;
642
637
  constructor(initialValue, compute2, effect, options) {
643
638
  super(initialValue, compute2, options);
644
639
  this.J = effect;
645
640
  this.B = initialValue;
646
- this.K = options?.render ? EFFECT_RENDER : EFFECT_USER;
641
+ this.C = options?.render ? EFFECT_RENDER : EFFECT_USER;
647
642
  this.e = getOwner()?.e || globalQueue;
648
- this.e.enqueue(this.K, this);
649
643
  this.r();
644
+ this.C === EFFECT_USER ? this.e.enqueue(this.C, this) : this.R();
650
645
  }
651
646
  write(value, flags = 0) {
652
647
  const currentFlags = this.i;
653
648
  this.i = flags;
654
649
  if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
655
- this.e.S?.(this);
650
+ this.e.T?.(this);
656
651
  }
657
652
  if (value === UNCHANGED)
658
653
  return this.d;
659
654
  this.d = value;
660
- this.I = true;
655
+ this.K = true;
661
656
  return value;
662
657
  }
663
658
  s(state) {
664
659
  if (this.a >= state)
665
660
  return;
666
661
  if (this.a === STATE_CLEAN)
667
- this.e.enqueue(this.K, this);
662
+ this.e.enqueue(this.C, this);
668
663
  this.a = state;
669
664
  }
670
665
  Q(error) {
@@ -675,6 +670,13 @@ var Effect = class extends Computation {
675
670
  this.B = void 0;
676
671
  super.w();
677
672
  }
673
+ R() {
674
+ if (this.K && this.a !== STATE_DISPOSED) {
675
+ this.J(this.d, this.B);
676
+ this.B = this.d;
677
+ this.K = false;
678
+ }
679
+ }
678
680
  };
679
681
  var EagerComputation = class extends Computation {
680
682
  e;
@@ -702,7 +704,7 @@ var SuspenseQueue = class extends Queue {
702
704
  return;
703
705
  super.run(type);
704
706
  }
705
- S(node) {
707
+ T(node) {
706
708
  if (node.i & LOADING_BIT) {
707
709
  this.k.add(node);
708
710
  if (!this.z) {
@@ -1170,7 +1172,7 @@ function resolveSource(s) {
1170
1172
  }
1171
1173
  var $SOURCES = Symbol(0);
1172
1174
  function merge(...sources) {
1173
- if (sources.length === 1)
1175
+ if (sources.length === 1 && typeof sources[0] !== "function")
1174
1176
  return sources[0];
1175
1177
  let proxy = false;
1176
1178
  const flattened = [];
@@ -1288,9 +1290,9 @@ function mapArray(list, map, options) {
1288
1290
  new Computation(
1289
1291
  [],
1290
1292
  updateKeyedMap.bind({
1291
- R: new Owner(),
1293
+ S: new Owner(),
1292
1294
  u: 0,
1293
- T: list,
1295
+ U: list,
1294
1296
  p: [],
1295
1297
  M: map,
1296
1298
  n: [],
@@ -1304,9 +1306,9 @@ function mapArray(list, map, options) {
1304
1306
  );
1305
1307
  }
1306
1308
  function updateKeyedMap() {
1307
- const newItems = this.T() || [], newLen = newItems.length;
1309
+ const newItems = this.U() || [], newLen = newItems.length;
1308
1310
  newItems[$TRACK];
1309
- runWithOwner(this.R, () => {
1311
+ runWithOwner(this.S, () => {
1310
1312
  let i, j, mapper = this.f ? () => {
1311
1313
  this.f[j] = new Computation(newItems[j], null);
1312
1314
  this.j[j] = new Computation(j, null);
@@ -1324,7 +1326,7 @@ function updateKeyedMap() {
1324
1326
  };
1325
1327
  if (newLen === 0) {
1326
1328
  if (this.u !== 0) {
1327
- this.R.dispose(false);
1329
+ this.S.dispose(false);
1328
1330
  this.k = [];
1329
1331
  this.p = [];
1330
1332
  this.n = [];
@@ -19,6 +19,7 @@ export declare class Effect<T = any> extends Computation<T> {
19
19
  _notify(state: number): void;
20
20
  _setError(error: unknown): void;
21
21
  _disposeNode(): void;
22
+ _runEffect(): void;
22
23
  }
23
24
  export declare class EagerComputation<T = any> extends Computation<T> {
24
25
  _queue: IQueue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "type": "module",