react-fine-grained-signals 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-BFIWh7AD.js","names":["signal","effect","signal","computed"],"sources":["../src/core/deep-signal.ts","../src/react/hooks.ts"],"sourcesContent":["import { getActiveSub, getBatchDepth } from \"alien-signals\";\nimport {\n batch,\n isSignal,\n registerSignal,\n SIGNAL_BRAND,\n SignalImpl,\n signal,\n} from \"./base.js\";\nimport type { Signal } from \"./base.js\";\nimport { hasActiveRenderCollector } from \"./render-tracking.js\";\n\n/** A signal whose plain-object and array values are reactive by property. */\nexport interface DeepSignal<T extends object> extends Signal<T> {}\n\n/**\n * Per-key version counter. Typed as the concrete implementation rather than\n * `Signal<number>` so the metadata sweep below can consult its\n * `hasSubscribers()` liveness check; these never escape into user code.\n */\ntype VersionSignal = SignalImpl<number>;\n\ninterface PropertyMetadata {\n properties: Map<PropertyKey, VersionSignal>;\n existence: Map<PropertyKey, VersionSignal>;\n propertyIndices: Set<number>;\n existenceIndices: Set<number>;\n iteration?: Signal<number>;\n arrayMethods: Map<\n PropertyKey,\n { method: (...args: unknown[]) => unknown; wrapper: (...args: unknown[]) => unknown }\n >;\n /**\n * Keys whose property has been removed (deleted, or truncated out of an\n * array) and whose version signals are therefore candidates for removal from\n * the maps above. Drained by `sweepPrunedKeys`; a key that still has a live\n * subscriber stays queued and is retried on the next sweep. Left `undefined`\n * until the first removal so the common append-only workload allocates\n * nothing extra.\n */\n prunable?: Set<PropertyKey> | undefined;\n proxy: object;\n}\n\nconst ARRAY_MUTATORS = new Set<PropertyKey>([\n \"copyWithin\",\n \"fill\",\n \"pop\",\n \"push\",\n \"reverse\",\n \"shift\",\n \"sort\",\n \"splice\",\n \"unshift\",\n]);\nconst proxyToRaw = new WeakMap<object, object>();\nconst rawToMetadata = new WeakMap<object, PropertyMetadata>();\nconst readonlyMapViews = new WeakMap<Map<unknown, unknown>, ReadonlyMap<unknown, unknown>>();\nconst readonlySetViews = new WeakMap<Set<unknown>, ReadonlySet<unknown>>();\nconst readonlyCollectionViewToRaw = new WeakMap<object, Map<unknown, unknown> | Set<unknown>>();\n// A carrier that contains one of our proxies has to be copied before it can be\n// stored. Remember that copy so assigning the same carrier again preserves the\n// same identity and aliases, just like assigning an ordinary raw object does.\nconst normalizedProxyCarriers = new WeakMap<object, object>();\n\n/**\n * The realm's built-in prototype objects, rejected deliberately rather than by\n * accident. Several of them look exactly like plain data to the rest of this\n * module: `Array.prototype` is array-exotic (so `Array.isArray` short-circuits\n * the prototype check below), while `Error.prototype`, `Date.prototype`,\n * `Promise.prototype`, `String.prototype`, ... all inherit straight from\n * `Object.prototype` and expose only extensible, writable data properties, so\n * neither `assertExtensible` nor `assertDataProperties` stops them. Adopting\n * one as deep state would let the `set` trap `Reflect.set` onto the real,\n * globally shared intrinsic. Some of them (`Object.prototype.__proto__`,\n * `Map.prototype.size`, ...) happen to be caught today by the accessor check,\n * but that protection is incidental and asymmetric; this set makes it uniform.\n *\n * Built from `globalThis` so an engine missing a builtin simply contributes\n * nothing. Only this realm's intrinsics are listed: an object from another\n * realm already fails the `Object.prototype` identity check below (the one\n * exception being a cross-realm array, which stays accepted as it is today).\n */\nconst INTRINSIC_PROTOTYPES: ReadonlySet<object> = (() => {\n const prototypes = new Set<object>();\n for (const name of [\n \"Object\",\n \"Array\",\n \"Function\",\n \"Boolean\",\n \"Number\",\n \"String\",\n \"Symbol\",\n \"BigInt\",\n \"Date\",\n \"RegExp\",\n \"Error\",\n \"AggregateError\",\n \"EvalError\",\n \"RangeError\",\n \"ReferenceError\",\n \"SyntaxError\",\n \"TypeError\",\n \"URIError\",\n \"Map\",\n \"Set\",\n \"WeakMap\",\n \"WeakSet\",\n \"WeakRef\",\n \"FinalizationRegistry\",\n \"Promise\",\n \"ArrayBuffer\",\n \"SharedArrayBuffer\",\n \"DataView\",\n ]) {\n const intrinsic = (globalThis as unknown as Record<string, unknown>)[name];\n if (typeof intrinsic !== \"function\") continue;\n const prototype: unknown = (intrinsic as { prototype?: unknown }).prototype;\n if ((typeof prototype === \"object\" && prototype !== null) || typeof prototype === \"function\") {\n prototypes.add(prototype as object);\n }\n }\n return prototypes;\n})();\n\nconst isIntrinsicPrototype = (value: unknown): boolean =>\n isObjectLike(value) && INTRINSIC_PROTOTYPES.has(value);\n\nfunction isPlainObjectOrArray(value: unknown): value is object {\n if (typeof value !== \"object\" || value === null || isSignal(value)) return false;\n // Before `Array.isArray`, which would otherwise wave `Array.prototype`\n // through: it is array-exotic, extensible, and carries only data properties.\n if (INTRINSIC_PROTOTYPES.has(value)) return false;\n if (Array.isArray(value)) return true;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction isObjectLike(value: unknown): value is object {\n return (typeof value === \"object\" && value !== null) || typeof value === \"function\";\n}\n\n/**\n * Resolves a value that may be one of our proxies or one of our readonly\n * collection views back to the raw object it wraps. Returns `undefined` when\n * `value` is not object-like or is not a value this module has wrapped, so\n * callers can fall back to using it as-is.\n */\nfunction toRaw(value: unknown): object | undefined {\n if (!isObjectLike(value)) return undefined;\n const directRaw = proxyToRaw.get(value);\n if (directRaw !== undefined) return directRaw;\n return readonlyCollectionViewToRaw.get(value);\n}\n\ntype RejectMutation = (operation: string) => () => never;\n\n/**\n * Shared scaffolding for `readonlyMapView`/`readonlySetView`: cache lookup,\n * the \"reject this mutation\" factory, defining the descriptors, the\n * feature-detected extras loop, and the dual-WeakMap registration. Only the\n * per-type descriptor bodies (which truly differ between Map and Set) and\n * the extras list are supplied by the caller.\n */\nfunction createReadonlyCollectionView<Raw extends object, View extends object>(\n raw: Raw,\n cache: WeakMap<Raw, View>,\n prototype: object,\n kind: string,\n buildCore: (raw: Raw, view: View, rejectMutation: RejectMutation) => Record<PropertyKey, PropertyDescriptor>,\n buildExtras: (raw: Raw, rejectMutation: RejectMutation) => Array<[string, (...args: unknown[]) => unknown]>,\n): View {\n const cached = cache.get(raw);\n if (cached !== undefined) return cached;\n\n const view = Object.create(prototype) as View;\n const rejectMutation: RejectMutation = (operation: string) => () => {\n throw new TypeError(\n `deepSignal() ${kind}#${operation}() is not allowed through .value; replace the ${kind} immutably`,\n );\n };\n Object.defineProperties(view, buildCore(raw, view, rejectMutation));\n for (const [name, impl] of buildExtras(raw, rejectMutation)) {\n Object.defineProperty(view, name, { enumerable: false, configurable: false, value: impl });\n }\n\n cache.set(raw, view);\n readonlyCollectionViewToRaw.set(view, raw as Map<unknown, unknown> | Set<unknown>);\n return view;\n}\n\nfunction readonlyMapView<Key, Value>(raw: Map<Key, Value>): ReadonlyMap<Key, Value> {\n return createReadonlyCollectionView(\n raw as Map<unknown, unknown>,\n readonlyMapViews,\n Map.prototype,\n \"Map\",\n (target, view, rejectMutation) => ({\n size: { enumerable: false, configurable: false, get: () => target.size },\n get: { enumerable: false, configurable: false, value: (key: unknown) => target.get(key) },\n has: { enumerable: false, configurable: false, value: (key: unknown) => target.has(key) },\n entries: {\n enumerable: false,\n configurable: false,\n value: () => Map.prototype.entries.call(target),\n },\n keys: {\n enumerable: false,\n configurable: false,\n value: () => Map.prototype.keys.call(target),\n },\n values: {\n enumerable: false,\n configurable: false,\n value: () => Map.prototype.values.call(target),\n },\n forEach: {\n enumerable: false,\n configurable: false,\n value: (\n callback: (value: unknown, key: unknown, map: ReadonlyMap<unknown, unknown>) => void,\n thisArg?: unknown,\n ) => {\n Map.prototype.forEach.call(target, (value, key) => callback.call(thisArg, value, key, view));\n },\n },\n [Symbol.iterator]: {\n enumerable: false,\n configurable: false,\n value: () => Map.prototype.entries.call(target),\n },\n set: { enumerable: false, configurable: false, value: rejectMutation(\"set\") },\n delete: { enumerable: false, configurable: false, value: rejectMutation(\"delete\") },\n clear: { enumerable: false, configurable: false, value: rejectMutation(\"clear\") },\n }),\n (_target, rejectMutation) => {\n const extras: Array<[string, (...args: unknown[]) => unknown]> = [];\n // Keep future mutating Map proposals from becoming an integrity bypass when\n // they are present in the running JavaScript engine.\n for (const operation of [\"getOrInsert\", \"getOrInsertComputed\", \"emplace\"]) {\n if (typeof (Map.prototype as unknown as Record<string, unknown>)[operation] === \"function\") {\n extras.push([operation, rejectMutation(operation)]);\n }\n }\n return extras;\n },\n ) as ReadonlyMap<Key, Value>;\n}\n\nfunction readonlySetView<Value>(raw: Set<Value>): ReadonlySet<Value> {\n return createReadonlyCollectionView(\n raw as Set<unknown>,\n readonlySetViews,\n Set.prototype,\n \"Set\",\n (target, view, rejectMutation) => ({\n size: { enumerable: false, configurable: false, get: () => target.size },\n has: { enumerable: false, configurable: false, value: (value: unknown) => target.has(value) },\n entries: {\n enumerable: false,\n configurable: false,\n value: () => Set.prototype.entries.call(target),\n },\n keys: {\n enumerable: false,\n configurable: false,\n value: () => Set.prototype.keys.call(target),\n },\n values: {\n enumerable: false,\n configurable: false,\n value: () => Set.prototype.values.call(target),\n },\n forEach: {\n enumerable: false,\n configurable: false,\n value: (\n callback: (value: unknown, key: unknown, set: ReadonlySet<unknown>) => void,\n thisArg?: unknown,\n ) => {\n Set.prototype.forEach.call(target, (value) => callback.call(thisArg, value, value, view));\n },\n },\n [Symbol.iterator]: {\n enumerable: false,\n configurable: false,\n value: () => Set.prototype.values.call(target),\n },\n add: { enumerable: false, configurable: false, value: rejectMutation(\"add\") },\n delete: { enumerable: false, configurable: false, value: rejectMutation(\"delete\") },\n clear: { enumerable: false, configurable: false, value: rejectMutation(\"clear\") },\n }),\n (target) => {\n const extras: Array<[string, (...args: unknown[]) => unknown]> = [];\n const forwardSetOperation = (operation: string) => (other: unknown) => {\n const method = (Set.prototype as unknown as Record<string, unknown>)[operation];\n if (typeof method !== \"function\") {\n throw new TypeError(`Set#${operation}() is unavailable in this JavaScript engine`);\n }\n const collection =\n isObjectLike(other) ? readonlyCollectionViewToRaw.get(other) ?? other : other;\n return Reflect.apply(method, target, [collection]);\n };\n // ES2025's Set operations are non-mutating. Forward them to the raw Set so\n // native methods receive their required internal-slot receiver. A second\n // deepSignal read-only view is unwrapped first because it is also set-like.\n for (const operation of [\n \"union\",\n \"intersection\",\n \"difference\",\n \"symmetricDifference\",\n \"isSubsetOf\",\n \"isSupersetOf\",\n \"isDisjointFrom\",\n ]) {\n if (typeof (Set.prototype as unknown as Record<string, unknown>)[operation] === \"function\") {\n extras.push([operation, forwardSetOperation(operation)]);\n }\n }\n return extras;\n },\n ) as ReadonlySet<Value>;\n}\n\nfunction assertRootValue(value: unknown): asserts value is object {\n if (!isPlainObjectOrArray(value)) {\n throw new TypeError(\"deepSignal() only accepts a plain object or array root\");\n }\n}\n\nfunction assertExtensible(value: object): void {\n if (!Object.isExtensible(value)) {\n throw new TypeError(\"deepSignal() cannot proxy a non-extensible object or array\");\n }\n}\n\nfunction assertDataProperties(value: object): void {\n for (const key of Reflect.ownKeys(value)) {\n const descriptor = Reflect.getOwnPropertyDescriptor(value, key);\n if (descriptor !== undefined && !(\"value\" in descriptor)) {\n throw new TypeError(\"deepSignal() does not support accessor properties\");\n }\n }\n}\n\nfunction assertDeepDataGraph(value: unknown): boolean {\n if (!isObjectLike(value)) return false;\n // A value can be reachable both as reactive plain data and through an opaque\n // value. A proxy beneath an opaque value cannot be unwrapped without changing\n // that value's observable identity, so reject it instead of leaking a proxy\n // into the raw tree.\n const seen = new WeakMap<object, number>();\n const pending: Array<{ value: object; insideOpaque: boolean }> = [\n { value, insideOpaque: false },\n ];\n let needsNormalization = false;\n\n while (pending.length > 0) {\n const { value: current, insideOpaque } = pending.pop() as {\n value: object;\n insideOpaque: boolean;\n };\n const wrapperRaw = toRaw(current);\n if (wrapperRaw !== undefined) {\n if (insideOpaque) {\n throw new TypeError(\n proxyToRaw.has(current)\n ? \"deepSignal() cannot store a deep proxy inside an opaque value\"\n : \"deepSignal() cannot store a deep collection view inside an opaque value\",\n );\n }\n // The raw graph was validated when this proxy (or collection view) was\n // created. Do not walk it again: this makes `{ inner: state.value.large }`\n // proportional to the new carrier rather than the already-known subtree.\n needsNormalization = true;\n continue;\n }\n const raw = current;\n const visitedAs = seen.get(raw) ?? 0;\n const visitFlag = insideOpaque ? 2 : 1;\n if ((visitedAs & visitFlag) !== 0) continue;\n seen.set(raw, visitedAs | visitFlag);\n\n // A built-in prototype adopted as reactive data would be written through\n // by the `set` trap, landing on the realm's shared intrinsic. Reject it\n // here, ahead of every branch below, so the diagnosis is the same for\n // `Array.prototype` (which nothing else catches) and for `Object.prototype`\n // (which only trips the accessor check by accident). Values reached\n // *through* an opaque one are exempt: they are never proxied and never\n // written to, and `{ ctor: Array }` reaches `Array.prototype` that way.\n if (!insideOpaque && isIntrinsicPrototype(raw)) {\n throw new TypeError(\"deepSignal() cannot store a built-in prototype object in deep state\");\n }\n\n if (raw instanceof Map) {\n for (const [key, entry] of raw) {\n if (isObjectLike(key)) {\n pending.push({ value: key, insideOpaque: true });\n }\n if (isObjectLike(entry)) {\n pending.push({ value: entry, insideOpaque: true });\n }\n }\n continue;\n }\n if (raw instanceof Set) {\n for (const entry of raw) {\n if (isObjectLike(entry)) {\n pending.push({ value: entry, insideOpaque: true });\n }\n }\n continue;\n }\n if (!isPlainObjectOrArray(raw)) {\n // Class instances, Date, functions, and other opaque values retain their\n // identity. Inspect their own data descriptors without invoking getters\n // so a contained deep proxy cannot enter the raw graph.\n for (const key of Reflect.ownKeys(raw)) {\n const descriptor = Reflect.getOwnPropertyDescriptor(raw, key);\n if (descriptor !== undefined && \"value\" in descriptor && isObjectLike(descriptor.value)) {\n pending.push({ value: descriptor.value, insideOpaque: true });\n }\n }\n continue;\n }\n\n if (!insideOpaque) {\n assertExtensible(raw);\n assertDataProperties(raw);\n }\n for (const key of Reflect.ownKeys(raw)) {\n const descriptor = Reflect.getOwnPropertyDescriptor(raw, key);\n if (descriptor !== undefined && \"value\" in descriptor) {\n const child = descriptor.value;\n if (isObjectLike(child)) {\n pending.push({ value: child, insideOpaque });\n }\n }\n }\n }\n\n return needsNormalization;\n}\n\nfunction matchesNormalizedGraph(source: object, normalized: object): boolean {\n const sources = new WeakMap<object, object>();\n const targets = new WeakMap<object, object>();\n const pending: Array<[unknown, unknown]> = [[source, normalized]];\n\n while (pending.length > 0) {\n const [currentSource, currentTarget] = pending.pop() as [unknown, unknown];\n if (typeof currentSource !== \"object\" || currentSource === null) {\n if (!Object.is(currentSource, currentTarget)) return false;\n continue;\n }\n\n const wrapperRaw = toRaw(currentSource);\n if (wrapperRaw !== undefined) {\n if (wrapperRaw !== currentTarget) return false;\n continue;\n }\n if (!isPlainObjectOrArray(currentSource)) {\n if (currentSource !== currentTarget) return false;\n continue;\n }\n if (\n typeof currentTarget !== \"object\" ||\n currentTarget === null ||\n !isPlainObjectOrArray(currentTarget)\n ) {\n return false;\n }\n\n const knownTarget = sources.get(currentSource);\n if (knownTarget !== undefined) {\n if (knownTarget !== currentTarget) return false;\n continue;\n }\n const knownSource = targets.get(currentTarget);\n if (knownSource !== undefined && knownSource !== currentSource) return false;\n sources.set(currentSource, currentTarget);\n targets.set(currentTarget, currentSource);\n\n if (\n Array.isArray(currentSource) !== Array.isArray(currentTarget) ||\n Object.getPrototypeOf(currentSource) !== Object.getPrototypeOf(currentTarget)\n ) {\n return false;\n }\n const sourceKeys = Reflect.ownKeys(currentSource);\n const targetKeys = Reflect.ownKeys(currentTarget);\n if (sourceKeys.length !== targetKeys.length) return false;\n // `entries()` rather than a plain index read so `key` is typed as a key\n // rather than `key | undefined`: `Reflect.ownKeys` returns a dense array,\n // so every index in range holds one, but only iteration says that in types.\n for (const [index, key] of sourceKeys.entries()) {\n if (key !== targetKeys[index]) return false;\n const sourceDescriptor = Reflect.getOwnPropertyDescriptor(currentSource, key);\n const targetDescriptor = Reflect.getOwnPropertyDescriptor(currentTarget, key);\n if (\n sourceDescriptor === undefined ||\n targetDescriptor === undefined ||\n !(\"value\" in sourceDescriptor) ||\n !(\"value\" in targetDescriptor) ||\n sourceDescriptor.configurable !== targetDescriptor.configurable ||\n sourceDescriptor.enumerable !== targetDescriptor.enumerable ||\n sourceDescriptor.writable !== targetDescriptor.writable\n ) {\n return false;\n }\n pending.push([sourceDescriptor.value, targetDescriptor.value]);\n }\n }\n\n return true;\n}\n\n/**\n * An array of `length` with no own index properties — holes, not `undefined`s.\n * `Array.from({ length })` would materialize every index as an own property,\n * so cloning a sparse carrier produced an array with strictly more own keys\n * than its source. `matchesNormalizedGraph` compares own keys one-for-one, so\n * that clone could never match its source again: the carrier cache missed on\n * every re-assignment, breaking the documented guarantee that assigning the\n * same carrier twice preserves identity and aliasing.\n */\nfunction emptyArrayOfLength(length: number): unknown[] {\n const result: unknown[] = [];\n result.length = length;\n return result;\n}\n\nfunction cloneWithoutProxies<T>(value: T): T {\n const wrapperRaw = toRaw(value);\n if (wrapperRaw !== undefined) return wrapperRaw as T;\n if (!isObjectLike(value)) return value;\n\n const cachedRoot = normalizedProxyCarriers.get(value);\n if (\n cachedRoot !== undefined &&\n matchesNormalizedGraph(value, cachedRoot)\n ) {\n return cachedRoot as T;\n }\n\n const clones = new WeakMap<object, object>();\n const created: Array<[object, object]> = [];\n const pending: object[] = [];\n\n const resolve = (current: unknown): unknown => {\n const resolvedRaw = toRaw(current);\n if (resolvedRaw !== undefined) return resolvedRaw;\n if (!isPlainObjectOrArray(current)) return current;\n\n const local = clones.get(current);\n if (local !== undefined) return local;\n\n const result: object = Array.isArray(current)\n ? emptyArrayOfLength(current.length)\n : Object.create(Object.getPrototypeOf(current));\n clones.set(current, result);\n created.push([current, result]);\n pending.push(current);\n return result;\n };\n\n const root = resolve(value) as T;\n while (pending.length > 0) {\n const source = pending.pop() as object;\n const target = clones.get(source) as object;\n for (const key of Reflect.ownKeys(source)) {\n if (Array.isArray(source) && key === \"length\") continue;\n const descriptor = Reflect.getOwnPropertyDescriptor(source, key);\n if (descriptor === undefined) continue;\n // Validation has already rejected accessors, before any clone is exposed.\n if (!(\"value\" in descriptor)) {\n throw new TypeError(\"deepSignal() does not support accessor properties\");\n }\n descriptor.value = resolve(descriptor.value);\n Reflect.defineProperty(target, key, descriptor);\n }\n }\n\n for (const [source, target] of created) {\n normalizedProxyCarriers.set(source, target);\n }\n return root;\n}\n\nfunction prepareDeepValue<T>(value: T): T {\n // Reassigning a value obtained from this deep signal is already known-good.\n // Avoid validating its entire graph again on this common O(1) path.\n const wrapperRaw = toRaw(value);\n if (wrapperRaw !== undefined) return wrapperRaw as T;\n const containsProxy = assertDeepDataGraph(value);\n return containsProxy ? cloneWithoutProxies(value) : value;\n}\n\nfunction isArrayIndex(key: PropertyKey): key is string {\n if (typeof key !== \"string\" || key === \"\") return false;\n const index = Number(key);\n return (\n Number.isInteger(index) &&\n index >= 0 &&\n index < 0xffff_ffff &&\n String(index) === key\n );\n}\n\n// `wrap`/`unwrap` and their helpers below have no per-call state: every map\n// they touch (`rawToMetadata`, `proxyToRaw`, ...) is module-global, and each\n// `PropertyMetadata` is threaded through explicit parameters. They are\n// module-scoped functions rather than being re-allocated as closures on\n// every `deepSignal()` call.\n\nconst unwrap = <T>(value: T): T => {\n return prepareDeepValue(value);\n};\n\n// Inherited members of the two prototypes a deep-signal target can have.\n// Reading one of these through the proxy (`list.map`, `list[Symbol.iterator]`,\n// `state.constructor`, ...) used to mint a permanent version signal for a key\n// that can never change, so a single `.map()` per render leaked one entry per\n// method name for the lifetime of the page. They are only skipped while the\n// key is *not* an own property, so a real data property named `map` or\n// `toString` — and an array's own `length` — stays fully reactive, and a\n// null-prototype object (which inherits nothing) is never affected.\nconst OBJECT_PROTOTYPE_KEYS: ReadonlySet<PropertyKey> = new Set(\n Reflect.ownKeys(Object.prototype),\n);\nconst ARRAY_PROTOTYPE_KEYS: ReadonlySet<PropertyKey> = new Set([\n ...Reflect.ownKeys(Object.prototype),\n ...Reflect.ownKeys(Array.prototype),\n]);\n\nconst isInheritedPrototypeMember = (target: object, key: PropertyKey): boolean => {\n if (Object.prototype.hasOwnProperty.call(target, key)) return false;\n const prototype = Object.getPrototypeOf(target) as object | null;\n if (prototype === Object.prototype) return OBJECT_PROTOTYPE_KEYS.has(key);\n if (prototype === Array.prototype) return ARRAY_PROTOTYPE_KEYS.has(key);\n return false;\n};\n\nconst getVersion = (\n versions: Map<PropertyKey, VersionSignal>,\n key: PropertyKey,\n): VersionSignal => {\n let version = versions.get(key);\n if (version === undefined) {\n version = registerSignal(new SignalImpl<number>(0));\n versions.set(key, version);\n }\n return version;\n};\n\nconst track = (\n target: object,\n versions: Map<PropertyKey, VersionSignal>,\n indices: Set<number>,\n key: PropertyKey,\n): void => {\n if (getActiveSub() === undefined && !hasActiveRenderCollector()) return;\n if (isInheritedPrototypeMember(target, key)) return;\n if (isArrayIndex(key)) indices.add(Number(key));\n const version = getVersion(versions, key);\n // Records that something reactive depends on this key right now, which is\n // what keeps `sweepPrunedKeys` from dropping it out from under a subscriber.\n version.markWatched();\n version.value;\n};\n\nconst notify = (\n versions: Map<PropertyKey, VersionSignal>,\n key: PropertyKey,\n): void => {\n const version = versions.get(key);\n if (version !== undefined) version.value += 1;\n};\n\n/**\n * Queues `key`'s version signals for removal once nothing depends on them.\n * Only called for a key that has just been removed *and* notified, which is\n * what makes the eventual removal safe: the notification forces every\n * subscriber to re-run, so one that still cares re-reads the key (re-arming\n * `markWatched`) and one that does not has already been unlinked.\n */\nconst markPrunable = (metadata: PropertyMetadata, key: PropertyKey): void => {\n if (!metadata.properties.has(key) && !metadata.existence.has(key)) return;\n (metadata.prunable ??= new Set()).add(key);\n};\n\n/**\n * Drops the version signals of removed keys once they have no subscribers\n * left, so a virtualized or repeatedly-spliced list stops accumulating one\n * entry per key that ever existed.\n *\n * Runs only at batch depth 0, where the write that queued these keys has\n * already flushed its effects; before that, `hasSubscribers()` would still\n * report the pre-flush picture. A key that is still subscribed (typically a\n * React store whose re-render has not committed yet) stays queued and is\n * reconsidered on the next sweep rather than being dropped early.\n */\nconst sweepPrunedKeys = (metadata: PropertyMetadata, target: object): void => {\n const prunable = metadata.prunable;\n if (prunable === undefined || prunable.size === 0) return;\n if (getBatchDepth() !== 0) return;\n\n for (const key of prunable) {\n // The key came back (an index was written again, a property re-added):\n // its version signals are live metadata again, not garbage.\n if (Object.prototype.hasOwnProperty.call(target, key)) {\n prunable.delete(key);\n continue;\n }\n const property = metadata.properties.get(key);\n const existence = metadata.existence.get(key);\n if (property?.hasSubscribers() === true || existence?.hasSubscribers() === true) {\n continue;\n }\n metadata.properties.delete(key);\n metadata.existence.delete(key);\n if (isArrayIndex(key)) {\n const index = Number(key);\n metadata.propertyIndices.delete(index);\n metadata.existenceIndices.delete(index);\n }\n prunable.delete(key);\n }\n\n if (prunable.size === 0) metadata.prunable = undefined;\n};\n\nconst trackIteration = (metadata: PropertyMetadata): void => {\n if (getActiveSub() === undefined && !hasActiveRenderCollector()) return;\n metadata.iteration ??= signal(0);\n metadata.iteration.value;\n};\n\nconst notifyIteration = (metadata: PropertyMetadata): void => {\n if (metadata.iteration !== undefined) metadata.iteration.value += 1;\n};\n\nconst notifyTruncatedIndices = (\n metadata: PropertyMetadata,\n currentLength: number,\n oldLength: number,\n): void => {\n const truncatedCount = oldLength - currentLength;\n const trackedCount =\n metadata.propertyIndices.size + metadata.existenceIndices.size;\n if (trackedCount === 0) return;\n\n if (truncatedCount <= trackedCount) {\n for (let index = currentLength; index < oldLength; index++) {\n const key = String(index);\n notify(metadata.properties, key);\n notify(metadata.existence, key);\n markPrunable(metadata, key);\n }\n return;\n }\n for (const index of metadata.propertyIndices) {\n if (index >= currentLength && index < oldLength) {\n const key = String(index);\n notify(metadata.properties, key);\n markPrunable(metadata, key);\n }\n }\n for (const index of metadata.existenceIndices) {\n if (index >= currentLength && index < oldLength) {\n const key = String(index);\n notify(metadata.existence, key);\n markPrunable(metadata, key);\n }\n }\n};\n\n/**\n * Whether `wrap()` would hand back something other than `value` itself — a\n * deep proxy for a plain object/array, or a readonly view for a Map/Set. The\n * `get` trap uses this to reject a non-configurable, non-writable property\n * whose value cannot be substituted, before `wrap()` performs the swap.\n */\nconst isWrappedByValue = (value: unknown): boolean =>\n isPlainObjectOrArray(value) || value instanceof Map || value instanceof Set;\n\nconst wrap = <T>(value: T): T => {\n const rawValue = (toRaw(value) as T | undefined) ?? value;\n if (rawValue instanceof Map) return readonlyMapView(rawValue) as T;\n if (rawValue instanceof Set) return readonlySetView(rawValue) as T;\n if (!isPlainObjectOrArray(rawValue)) return rawValue;\n assertExtensible(rawValue);\n\n const cached = rawToMetadata.get(rawValue);\n if (cached !== undefined) return cached.proxy as T;\n assertDataProperties(rawValue);\n\n const metadata: PropertyMetadata = {\n properties: new Map(),\n existence: new Map(),\n propertyIndices: new Set(),\n existenceIndices: new Set(),\n arrayMethods: new Map(),\n proxy: undefined as unknown as object,\n };\n\n const proxy = new Proxy(rawValue, {\n get(target, key, receiver) {\n // Deep state is raw data, never a signal. Answering the identity probe\n // up front keeps `isSignal()` on a nested proxy from allocating a\n // version signal for a key that can never change. An own brand only\n // exists if a raw reference bypassed this proxy, and it is reported so\n // the proxy invariants hold.\n if (key === SIGNAL_BRAND && !Object.prototype.hasOwnProperty.call(target, key)) {\n return undefined;\n }\n track(target, metadata.properties, metadata.propertyIndices, key);\n const result = Reflect.get(target, key, receiver);\n\n if (\n Array.isArray(target) &&\n ARRAY_MUTATORS.has(key) &&\n typeof result === \"function\"\n ) {\n const cachedMethod = metadata.arrayMethods.get(key);\n if (cachedMethod?.method === result) return cachedMethod.wrapper;\n\n const method = result as (...args: unknown[]) => unknown;\n const wrapper = function (this: unknown, ...args: unknown[]) {\n try {\n return batch(() => Reflect.apply(method, this, args));\n } finally {\n sweepPrunedKeys(metadata, target);\n }\n };\n metadata.arrayMethods.set(key, { method, wrapper });\n return wrapper;\n }\n\n // Checked before `wrap()` substitutes anything: `wrap()` also swaps a\n // Map/Set for a readonly view, and those views are just as unassignable\n // back through a non-configurable, non-writable slot as a nested proxy\n // is. Gating this on `isPlainObjectOrArray(result)` let a frozen\n // Map/Set-valued property past the friendly error and into a raw engine\n // `TypeError` later on.\n if (isWrappedByValue(result)) {\n const descriptor = Reflect.getOwnPropertyDescriptor(target, key);\n if (\n descriptor !== undefined &&\n \"value\" in descriptor &&\n descriptor.configurable === false &&\n descriptor.writable === false\n ) {\n throw new TypeError(\n \"deepSignal() cannot wrap a non-configurable, non-writable object property\",\n );\n }\n }\n\n return wrap(result);\n },\n\n set(target, key, nextValue) {\n if (key === \"__proto__\") {\n throw new TypeError(\"deepSignal() does not support prototype mutation\");\n }\n // Storing the brand would make this subtree answer `isSignal()`, which\n // silently stops it from being wrapped and kills its reactivity.\n if (key === SIGNAL_BRAND) {\n throw new TypeError(\"deepSignal() does not support branding state as a signal\");\n }\n const oldValue = Reflect.get(target, key, target);\n const existed = Reflect.has(target, key);\n const owned = Object.prototype.hasOwnProperty.call(target, key);\n const oldLength = Array.isArray(target) ? target.length : undefined;\n const rawNextValue = unwrap(nextValue);\n const succeeded = Reflect.set(target, key, rawNextValue, target);\n if (!succeeded) return false;\n\n const currentValue = Reflect.get(target, key, target);\n const existsNow = Reflect.has(target, key);\n const ownedNow = Object.prototype.hasOwnProperty.call(target, key);\n\n batch(() => {\n if (!Object.is(oldValue, currentValue) || owned !== ownedNow) {\n notify(metadata.properties, key);\n }\n if (existed !== existsNow) notify(metadata.existence, key);\n if (owned !== ownedNow) notifyIteration(metadata);\n\n if (Array.isArray(target) && oldLength !== undefined) {\n const currentLength = target.length;\n if (key !== \"length\" && oldLength !== currentLength) {\n notify(metadata.properties, \"length\");\n }\n if (key === \"length\" && currentLength < oldLength) {\n notifyTruncatedIndices(metadata, currentLength, oldLength);\n notifyIteration(metadata);\n }\n }\n });\n sweepPrunedKeys(metadata, target);\n\n return true;\n },\n\n deleteProperty(target, key) {\n const existed = Reflect.has(target, key);\n const owned = Object.prototype.hasOwnProperty.call(target, key);\n const succeeded = Reflect.deleteProperty(target, key);\n if (!succeeded || !owned) return succeeded;\n\n batch(() => {\n notify(metadata.properties, key);\n if (existed !== Reflect.has(target, key)) {\n notify(metadata.existence, key);\n }\n notifyIteration(metadata);\n markPrunable(metadata, key);\n });\n sweepPrunedKeys(metadata, target);\n return true;\n },\n\n getOwnPropertyDescriptor(target, key) {\n // `Object.getOwnPropertyDescriptor(state, key).value` is a read of the\n // property, so it subscribes through the same per-key version signal the\n // `get` trap uses and hands back the same wrapped value. Without this\n // trap the descriptor carried the raw nested object: a read that never\n // re-ran, and — via `Object.getOwnPropertyDescriptors` — every top-level\n // raw reference in one call.\n track(target, metadata.properties, metadata.propertyIndices, key);\n const descriptor = Reflect.getOwnPropertyDescriptor(target, key);\n if (descriptor === undefined || !(\"value\" in descriptor)) return descriptor;\n\n // The one value that cannot be substituted. [[GetOwnProperty]] requires\n // the reported descriptor to be compatible with the target's, and for a\n // non-configurable, non-writable data property that means reporting the\n // very same value — a proxy may not lie about it, so the engine throws\n // at the call site if we swap in a wrapper. `get` refuses such a\n // property outright rather than hand back an unwrapped reference; here\n // refusing would break `Object.getOwnPropertyDescriptors()` for the\n // whole object, so report it exactly as it is, which is also all the\n // invariant ever lets a caller observe.\n if (descriptor.configurable === false && descriptor.writable === false) {\n return descriptor;\n }\n\n descriptor.value = wrap(descriptor.value);\n return descriptor;\n },\n\n has(target, key) {\n track(target, metadata.existence, metadata.existenceIndices, key);\n return Reflect.has(target, key);\n },\n\n ownKeys(target) {\n trackIteration(metadata);\n return Reflect.ownKeys(target);\n },\n\n defineProperty() {\n throw new TypeError(\"deepSignal() does not support property descriptors\");\n },\n\n preventExtensions() {\n throw new TypeError(\"deepSignal() state must remain extensible\");\n },\n\n setPrototypeOf() {\n throw new TypeError(\"deepSignal() does not support prototype mutation\");\n },\n });\n\n metadata.proxy = proxy;\n rawToMetadata.set(rawValue, metadata);\n proxyToRaw.set(proxy, rawValue);\n return proxy as T;\n};\n\nclass DeepSignalImpl<T extends object> implements DeepSignal<T> {\n readonly #source: SignalImpl<T>;\n\n constructor(initialValue: T) {\n this.#source = new SignalImpl(initialValue);\n }\n\n get value(): T {\n // Runtime collection views intentionally keep the established `.value: T`\n // public type. `DeepSignal<T>` must remain assignable to `Signal<T>`.\n return wrap(this.#source.value) as T;\n }\n\n set value(nextValue: T) {\n const rawValue = unwrap(nextValue);\n assertRootValue(rawValue);\n this.#source.value = rawValue as T;\n }\n\n peek(): T {\n return this.#source.peek();\n }\n}\n\n/**\n * Reports the per-key reactive metadata currently retained for a deep proxy\n * (or for the raw object behind it). Exposed for this package's own tests\n * only — it is deliberately absent from every published entry point, and the\n * shape it returns is internal detail, not API.\n */\nexport function inspectDeepSignalMetadata(value: object): {\n properties: PropertyKey[];\n existence: PropertyKey[];\n propertyIndices: number[];\n existenceIndices: number[];\n} | undefined {\n const metadata = rawToMetadata.get(toRaw(value) ?? value);\n if (metadata === undefined) return undefined;\n return {\n properties: [...metadata.properties.keys()],\n existence: [...metadata.existence.keys()],\n propertyIndices: [...metadata.propertyIndices],\n existenceIndices: [...metadata.existenceIndices],\n };\n}\n\n/**\n * Creates a signal that lazily tracks nested plain-object and array properties.\n * Mutations must go through `.value`; changes made through the original raw\n * object are intentionally not observable.\n */\nexport function deepSignal<T extends object>(initialValue: T): DeepSignal<T> {\n const rawInitialValue = prepareDeepValue(initialValue);\n assertRootValue(rawInitialValue);\n\n wrap(rawInitialValue);\n return registerSignal(new DeepSignalImpl(rawInitialValue as T)) as DeepSignal<T>;\n}\n","import {\n useCallback,\n useEffect as useReactEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\";\nimport { computed, deepSignal, effect, signal, untracked } from \"../core/index.js\";\nimport type {\n DeepSignal,\n ReadonlySignal,\n Signal,\n} from \"../core/index.js\";\nimport { untrackedRender } from \"../core/render-tracking.js\";\nimport type { DependencyList } from \"react\";\nexport { useSignals } from \"./use-signals.js\";\n\nconst EMPTY_DEPENDENCIES: DependencyList = [];\n\n/** Which of `useComputed`'s two mutually exclusive modes a call site uses. */\ntype ComputedMode = \"without a dependency array\" | \"with a dependency array\";\n\n/** An immutable value that React can safely compare as an external-store snapshot. */\nexport type SignalSnapshot =\n | string\n | number\n | boolean\n | bigint\n | symbol\n | null\n | undefined;\n\ntype SelectorResult<S extends SignalSnapshot> =\n | { readonly kind: \"value\"; readonly value: S }\n | { readonly kind: \"error\"; readonly error: unknown };\n\nfunction assertSignalSnapshot(value: unknown): asserts value is SignalSnapshot {\n if ((typeof value === \"object\" && value !== null) || typeof value === \"function\") {\n throw new TypeError(\n \"useDeepSignalValue selector must return a primitive snapshot; objects, Proxies, and functions are not supported\",\n );\n }\n}\n\n/**\n * Shared `useSyncExternalStore` subscription wiring for a signal-backed\n * store. On `subscribe`, starts an `effect()` that reruns `onEvaluate` on\n * every relevant signal write and notifies React exactly when it reports a\n * change; returns that effect's own dispose as the unsubscribe. The very\n * first synchronous run — made while `subscribe` itself is still\n * establishing the effect — never notifies, matching how each caller here\n * already behaved: `useSyncExternalStore` performs its own \"did the\n * snapshot change since render\" check independently of anything a `notify`\n * call does, so a store's own subscribe-time run does not need to report on\n * that window too.\n *\n * `getSnapshot` is intentionally not this helper's concern — the caller\n * wires its own, whether that means recomputing fresh each call\n * (`useSignalValue`) or returning a cached result (the deep-selector store).\n *\n * An exception thrown by `onEvaluate` is swallowed here and treated as a\n * change worth notifying about. This mirrors `useSignalValue`'s prior\n * inline behavior: a computed that starts failing must still trigger a\n * re-render so `getSnapshot`'s own unguarded read can rethrow into an Error\n * Boundary, rather than leaving this background effect's throw to escape\n * into whatever write triggered the re-run. Callers whose `onEvaluate`\n * already captures errors into its own return value (the deep-selector\n * store) never hit this path.\n */\nfunction createSignalStore(onEvaluate: () => boolean): (notify: () => void) => () => void {\n return (notify: () => void): (() => void) => {\n let isInitialRun = true;\n return effect(() => {\n let changed: boolean;\n try {\n changed = onEvaluate();\n } catch {\n changed = true;\n }\n if (isInitialRun) {\n isInitialRun = false;\n return;\n }\n if (changed) notify();\n });\n };\n}\n\n/**\n * Holds a selector result outside the reactive graph. In particular, a\n * selector error must not escape from the signal write that caused a reactive\n * re-evaluation: React needs to observe it during its next render so an Error\n * Boundary can handle it. Unlike `useSignalValue`, errors are modeled as an\n * explicit `SelectorResult` union rather than swallowed and re-thrown from a\n * fresh read: `getSnapshot` below must return the same cached result the\n * subscribed effect last settled on, not re-run `selector` on every render.\n */\nfunction createDeepSelectorStore<T extends object, S extends SignalSnapshot>(\n source: DeepSignal<T>,\n selector: (value: T) => S,\n) {\n const evaluate = (): SelectorResult<S> => {\n try {\n const value = untrackedRender(() => selector(source.value));\n assertSignalSnapshot(value);\n return { kind: \"value\", value };\n } catch (error) {\n return { kind: \"error\", error };\n }\n };\n\n let result = evaluate();\n\n const hasChanged = (next: SelectorResult<S>): boolean => {\n if (result.kind !== next.kind) return true;\n return result.kind === \"value\" && next.kind === \"value\"\n ? !Object.is(result.value, next.value)\n : result.kind === \"error\" && next.kind === \"error\"\n ? !Object.is(result.error, next.error)\n : false;\n };\n\n return {\n // Layers Object.is diffing on top of the shared subscribe/notify core:\n // an update to the deep signal reruns `selector`, but only a result that\n // actually differs from the last one (by Object.is, same rule the\n // `getSnapshot`-level comparison in `useSyncExternalStore` itself uses)\n // is worth a React re-render.\n subscribe: createSignalStore(() => {\n const next = evaluate();\n if (!hasChanged(next)) return false;\n result = next;\n return true;\n }),\n getSnapshot(): S {\n if (result.kind === \"error\") throw result.error;\n return result.value;\n },\n };\n}\n\n/** Creates a signal whose identity is stable for the lifetime of this component. */\nexport function useSignal<T>(initialValue: T): Signal<T> {\n const signalRef = useRef<Signal<T> | undefined>(undefined);\n\n if (signalRef.current === undefined) {\n signalRef.current = signal(initialValue);\n }\n\n return signalRef.current;\n}\n\n/**\n * Creates a deep signal whose identity is stable for the component lifetime.\n * A factory is evaluated only while initializing a mounted component instance;\n * it must remain pure because React Strict Mode may replay initial rendering.\n */\nexport function useDeepSignal<T extends object>(\n initialValue: T | (() => T),\n): DeepSignal<T> {\n const signalRef = useRef<DeepSignal<T> | undefined>(undefined);\n\n if (signalRef.current === undefined) {\n signalRef.current = deepSignal(\n typeof initialValue === \"function\" ? initialValue() : initialValue,\n );\n }\n\n return signalRef.current;\n}\n\n/**\n * Selects a property-level primitive snapshot from a deep signal.\n *\n * Every non-signal value captured by `selector` must be listed in\n * `dependencies`. Object and proxy results are intentionally rejected because\n * mutable snapshots cannot satisfy `useSyncExternalStore` identity semantics.\n *\n * `dependencies` must keep a fixed length across this component's lifetime,\n * matching `useMemo`'s own rule (its length feeds a `useMemo` deps array\n * below via `[source, ...dependencies]`). A length change is caught and\n * thrown as a clear error rather than left to degrade into React's silent\n * \"changed size between renders\" dev warning, mirroring `useComputed`'s\n * dependency-mode-switch guard.\n */\nexport function useDeepSignalValue<\n T extends object,\n S extends SignalSnapshot,\n>(\n source: DeepSignal<T>,\n selector: (value: T) => S,\n dependencies: DependencyList,\n): S {\n // A variable-length `dependencies` would otherwise only surface as React's\n // dev-mode \"changed size between renders\" warning on the `useMemo` call\n // below, while silently recreating the store (and losing selector/error\n // history) on every subsequent render. Mirrors `useComputed`'s mode-switch\n // guard below: a violation is a loud, actionable error instead of a\n // silently degraded memo.\n const initialDependencyLengthRef = useRef<number | undefined>(undefined);\n initialDependencyLengthRef.current ??= dependencies.length;\n if (dependencies.length !== initialDependencyLengthRef.current) {\n const error = new Error(\n `useDeepSignalValue: the \\`dependencies\\` array length changed between renders (from ${initialDependencyLengthRef.current} to ${dependencies.length}) for this call site. Keep \\`dependencies\\` a fixed length across the component's lifetime, matching useMemo's rules.`,\n );\n error.name = \"UseDeepSignalValueDependencyLengthChangeError\";\n throw error;\n }\n\n const store = useMemo(\n () => createDeepSelectorStore(source, selector),\n [source, ...dependencies],\n );\n return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n}\n\n/**\n * Creates a computed signal with a stable identity.\n *\n * When `dependencies` is omitted, the getter must only read signals. Its initial\n * closure is retained for the component lifetime, so props, state, and other\n * non-signal values must not be captured in that mode.\n *\n * When the getter captures props, state, or any other non-signal value, list all\n * of those values in `dependencies`. React memoization then creates a separate\n * computed when they change, rather than replacing the getter of an existing\n * computed during render. An abandoned render therefore cannot change the\n * closure used by the previously committed computed. Choose one mode for a\n * component's lifetime.\n */\nexport function useComputed<T>(\n getValue: () => T,\n dependencies?: DependencyList,\n): ReadonlySignal<T> {\n const dependencyComputed = useMemo(\n () =>\n dependencies === undefined\n ? undefined\n : computed(getValue),\n dependencies ?? EMPTY_DEPENDENCIES,\n );\n\n const initialModeRef = useRef<ComputedMode | undefined>(undefined);\n const signalOnlyComputedRef = useRef<ReadonlySignal<T> | undefined>(undefined);\n\n // Both directions of a mode switch are silently destructive, so neither is\n // allowed to reach the caller as a mystery. Going deps -> no-deps used to\n // hand back `undefined` typed as `ReadonlySignal<T>`, so the crash surfaced\n // at the call site as \"Cannot read properties of undefined (reading\n // 'value')\" with nothing pointing back here. Going no-deps -> deps quietly\n // built a *second* computed with a new identity mid-lifetime, invalidating\n // every subscription already made to the first.\n const mode: ComputedMode =\n dependencies === undefined ? \"without a dependency array\" : \"with a dependency array\";\n initialModeRef.current ??= mode;\n if (initialModeRef.current !== mode) {\n const error = new Error(\n `useComputed: the dependency-array mode changed between renders (from ${initialModeRef.current} to ${mode}) for this call site. Keep passing deps consistently, matching useMemo's rules.`,\n );\n error.name = \"UseComputedModeChangeError\";\n throw error;\n }\n\n // Defined exactly when `dependencies` is, per the memo above; checking the\n // result rather than the argument is what removes the old `!` assertion.\n if (dependencyComputed !== undefined) return dependencyComputed;\n\n if (signalOnlyComputedRef.current === undefined) {\n signalOnlyComputedRef.current = computed(getValue);\n }\n\n return signalOnlyComputedRef.current;\n}\n\n/**\n * Runs a reactive effect after this component has committed, disposing it when\n * the component unmounts (and during React Strict Mode's development replay).\n *\n * When `dependencies` is omitted, the callback must only capture signals. Its\n * initial closure is retained for the component lifetime, so unrelated React\n * renders do not restart the effect.\n *\n * When the callback captures props, state, or any other non-signal value, list\n * all of those values in `dependencies`. The effect is then reconnected after\n * those dependencies change. Choose one mode for a component's lifetime.\n */\nexport function useSignalEffect(\n callback: () => void | (() => void),\n dependencies?: DependencyList,\n): void {\n useReactEffect(() => effect(callback), dependencies ?? EMPTY_DEPENDENCIES);\n}\n\n/**\n * Reads a signal and subscribes the component to subsequent changes.\n *\n * The immediate run made by the public `effect` API establishes dependency\n * tracking only. It intentionally does not notify React: `useSyncExternalStore`\n * owns the initial consistency check after subscribing. See `createSignalStore`\n * for the shared subscribe/notify wiring, including why a read that throws\n * (a computed whose cached error `.value` rethrows) is swallowed in the\n * background effect and left for `getSnapshot` to rethrow instead.\n */\nexport function useSignalValue<T>(source: ReadonlySignal<T>): T {\n const subscribe = useMemo(\n () =>\n createSignalStore(() => {\n // The read (not its result) is what registers the alien-signals\n // dependency link, so it still happens even though the return value\n // here is constant: every non-initial run of this effect is reported\n // as a change, exactly as before.\n source.value;\n return true;\n }),\n [source],\n );\n\n // A leaf subscription owns this read. An unmanaged useSignals() scope may\n // still be open for an ancestor or earlier sibling until React commits, so\n // do not also register the source with that component's render collector.\n // `untracked` rather than `untrackedRender`: the latter clears only this\n // package's render collector, leaving alien-signals' own `activeSub` in\n // place, so a `getSnapshot` reached while some effect or computed is\n // evaluating would silently graft this source onto that subscriber's\n // dependency list. `computed()` and `peek()` already use `untracked` for\n // exactly this reason.\n const getSnapshot = useCallback(\n () => untracked(() => source.value),\n [source],\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"],"mappings":";;;;;AA4CA,MAAM,iCAAiB,IAAI,IAAiB;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,6BAAa,IAAI,QAAwB;AAC/C,MAAM,gCAAgB,IAAI,QAAkC;AAC5D,MAAM,mCAAmB,IAAI,QAA8D;AAC3F,MAAM,mCAAmB,IAAI,QAA4C;AACzE,MAAM,8CAA8B,IAAI,QAAsD;AAI9F,MAAM,0CAA0B,IAAI,QAAwB;;;;;;;;;;;;;;;;;;;AAoB5D,MAAM,8BAAmD;CACvD,MAAM,6BAAa,IAAI,IAAY;CACnC,KAAK,MAAM,QAAQ;EACjB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAC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B,MAAM,WAAW,MAAM,aAAa,MAAM,WAAW;AACnF;;;;;;;;;;;;;;;AAgBA,SAAgB,YACd,UACA,cACmB;CACnB,MAAM,qBAAqB,cAEvB,iBAAiB,KAAA,IACb,KAAA,IACAC,WAAS,QAAQ,GACvB,gBAAgB,kBAClB;CAEA,MAAM,iBAAiB,OAAiC,KAAA,CAAS;CACjE,MAAM,wBAAwB,OAAsC,KAAA,CAAS;CAS7E,MAAM,OACJ,iBAAiB,KAAA,IAAY,+BAA+B;CAC9D,eAAe,YAAY;CAC3B,IAAI,eAAe,YAAY,MAAM;EACnC,MAAM,wBAAQ,IAAI,MAChB,wEAAwE,eAAe,QAAQ,MAAM,KAAK,gFAC5G;EACA,MAAM,OAAO;EACb,MAAM;CACR;CAIA,IAAI,uBAAuB,KAAA,GAAW,OAAO;CAE7C,IAAI,sBAAsB,YAAY,KAAA,GACpC,sBAAsB,UAAUA,WAAS,QAAQ;CAGnD,OAAO,sBAAsB;AAC/B;;;;;;;;;;;;;AAcA,SAAgB,gBACd,UACA,cACM;CACN,gBAAqBF,SAAO,QAAQ,GAAG,gBAAgB,kBAAkB;AAC3E;;;;;;;;;;;AAYA,SAAgB,eAAkB,QAA8B;CAC9D,MAAM,YAAY,cAEd,wBAAwB;EAKtB,OAAO;EACP,OAAO;CACT,CAAC,GACH,CAAC,MAAM,CACT;CAWA,MAAM,cAAc,kBACZ,gBAAgB,OAAO,KAAK,GAClC,CAAC,MAAM,CACT;CAEA,OAAO,qBAAqB,WAAW,aAAa,WAAW;AACjE"}
@@ -0,0 +1,80 @@
1
+ import { a as effect, c as untracked, i as computed, n as Signal, o as isSignal, r as batch, s as signal, t as ReadonlySignal } from "./base-Bx5ahfW2.js";
2
+ import { r as useSignals } from "./use-signals-CBDbbAbV.js";
3
+ import { DependencyList } from "react";
4
+ //#region src/core/deep-signal.d.ts
5
+ /** A signal whose plain-object and array values are reactive by property. */
6
+ interface DeepSignal<T extends object> extends Signal<T> {}
7
+ /**
8
+ * Creates a signal that lazily tracks nested plain-object and array properties.
9
+ * Mutations must go through `.value`; changes made through the original raw
10
+ * object are intentionally not observable.
11
+ */
12
+ declare function deepSignal<T extends object>(initialValue: T): DeepSignal<T>;
13
+ //#endregion
14
+ //#region src/react/hooks.d.ts
15
+ /** An immutable value that React can safely compare as an external-store snapshot. */
16
+ type SignalSnapshot = string | number | boolean | bigint | symbol | null | undefined;
17
+ /** Creates a signal whose identity is stable for the lifetime of this component. */
18
+ declare function useSignal<T>(initialValue: T): Signal<T>;
19
+ /**
20
+ * Creates a deep signal whose identity is stable for the component lifetime.
21
+ * A factory is evaluated only while initializing a mounted component instance;
22
+ * it must remain pure because React Strict Mode may replay initial rendering.
23
+ */
24
+ declare function useDeepSignal<T extends object>(initialValue: T | (() => T)): DeepSignal<T>;
25
+ /**
26
+ * Selects a property-level primitive snapshot from a deep signal.
27
+ *
28
+ * Every non-signal value captured by `selector` must be listed in
29
+ * `dependencies`. Object and proxy results are intentionally rejected because
30
+ * mutable snapshots cannot satisfy `useSyncExternalStore` identity semantics.
31
+ *
32
+ * `dependencies` must keep a fixed length across this component's lifetime,
33
+ * matching `useMemo`'s own rule (its length feeds a `useMemo` deps array
34
+ * below via `[source, ...dependencies]`). A length change is caught and
35
+ * thrown as a clear error rather than left to degrade into React's silent
36
+ * "changed size between renders" dev warning, mirroring `useComputed`'s
37
+ * dependency-mode-switch guard.
38
+ */
39
+ declare function useDeepSignalValue<T extends object, S extends SignalSnapshot>(source: DeepSignal<T>, selector: (value: T) => S, dependencies: DependencyList): S;
40
+ /**
41
+ * Creates a computed signal with a stable identity.
42
+ *
43
+ * When `dependencies` is omitted, the getter must only read signals. Its initial
44
+ * closure is retained for the component lifetime, so props, state, and other
45
+ * non-signal values must not be captured in that mode.
46
+ *
47
+ * When the getter captures props, state, or any other non-signal value, list all
48
+ * of those values in `dependencies`. React memoization then creates a separate
49
+ * computed when they change, rather than replacing the getter of an existing
50
+ * computed during render. An abandoned render therefore cannot change the
51
+ * closure used by the previously committed computed. Choose one mode for a
52
+ * component's lifetime.
53
+ */
54
+ declare function useComputed<T>(getValue: () => T, dependencies?: DependencyList): ReadonlySignal<T>;
55
+ /**
56
+ * Runs a reactive effect after this component has committed, disposing it when
57
+ * the component unmounts (and during React Strict Mode's development replay).
58
+ *
59
+ * When `dependencies` is omitted, the callback must only capture signals. Its
60
+ * initial closure is retained for the component lifetime, so unrelated React
61
+ * renders do not restart the effect.
62
+ *
63
+ * When the callback captures props, state, or any other non-signal value, list
64
+ * all of those values in `dependencies`. The effect is then reconnected after
65
+ * those dependencies change. Choose one mode for a component's lifetime.
66
+ */
67
+ declare function useSignalEffect(callback: () => void | (() => void), dependencies?: DependencyList): void;
68
+ /**
69
+ * Reads a signal and subscribes the component to subsequent changes.
70
+ *
71
+ * The immediate run made by the public `effect` API establishes dependency
72
+ * tracking only. It intentionally does not notify React: `useSyncExternalStore`
73
+ * owns the initial consistency check after subscribing. See `createSignalStore`
74
+ * for the shared subscribe/notify wiring, including why a read that throws
75
+ * (a computed whose cached error `.value` rethrows) is swallowed in the
76
+ * background effect and left for `getSnapshot` to rethrow instead.
77
+ */
78
+ declare function useSignalValue<T>(source: ReadonlySignal<T>): T;
79
+ //#endregion
80
+ export { type DeepSignal, type ReadonlySignal, type Signal, type SignalSnapshot, batch, computed, deepSignal, effect, isSignal, signal, untracked, useComputed, useDeepSignal, useDeepSignalValue, useSignal, useSignalEffect, useSignalValue, useSignals };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { a as effect, c as signal, i as computed, l as untracked, o as isSignal, r as batch } from "./base-BZTnpU8U.js";
2
+ import { a as useSignalEffect, i as useSignal, n as useDeepSignal, o as useSignalValue, r as useDeepSignalValue, s as deepSignal, t as useComputed } from "./hooks-BFIWh7AD.js";
3
+ import { n as useSignals } from "./use-signals-8i2B-94o.js";
4
+ export { batch, computed, deepSignal, effect, isSignal, signal, untracked, useComputed, useDeepSignal, useDeepSignalValue, useSignal, useSignalEffect, useSignalValue, useSignals };