@solid-primitives/utils 5.1.0 → 5.2.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
@@ -153,9 +153,19 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
153
153
  handleAdded(currEl);
154
154
  }
155
155
  }
156
+ function createHydrateSignal(serverValue, update, options) {
157
+ if (exports.isServer) {
158
+ return solidJs.createSignal(serverValue);
159
+ }
160
+ let init = !!solidJs.sharedConfig.context;
161
+ const [state, setState] = solidJs.createSignal(init ? serverValue : update(), options);
162
+ init && solidJs.onMount(() => setState(() => update()));
163
+ return [state, setState];
164
+ }
156
165
 
157
166
  exports.accessWith = accessWith;
158
167
  exports.chain = chain;
168
+ exports.createHydrateSignal = createHydrateSignal;
159
169
  exports.createMicrotask = createMicrotask;
160
170
  exports.createStaticStore = createStaticStore;
161
171
  exports.defer = defer;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Accessor, Setter, AccessorArray, NoInfer, EffectFunction, onCleanup } from 'solid-js';
2
- export { EffectOptions, MemoOptions, OnOptions, SignalOptions } from 'solid-js/types/reactive/signal';
1
+ import { Accessor, Setter, AccessorArray, NoInfer, EffectFunction, onCleanup, SignalOptions, Signal } from 'solid-js';
2
+ export { EffectOptions, OnOptions } from 'solid-js/types/reactive/signal';
3
3
 
4
4
  /**
5
5
  * Can be single or in an array
@@ -78,9 +78,10 @@ type Position = {
78
78
  x: number;
79
79
  y: number;
80
80
  };
81
- type Narrow<T> = (T extends [] ? [] : never) | (T extends string | number | bigint | boolean ? T : never) | {
82
- [K in keyof T]: T[K] extends Function ? T[K] : Narrow<T[K]>;
81
+ type RawNarrow<T> = (T extends [] ? [] : never) | (T extends string | number | bigint | boolean ? T : never) | {
82
+ [K in keyof T]: T[K] extends Function ? T[K] : RawNarrow<T[K]>;
83
83
  };
84
+ type Narrow<T extends any> = T extends [] ? T : RawNarrow<T>;
84
85
 
85
86
  /** no operation */
86
87
  declare const noop: Noop;
@@ -189,5 +190,17 @@ declare function createStaticStore<T extends Readonly<AnyStatic>>(init: T): [acc
189
190
  * @param handleRemoved called once for every removed from array
190
191
  */
191
192
  declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
193
+ /**
194
+ * A signal object that handle hydration.
195
+ * @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
197
+ * @param options {@link SignalOptions}
198
+ * @returns
199
+ * ```ts
200
+ * [state: Accessor<T>, setState: Setter<T>]
201
+ * ```
202
+ * @see {@link createSignal}
203
+ */
204
+ declare function createHydrateSignal<T>(serverValue: T, update: () => T, options?: SignalOptions<T>): Signal<T>;
192
205
 
193
- 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, createMicrotask, createStaticStore, defer, entries, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, tryOnCleanup, withAccess };
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 };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DEV, untrack, getOwner, onCleanup, createSignal, batch } from 'solid-js';
1
+ import { DEV, untrack, getOwner, onCleanup, createSignal, sharedConfig, onMount, batch } from 'solid-js';
2
2
  import { isServer as isServer$1 } from 'solid-js/web';
3
3
 
4
4
  // src/index.ts
@@ -151,5 +151,14 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
151
151
  handleAdded(currEl);
152
152
  }
153
153
  }
154
+ function createHydrateSignal(serverValue, update, options) {
155
+ if (isServer) {
156
+ return createSignal(serverValue);
157
+ }
158
+ let init = !!sharedConfig.context;
159
+ const [state, setState] = createSignal(init ? serverValue : update(), options);
160
+ init && onMount(() => setState(() => update()));
161
+ return [state, setState];
162
+ }
154
163
 
155
- export { access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createStaticStore, defer, entries, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, tryOnCleanup, withAccess };
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 };
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "5.1.0",
3
+ "version": "5.2.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
+ "contributors": [
7
+ "Tom Pichaud <dev.tompichaud@icloud.com>"
8
+ ],
6
9
  "license": "MIT",
7
10
  "homepage": "https://github.com/solidjs-community/solid-primitives/tree/main/packages/utils#readme",
8
11
  "repository": {