@solid-primitives/utils
Advanced tools
Comparing version 5.4.0 to 5.5.0
@@ -1,2 +0,3 @@ | ||
import { Accessor, Setter, AccessorArray, NoInfer, EffectFunction, onCleanup, SignalOptions, Signal } from 'solid-js'; | ||
import { Accessor, Setter, AccessorArray, NoInfer, EffectFunction, onCleanup, SignalOptions, createSignal } from 'solid-js'; | ||
export { isServer } from 'solid-js/web'; | ||
export { EffectOptions, OnOptions, ResolvedChildren, ResolvedJSXElement } from 'solid-js/types/reactive/signal'; | ||
@@ -88,8 +89,10 @@ | ||
declare const noop: Noop; | ||
declare const isServer: boolean; | ||
declare const isClient = true; | ||
declare const trueFn: () => boolean; | ||
declare const falseFn: () => boolean; | ||
declare const isClient: boolean; | ||
/** development environment */ | ||
declare const isDev = true; | ||
declare const isDev: boolean; | ||
/** production environment */ | ||
declare const isProd = false; | ||
declare const isProd: boolean; | ||
/** | ||
@@ -175,2 +178,17 @@ * Check if the value is an instance of ___ | ||
declare function createMicrotask<A extends any[] | []>(fn: (...a: A) => void): (...a: A) => void; | ||
/** | ||
* A hydratable version of the {@link createSignal}. It will use the serverValue on the server and the update function on the client. If initialized during hydration it will use serverValue as the initial value and update it once hydration is complete. | ||
* | ||
* @param serverValue initial value of the state on the server | ||
* @param update called once on the client or on hydration to initialize the value | ||
* @param options {@link SignalOptions} | ||
* @returns | ||
* ```ts | ||
* [state: Accessor<T>, setState: Setter<T>] | ||
* ``` | ||
* @see {@link createSignal} | ||
*/ | ||
declare function createHydratableSignal<T>(serverValue: T, update: () => T, options?: SignalOptions<T>): ReturnType<typeof createSignal<T>>; | ||
/** @deprecated use {@link createHydratableSignal} instead */ | ||
declare const createHydrateSignal: typeof createHydratableSignal; | ||
type StaticStoreSetter<T extends Readonly<AnyStatic>> = { | ||
@@ -191,2 +209,13 @@ (setter: (prev: T) => Partial<T>): T; | ||
/** | ||
* A hydratable version of the {@link createStaticStore}. It will use the serverValue on the server and the update function on the client. If initialized during hydration it will use serverValue as the initial value and update it once hydration is complete. | ||
* | ||
* @param serverValue initial value of the state on the server | ||
* @param update called once on the client or on hydration to initialize the value | ||
* @returns | ||
* ```ts | ||
* [access: Readonly<T>, write: StaticStoreSetter<T>] | ||
* ``` | ||
*/ | ||
declare function createHydratableStaticStore<T extends Readonly<AnyStatic>>(serverValue: T, update: () => T): ReturnType<typeof createStaticStore<T>>; | ||
/** | ||
* Handle items removed and added to the array by diffing it by refference. | ||
@@ -200,15 +229,3 @@ * | ||
declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void; | ||
/** | ||
* A signal object that handle hydration. | ||
* @param serverValue initial value of the state on the server | ||
* @param update called once on the client or on hydration to initialize the value | ||
* @param options {@link SignalOptions} | ||
* @returns | ||
* ```ts | ||
* [state: Accessor<T>, setState: Setter<T>] | ||
* ``` | ||
* @see {@link createSignal} | ||
*/ | ||
declare function createHydrateSignal<T>(serverValue: T, update: () => T, options?: SignalOptions<T>): Signal<T>; | ||
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 }; | ||
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, createHydratableSignal, createHydratableStaticStore, createHydrateSignal, createMicrotask, createStaticStore, defer, entries, falseFn, handleDiffArray, isClient, isDev, isObject, isProd, keys, noop, ofClass, reverseChain, trueFn, tryOnCleanup, withAccess }; |
import { DEV, untrack, getOwner, onCleanup, createSignal, sharedConfig, onMount, batch } from 'solid-js'; | ||
import { isServer as isServer$1 } from 'solid-js/web'; | ||
import { isServer } from 'solid-js/web'; | ||
export { isServer } from 'solid-js/web'; | ||
// src/index.ts | ||
var noop = () => void 0; | ||
var isServer = isServer$1; | ||
var trueFn = () => true; | ||
var falseFn = () => false; | ||
var isClient = !isServer; | ||
@@ -87,5 +89,17 @@ var isDev = DEV && isClient; | ||
} | ||
function createHydratableSignal(serverValue, update, options) { | ||
if (isServer) { | ||
return createSignal(serverValue, options); | ||
} | ||
if (sharedConfig.context) { | ||
const [state, setState] = createSignal(serverValue, options); | ||
onMount(() => setState(() => update())); | ||
return [state, setState]; | ||
} | ||
return createSignal(update(), options); | ||
} | ||
var createHydrateSignal = createHydratableSignal; | ||
function createStaticStore(init) { | ||
const copy = { ...init }; | ||
const store = {}; | ||
const store = { ...init }; | ||
const cache = /* @__PURE__ */ new Map(); | ||
@@ -97,3 +111,3 @@ const getValue = (key) => { | ||
const signal = createSignal(copy[key], { | ||
name: typeof key === "string" ? key : void 0 | ||
internal: true | ||
}); | ||
@@ -111,17 +125,15 @@ cache.set(key, signal); | ||
}; | ||
for (const key of keys(init)) { | ||
store[key] = void 0; | ||
Object.defineProperty(store, key, { | ||
get: getValue.bind(void 0, key) | ||
}); | ||
for (const key in init) { | ||
Object.defineProperty(store, key, { get: getValue.bind(void 0, key) }); | ||
} | ||
const setter = (a, b) => { | ||
if (isObject(a)) | ||
untrack(() => { | ||
batch(() => { | ||
for (const [key, value] of entries(accessWith(a, store))) | ||
setValue(key, () => value); | ||
}); | ||
if (isObject(a)) { | ||
const entries2 = untrack( | ||
() => Object.entries(accessWith(a, store)) | ||
); | ||
batch(() => { | ||
for (const [key, value] of entries2) | ||
setValue(key, () => value); | ||
}); | ||
else | ||
} else | ||
setValue(a, b); | ||
@@ -132,2 +144,12 @@ return store; | ||
} | ||
function createHydratableStaticStore(serverValue, update) { | ||
if (isServer) | ||
return createStaticStore(serverValue); | ||
if (sharedConfig.context) { | ||
const [state, setState] = createStaticStore(serverValue); | ||
onMount(() => setState(update())); | ||
return [state, setState]; | ||
} | ||
return createStaticStore(update()); | ||
} | ||
function handleDiffArray(current, prev, handleAdded, handleRemoved) { | ||
@@ -164,11 +186,3 @@ const currLength = current.length; | ||
} | ||
function createHydrateSignal(serverValue, update, options) { | ||
if (isServer) { | ||
return createSignal(serverValue); | ||
} | ||
const [state, setState] = createSignal(sharedConfig.context ? serverValue : update(), options); | ||
sharedConfig.context && onMount(() => setState(() => update())); | ||
return [state, setState]; | ||
} | ||
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 }; | ||
export { access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createHydratableSignal, createHydratableStaticStore, createHydrateSignal, createMicrotask, createStaticStore, defer, entries, falseFn, handleDiffArray, isClient, isDev, isObject, isProd, keys, noop, ofClass, reverseChain, trueFn, tryOnCleanup, withAccess }; |
{ | ||
"name": "@solid-primitives/utils", | ||
"version": "5.4.0", | ||
"version": "5.5.0", | ||
"description": "A bunch of reactive utility types and functions, for building primitives with Solid.js", | ||
@@ -5,0 +5,0 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25134
601