@solidjs/signals 0.2.1 → 0.2.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
@@ -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;
@@ -666,8 +612,10 @@ function isPending(fn, loadingValue) {
666
612
  latest(fn);
667
613
  return staleCheck._value;
668
614
  } catch (err) {
669
- if (argLength > 1 && err instanceof NotReadyError)
670
- return !!loadingValue;
615
+ if (!(err instanceof NotReadyError))
616
+ return false;
617
+ if (argLength > 1)
618
+ return loadingValue;
671
619
  throw err;
672
620
  } finally {
673
621
  staleCheck = current;
@@ -752,6 +700,68 @@ function compute(owner, fn, observer) {
752
700
  notStale = prevNotStale;
753
701
  }
754
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
+ }
755
765
  function createBoundary(fn, queue) {
756
766
  const owner = new Owner();
757
767
  const parentQueue = owner._queue;
@@ -775,7 +785,7 @@ var Effect = class extends Computation {
775
785
  this._prevValue = initialValue;
776
786
  this._type = options?.render ? EFFECT_RENDER : EFFECT_USER;
777
787
  if (this._type === EFFECT_RENDER) {
778
- 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);
779
789
  }
780
790
  this._updateIfNecessary();
781
791
  !options?.defer && (this._type === EFFECT_USER ? this._queue.enqueue(this._type, this) : this._runEffect());
@@ -806,9 +816,9 @@ var Effect = class extends Computation {
806
816
  _setError(error) {
807
817
  this._cleanup?.();
808
818
  if (this._stateFlags & LOADING_BIT) {
809
- this._stateFlags = 0;
810
819
  this._queue._update?.(this);
811
820
  }
821
+ this._stateFlags = ERROR_BIT;
812
822
  if (this._type === EFFECT_USER) {
813
823
  try {
814
824
  return this._onerror ? this._cleanup = this._onerror(error) : console.error(new EffectError(this._effect, error));
@@ -1437,7 +1447,7 @@ function reconcile(value, key) {
1437
1447
  };
1438
1448
  }
1439
1449
 
1440
- // src/store/utilities.ts
1450
+ // src/store/utils.ts
1441
1451
  function trueFn() {
1442
1452
  return true;
1443
1453
  }
package/dist/node.cjs CHANGED
@@ -134,60 +134,6 @@ function runEffectQueue(queue) {
134
134
  function isUndefined(value) {
135
135
  return typeof value === "undefined";
136
136
  }
137
- function flatten(children, options) {
138
- if (typeof children === "function" && !children.length) {
139
- if (options == null ? void 0 : options.doNotUnwrap)
140
- return children;
141
- do {
142
- children = children();
143
- } while (typeof children === "function" && !children.length);
144
- }
145
- if ((options == null ? void 0 : options.skipNonRendered) && (children == null || children === true || children === false || children === ""))
146
- return;
147
- if (Array.isArray(children)) {
148
- let results = [];
149
- if (flattenArray(children, results, options)) {
150
- return () => {
151
- let nested = [];
152
- flattenArray(results, nested, { ...options, doNotUnwrap: false });
153
- return nested;
154
- };
155
- }
156
- return results;
157
- }
158
- return children;
159
- }
160
- function flattenArray(children, results = [], options) {
161
- let notReady = null;
162
- let needsUnwrap = false;
163
- for (let i = 0; i < children.length; i++) {
164
- try {
165
- let child = children[i];
166
- if (typeof child === "function" && !child.length) {
167
- if (options == null ? void 0 : options.doNotUnwrap) {
168
- results.push(child);
169
- needsUnwrap = true;
170
- continue;
171
- }
172
- do {
173
- child = child();
174
- } while (typeof child === "function" && !child.length);
175
- }
176
- if (Array.isArray(child)) {
177
- needsUnwrap = flattenArray(child, results, options);
178
- } else if ((options == null ? void 0 : options.skipNonRendered) && (child == null || child === true || child === false || child === "")) {
179
- } else
180
- results.push(child);
181
- } catch (e) {
182
- if (!(e instanceof NotReadyError))
183
- throw e;
184
- notReady = e;
185
- }
186
- }
187
- if (notReady)
188
- throw notReady;
189
- return needsUnwrap;
190
- }
191
137
 
192
138
  // src/core/owner.ts
193
139
  var currentOwner = null;
@@ -663,8 +609,10 @@ function isPending(fn, loadingValue) {
663
609
  latest(fn);
664
610
  return staleCheck.e;
665
611
  } catch (err) {
666
- if (argLength > 1 && err instanceof NotReadyError)
667
- return !!loadingValue;
612
+ if (!(err instanceof NotReadyError))
613
+ return false;
614
+ if (argLength > 1)
615
+ return loadingValue;
668
616
  throw err;
669
617
  } finally {
670
618
  staleCheck = current;
@@ -749,6 +697,68 @@ function compute(owner, fn, observer) {
749
697
  notStale = prevNotStale;
750
698
  }
751
699
  }
700
+ function flatten(children, options) {
701
+ try {
702
+ if (typeof children === "function" && !children.length) {
703
+ if (options == null ? void 0 : options.doNotUnwrap)
704
+ return children;
705
+ do {
706
+ children = children();
707
+ } while (typeof children === "function" && !children.length);
708
+ }
709
+ if ((options == null ? void 0 : options.skipNonRendered) && (children == null || children === true || children === false || children === ""))
710
+ return;
711
+ if (Array.isArray(children)) {
712
+ let results = [];
713
+ if (flattenArray(children, results, options)) {
714
+ return () => {
715
+ let nested = [];
716
+ flattenArray(results, nested, { ...options, doNotUnwrap: false });
717
+ return nested;
718
+ };
719
+ }
720
+ return results;
721
+ }
722
+ return children;
723
+ } catch (e) {
724
+ if ((options == null ? void 0 : options.skipNonRendered) && e instanceof NotReadyError) {
725
+ newFlags |= LOADING_BIT;
726
+ return void 0;
727
+ }
728
+ throw e;
729
+ }
730
+ }
731
+ function flattenArray(children, results = [], options) {
732
+ let notReady = null;
733
+ let needsUnwrap = false;
734
+ for (let i = 0; i < children.length; i++) {
735
+ try {
736
+ let child = children[i];
737
+ if (typeof child === "function" && !child.length) {
738
+ if (options == null ? void 0 : options.doNotUnwrap) {
739
+ results.push(child);
740
+ needsUnwrap = true;
741
+ continue;
742
+ }
743
+ do {
744
+ child = child();
745
+ } while (typeof child === "function" && !child.length);
746
+ }
747
+ if (Array.isArray(child)) {
748
+ needsUnwrap = flattenArray(child, results, options);
749
+ } else if ((options == null ? void 0 : options.skipNonRendered) && (child == null || child === true || child === false || child === "")) {
750
+ } else
751
+ results.push(child);
752
+ } catch (e) {
753
+ if (!(e instanceof NotReadyError))
754
+ throw e;
755
+ notReady = e;
756
+ }
757
+ }
758
+ if (notReady)
759
+ throw notReady;
760
+ return needsUnwrap;
761
+ }
752
762
  function createBoundary(fn, queue) {
753
763
  const owner = new Owner();
754
764
  const parentQueue = owner.h;
@@ -772,7 +782,7 @@ var Effect = class extends Computation {
772
782
  this.M = initialValue;
773
783
  this.u = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
774
784
  if (this.u === EFFECT_RENDER) {
775
- this.A = (p) => getClock() > this.h.created ? latest(() => compute2(p)) : compute2(p);
785
+ this.A = (p) => getClock() > this.h.created && !(this.d & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
776
786
  }
777
787
  this.y();
778
788
  !(options == null ? void 0 : options.defer) && (this.u === EFFECT_USER ? this.h.enqueue(this.u, this) : this.T());
@@ -803,9 +813,9 @@ var Effect = class extends Computation {
803
813
  var _a, _b, _c;
804
814
  (_a = this.B) == null ? void 0 : _a.call(this);
805
815
  if (this.d & LOADING_BIT) {
806
- this.d = 0;
807
816
  (_c = (_b = this.h).R) == null ? void 0 : _c.call(_b, this);
808
817
  }
818
+ this.d = ERROR_BIT;
809
819
  if (this.u === EFFECT_USER) {
810
820
  try {
811
821
  return this.L ? this.B = this.L(error) : console.error(new EffectError(this.K, error));
@@ -1437,7 +1447,7 @@ function reconcile(value, key) {
1437
1447
  };
1438
1448
  }
1439
1449
 
1440
- // src/store/utilities.ts
1450
+ // src/store/utils.ts
1441
1451
  function trueFn() {
1442
1452
  return true;
1443
1453
  }
package/dist/prod.js CHANGED
@@ -132,60 +132,6 @@ function runEffectQueue(queue) {
132
132
  function isUndefined(value) {
133
133
  return typeof value === "undefined";
134
134
  }
135
- function flatten(children, options) {
136
- if (typeof children === "function" && !children.length) {
137
- if (options?.doNotUnwrap)
138
- return children;
139
- do {
140
- children = children();
141
- } while (typeof children === "function" && !children.length);
142
- }
143
- if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
144
- return;
145
- if (Array.isArray(children)) {
146
- let results = [];
147
- if (flattenArray(children, results, options)) {
148
- return () => {
149
- let nested = [];
150
- flattenArray(results, nested, { ...options, doNotUnwrap: false });
151
- return nested;
152
- };
153
- }
154
- return results;
155
- }
156
- return children;
157
- }
158
- function flattenArray(children, results = [], options) {
159
- let notReady = null;
160
- let needsUnwrap = false;
161
- for (let i = 0; i < children.length; i++) {
162
- try {
163
- let child = children[i];
164
- if (typeof child === "function" && !child.length) {
165
- if (options?.doNotUnwrap) {
166
- results.push(child);
167
- needsUnwrap = true;
168
- continue;
169
- }
170
- do {
171
- child = child();
172
- } while (typeof child === "function" && !child.length);
173
- }
174
- if (Array.isArray(child)) {
175
- needsUnwrap = flattenArray(child, results, options);
176
- } else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
177
- } else
178
- results.push(child);
179
- } catch (e) {
180
- if (!(e instanceof NotReadyError))
181
- throw e;
182
- notReady = e;
183
- }
184
- }
185
- if (notReady)
186
- throw notReady;
187
- return needsUnwrap;
188
- }
189
135
 
190
136
  // src/core/owner.ts
191
137
  var currentOwner = null;
@@ -659,8 +605,10 @@ function isPending(fn, loadingValue) {
659
605
  latest(fn);
660
606
  return staleCheck.e;
661
607
  } catch (err) {
662
- if (argLength > 1 && err instanceof NotReadyError)
663
- return !!loadingValue;
608
+ if (!(err instanceof NotReadyError))
609
+ return false;
610
+ if (argLength > 1)
611
+ return loadingValue;
664
612
  throw err;
665
613
  } finally {
666
614
  staleCheck = current;
@@ -745,6 +693,68 @@ function compute(owner, fn, observer) {
745
693
  notStale = prevNotStale;
746
694
  }
747
695
  }
696
+ function flatten(children, options) {
697
+ try {
698
+ if (typeof children === "function" && !children.length) {
699
+ if (options?.doNotUnwrap)
700
+ return children;
701
+ do {
702
+ children = children();
703
+ } while (typeof children === "function" && !children.length);
704
+ }
705
+ if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
706
+ return;
707
+ if (Array.isArray(children)) {
708
+ let results = [];
709
+ if (flattenArray(children, results, options)) {
710
+ return () => {
711
+ let nested = [];
712
+ flattenArray(results, nested, { ...options, doNotUnwrap: false });
713
+ return nested;
714
+ };
715
+ }
716
+ return results;
717
+ }
718
+ return children;
719
+ } catch (e) {
720
+ if (options?.skipNonRendered && e instanceof NotReadyError) {
721
+ newFlags |= LOADING_BIT;
722
+ return void 0;
723
+ }
724
+ throw e;
725
+ }
726
+ }
727
+ function flattenArray(children, results = [], options) {
728
+ let notReady = null;
729
+ let needsUnwrap = false;
730
+ for (let i = 0; i < children.length; i++) {
731
+ try {
732
+ let child = children[i];
733
+ if (typeof child === "function" && !child.length) {
734
+ if (options?.doNotUnwrap) {
735
+ results.push(child);
736
+ needsUnwrap = true;
737
+ continue;
738
+ }
739
+ do {
740
+ child = child();
741
+ } while (typeof child === "function" && !child.length);
742
+ }
743
+ if (Array.isArray(child)) {
744
+ needsUnwrap = flattenArray(child, results, options);
745
+ } else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
746
+ } else
747
+ results.push(child);
748
+ } catch (e) {
749
+ if (!(e instanceof NotReadyError))
750
+ throw e;
751
+ notReady = e;
752
+ }
753
+ }
754
+ if (notReady)
755
+ throw notReady;
756
+ return needsUnwrap;
757
+ }
748
758
  function createBoundary(fn, queue) {
749
759
  const owner = new Owner();
750
760
  const parentQueue = owner.h;
@@ -768,7 +778,7 @@ var Effect = class extends Computation {
768
778
  this.M = initialValue;
769
779
  this.u = options?.render ? EFFECT_RENDER : EFFECT_USER;
770
780
  if (this.u === EFFECT_RENDER) {
771
- this.A = (p) => getClock() > this.h.created ? latest(() => compute2(p)) : compute2(p);
781
+ this.A = (p) => getClock() > this.h.created && !(this.d & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
772
782
  }
773
783
  this.y();
774
784
  !options?.defer && (this.u === EFFECT_USER ? this.h.enqueue(this.u, this) : this.T());
@@ -797,9 +807,9 @@ var Effect = class extends Computation {
797
807
  F(error) {
798
808
  this.B?.();
799
809
  if (this.d & LOADING_BIT) {
800
- this.d = 0;
801
810
  this.h.R?.(this);
802
811
  }
812
+ this.d = ERROR_BIT;
803
813
  if (this.u === EFFECT_USER) {
804
814
  try {
805
815
  return this.L ? this.B = this.L(error) : console.error(new EffectError(this.K, error));
@@ -1424,7 +1434,7 @@ function reconcile(value, key) {
1424
1434
  };
1425
1435
  }
1426
1436
 
1427
- // src/store/utilities.ts
1437
+ // src/store/utils.ts
1428
1438
  function trueFn() {
1429
1439
  return true;
1430
1440
  }
@@ -162,5 +162,9 @@ export declare function runWithObserver<T>(observer: Computation, run: () => T):
162
162
  */
163
163
  export declare function compute<T>(owner: Owner | null, fn: (val: T) => T, observer: Computation<T>): T;
164
164
  export declare function compute<T>(owner: Owner | null, fn: (val: undefined) => T, observer: null): T;
165
+ export declare function flatten(children: any, options?: {
166
+ skipNonRendered?: boolean;
167
+ doNotUnwrap?: boolean;
168
+ }): any;
165
169
  export declare function createBoundary<T>(fn: () => T, queue: IQueue): T;
166
170
  export {};
@@ -1,9 +1,8 @@
1
1
  export { ContextNotFoundError, NoOwnerError, NotReadyError, type ErrorHandler } from "./error.js";
2
2
  export { Owner, createContext, getContext, setContext, hasContext, getOwner, onCleanup, type Context, type ContextRecord, type Disposable } from "./owner.js";
3
- export { Computation, createBoundary, getObserver, isEqual, untrack, hasUpdated, isPending, latest, catchError, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
3
+ export { Computation, createBoundary, getObserver, isEqual, untrack, hasUpdated, isPending, latest, flatten, catchError, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
4
4
  export { Effect, EagerComputation } from "./effect.js";
5
5
  export { flushSync, getClock, incrementClock, type IQueue, Queue } from "./scheduler.js";
6
6
  export { createSuspense } from "./suspense.js";
7
7
  export { SUPPORTS_PROXY } from "./constants.js";
8
8
  export * from "./flags.js";
9
- export { flatten } from "./utils.js";
@@ -1,5 +1 @@
1
1
  export declare function isUndefined(value: any): value is undefined;
2
- export declare function flatten(children: any, options?: {
3
- skipNonRendered?: boolean;
4
- doNotUnwrap?: boolean;
5
- }): any;
@@ -1,6 +1,6 @@
1
1
  export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
2
- export type { Merge, Omit } from "./utilities.js";
2
+ export type { Merge, Omit } from "./utils.js";
3
3
  export { unwrap, isWrappable, createStore, $RAW, $TRACK, $PROXY, $TARGET } from "./store.js";
4
4
  export { createProjection } from "./projection.js";
5
5
  export { reconcile } from "./reconcile.js";
6
- export { merge, omit } from "./utilities.js";
6
+ export { merge, omit } from "./utils.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
File without changes