@solid-primitives/utils 5.2.0 → 5.3.0

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/index.cjs CHANGED
@@ -17,9 +17,15 @@ exports.compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
17
17
  exports.arrayEquals = (a, b) => a === b || a.length === b.length && a.every((e, i) => e === b[i]);
18
18
  function chain(callbacks) {
19
19
  return (...args) => {
20
- for (const callback of callbacks) {
21
- if (typeof callback === "function")
22
- callback(...args);
20
+ for (const callback of callbacks)
21
+ callback && callback(...args);
22
+ };
23
+ }
24
+ function reverseChain(callbacks) {
25
+ return (...args) => {
26
+ for (let i = callbacks.length - 1; i >= 0; i--) {
27
+ const callback = callbacks[i];
28
+ callback && callback(...args);
23
29
  }
24
30
  };
25
31
  }
@@ -29,7 +35,7 @@ exports.asArray = (value) => Array.isArray(value) ? value : [value];
29
35
  exports.accessArray = (list) => list.map((v) => exports.access(v));
30
36
  exports.withAccess = (value, fn) => {
31
37
  const _value = exports.access(value);
32
- typeof _value !== "undefined" && _value !== null && fn(_value);
38
+ typeof _value != null && fn(_value);
33
39
  };
34
40
  exports.asAccessor = (v) => typeof v === "function" ? v : () => v;
35
41
  function accessWith(valueOrFn, ...args) {
@@ -157,9 +163,8 @@ function createHydrateSignal(serverValue, update, options) {
157
163
  if (exports.isServer) {
158
164
  return solidJs.createSignal(serverValue);
159
165
  }
160
- let init = !!solidJs.sharedConfig.context;
161
- const [state, setState] = solidJs.createSignal(init ? serverValue : update(), options);
162
- init && solidJs.onMount(() => setState(() => update()));
166
+ const [state, setState] = solidJs.createSignal(solidJs.sharedConfig.context ? serverValue : update(), options);
167
+ solidJs.sharedConfig.context && solidJs.onMount(() => setState(() => update()));
163
168
  return [state, setState];
164
169
  }
165
170
 
@@ -171,3 +176,4 @@ exports.createStaticStore = createStaticStore;
171
176
  exports.defer = defer;
172
177
  exports.handleDiffArray = handleDiffArray;
173
178
  exports.isObject = isObject;
179
+ exports.reverseChain = reverseChain;
package/dist/index.d.ts CHANGED
@@ -108,6 +108,10 @@ declare const arrayEquals: (a: readonly unknown[], b: readonly unknown[]) => boo
108
108
  declare function chain<Args extends [] | any[]>(callbacks: {
109
109
  [Symbol.iterator](): IterableIterator<((...args: Args) => any) | undefined>;
110
110
  }): (...args: Args) => void;
111
+ /**
112
+ * Returns a function that will call all functions in the reversed order with the same arguments.
113
+ */
114
+ declare function reverseChain<Args extends [] | any[]>(callbacks: (((...args: Args) => any) | undefined)[]): (...args: Args) => void;
111
115
  declare const clamp: (n: number, min: number, max: number) => number;
112
116
  /**
113
117
  * Accesses the value of a MaybeAccessor
@@ -193,7 +197,7 @@ declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], h
193
197
  /**
194
198
  * A signal object that handle hydration.
195
199
  * @param serverValue initial value of the state on the server
196
- * @param update called once on the client or on hydration to initialise the value
200
+ * @param update called once on the client or on hydration to initialize the value
197
201
  * @param options {@link SignalOptions}
198
202
  * @returns
199
203
  * ```ts
@@ -203,4 +207,4 @@ declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], h
203
207
  */
204
208
  declare function createHydrateSignal<T>(serverValue: T, update: () => T, options?: SignalOptions<T>): Signal<T>;
205
209
 
206
- export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Narrow, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterParam, Simplify, StaticStoreSetter, Tail, Truthy, UnboxLazy, UnionToIntersection, Values, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createHydrateSignal, createMicrotask, createStaticStore, defer, entries, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, tryOnCleanup, withAccess };
210
+ export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Narrow, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterParam, Simplify, StaticStoreSetter, Tail, Truthy, UnboxLazy, UnionToIntersection, Values, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createHydrateSignal, createMicrotask, createStaticStore, defer, entries, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, reverseChain, tryOnCleanup, withAccess };
package/dist/index.js CHANGED
@@ -15,9 +15,15 @@ var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
15
15
  var arrayEquals = (a, b) => a === b || a.length === b.length && a.every((e, i) => e === b[i]);
16
16
  function chain(callbacks) {
17
17
  return (...args) => {
18
- for (const callback of callbacks) {
19
- if (typeof callback === "function")
20
- callback(...args);
18
+ for (const callback of callbacks)
19
+ callback && callback(...args);
20
+ };
21
+ }
22
+ function reverseChain(callbacks) {
23
+ return (...args) => {
24
+ for (let i = callbacks.length - 1; i >= 0; i--) {
25
+ const callback = callbacks[i];
26
+ callback && callback(...args);
21
27
  }
22
28
  };
23
29
  }
@@ -27,7 +33,7 @@ var asArray = (value) => Array.isArray(value) ? value : [value];
27
33
  var accessArray = (list) => list.map((v) => access(v));
28
34
  var withAccess = (value, fn) => {
29
35
  const _value = access(value);
30
- typeof _value !== "undefined" && _value !== null && fn(_value);
36
+ typeof _value != null && fn(_value);
31
37
  };
32
38
  var asAccessor = (v) => typeof v === "function" ? v : () => v;
33
39
  function accessWith(valueOrFn, ...args) {
@@ -155,10 +161,9 @@ function createHydrateSignal(serverValue, update, options) {
155
161
  if (isServer) {
156
162
  return createSignal(serverValue);
157
163
  }
158
- let init = !!sharedConfig.context;
159
- const [state, setState] = createSignal(init ? serverValue : update(), options);
160
- init && onMount(() => setState(() => update()));
164
+ const [state, setState] = createSignal(sharedConfig.context ? serverValue : update(), options);
165
+ sharedConfig.context && onMount(() => setState(() => update()));
161
166
  return [state, setState];
162
167
  }
163
168
 
164
- export { access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createHydrateSignal, createMicrotask, createStaticStore, defer, entries, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, tryOnCleanup, withAccess };
169
+ export { access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createHydrateSignal, createMicrotask, createStaticStore, defer, entries, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, reverseChain, tryOnCleanup, withAccess };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
5
5
  "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
6
6
  "contributors": [