signalium 3.0.1 → 3.0.2
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/CHANGELOG.md +6 -0
- package/dist/cjs/development/index.js +1 -1
- package/dist/cjs/development/react/index.js +1 -1
- package/dist/cjs/development/{snapshot-BfP4w3lC.js → snapshot-CbZ6IH3B.js} +4 -3
- package/dist/cjs/development/snapshot-CbZ6IH3B.js.map +1 -0
- package/dist/cjs/development/utils.js +1 -1
- package/dist/cjs/production/index.js +1 -1
- package/dist/cjs/production/react/index.js +1 -1
- package/dist/cjs/production/{snapshot-DnzyLNij.js → snapshot-DWwH7_9y.js} +4 -3
- package/dist/cjs/production/snapshot-DWwH7_9y.js.map +1 -0
- package/dist/cjs/production/utils.js +1 -1
- package/dist/esm/development/index.js +1 -1
- package/dist/esm/development/react/index.js +1 -1
- package/dist/esm/development/{snapshot-DbLBnoC8.js → snapshot-CkndI4Hh.js} +4 -3
- package/dist/esm/development/snapshot-CkndI4Hh.js.map +1 -0
- package/dist/esm/development/utils.js +2 -2
- package/dist/esm/internals/utils/snapshot.d.ts.map +1 -1
- package/dist/esm/production/index.js +1 -1
- package/dist/esm/production/react/index.js +1 -1
- package/dist/esm/production/{snapshot-DzqbjLXg.js → snapshot-CdCaJJ0L.js} +4 -3
- package/dist/esm/production/snapshot-CdCaJJ0L.js.map +1 -0
- package/dist/esm/production/utils.js +2 -2
- package/package.json +1 -1
- package/dist/cjs/development/snapshot-BfP4w3lC.js.map +0 -1
- package/dist/cjs/production/snapshot-DnzyLNij.js.map +0 -1
- package/dist/esm/development/snapshot-DbLBnoC8.js.map +0 -1
- package/dist/esm/production/snapshot-DzqbjLXg.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# signalium
|
|
2
2
|
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 20767d3: Fix `useReactive` snapshots of `ReactiveTask` to carry over the `run` method. Previously, when a task was read through `useReactive`, the deep-snapshot returned a plain object with `value`/`error`/`isPending`/etc. but no `run`, so consumers couldn't invoke `result.run(...)` against the underlying task. The snapshot now includes `run`, and its identity is included in the structural-equality short-circuit so reference stability across pending → resolved transitions is preserved.
|
|
8
|
+
|
|
3
9
|
## 3.0.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const snapshot = require("./snapshot-
|
|
3
|
+
const snapshot = require("./snapshot-CbZ6IH3B.js");
|
|
4
4
|
const debug = require("./debug-C46WDxhL.js");
|
|
5
5
|
const utils = require("./utils.js");
|
|
6
6
|
exports.reactive = snapshot.reactive;
|
|
@@ -4,7 +4,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const debug = require("../debug-C46WDxhL.js");
|
|
6
6
|
const componentShared = require("../component-shared-Cug2Y5YZ.js");
|
|
7
|
-
const snapshot = require("../snapshot-
|
|
7
|
+
const snapshot = require("../snapshot-CbZ6IH3B.js");
|
|
8
8
|
function _interopNamespaceDefault(e) {
|
|
9
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
10
|
if (e) {
|
|
@@ -81,10 +81,11 @@ function snapshotReactivePromise(current, prev, snap) {
|
|
|
81
81
|
const isResolved = current.isResolved;
|
|
82
82
|
const isReady = current.isReady;
|
|
83
83
|
const isSettled = current.isSettled;
|
|
84
|
-
|
|
84
|
+
const run = current.run;
|
|
85
|
+
if (prevObj && value === prevObj.value && error === prevObj.error && isPending === prevObj.isPending && isRejected === prevObj.isRejected && isResolved === prevObj.isResolved && isReady === prevObj.isReady && isSettled === prevObj.isSettled && run === prevObj.run) {
|
|
85
86
|
return prevObj;
|
|
86
87
|
}
|
|
87
|
-
return { value, error, isPending, isRejected, isResolved, isReady, isSettled };
|
|
88
|
+
return { value, error, isPending, isRejected, isResolved, isReady, isSettled, run };
|
|
88
89
|
}
|
|
89
90
|
function snapshotMap(current, prev, snap) {
|
|
90
91
|
const prevMap = prev instanceof Map ? prev : void 0;
|
|
@@ -154,4 +155,4 @@ exports.relay = relay;
|
|
|
154
155
|
exports.snapshot = snapshot;
|
|
155
156
|
exports.task = task;
|
|
156
157
|
exports.watcher = watcher;
|
|
157
|
-
//# sourceMappingURL=snapshot-
|
|
158
|
+
//# sourceMappingURL=snapshot-CbZ6IH3B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-CbZ6IH3B.js","sources":["../../../.tsc-out/internals/core-api.js","../../../.tsc-out/internals/utils/snapshot.js"],"sourcesContent":["import { getCurrentScope, getScopeOwner, SignalScope } from './contexts.js';\nimport { createReactiveDefinition, createReactiveSignal, } from './reactive.js';\nimport { createRelay, createTask } from './async.js';\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const DERIVED_DEFINITION_MAP = new WeakMap();\nexport function getReactiveFnAndDefinition(fn, opts) {\n let fnAndDef = DERIVED_DEFINITION_MAP.get(fn);\n if (!fnAndDef) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const defScope = getCurrentScope();\n const reactiveFn = (...args) => {\n const scope = getCurrentScope(defScope);\n const signal = scope.get(def, args);\n return signal.value;\n };\n fnAndDef = [reactiveFn, def];\n DERIVED_DEFINITION_MAP.set(fn, fnAndDef);\n }\n return fnAndDef;\n}\nexport function reactive(fn, opts) {\n return getReactiveFnAndDefinition(fn, opts)[0];\n}\nexport const reactiveMethod = (owner, fn, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const reactiveFn = (...args) => {\n return getScopeOwner(owner).get(def, args).value;\n };\n DERIVED_DEFINITION_MAP.set(reactiveFn, [reactiveFn, def]);\n return reactiveFn;\n};\nexport function relay(activate, opts) {\n const scope = getCurrentScope();\n return createRelay(activate, scope, opts);\n}\nexport const task = (fn, opts) => {\n const scope = getCurrentScope();\n return createTask(fn, scope, opts);\n};\nexport function watcher(fn, opts) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, undefined, opts?.tracer);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n}\n/**\n * Creates a reactive signal from a compute function. This is useful for when you\n * want to create a signal that does not receive parameters, but is still reactive.\n *\n * @param compute\n * @param opts\n * @returns\n */\nexport const reactiveSignal = (compute, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, compute, opts?.equals, false, undefined, undefined);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n};\n","import { isReactivePromise } from '../async.js';\nconst getProto = Object.getPrototypeOf;\nfunction snapshotArray(current, prev, snap) {\n const prevArr = Array.isArray(prev) ? prev : undefined;\n let changed = !prevArr || prevArr.length !== current.length;\n const result = new Array(current.length);\n for (let i = 0; i < current.length; i++) {\n result[i] = snap(current[i], prevArr?.[i]);\n if (!changed && result[i] !== prevArr[i]) {\n changed = true;\n }\n }\n return changed ? result : prevArr;\n}\nfunction snapshotPlainObject(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' && !Array.isArray(prev)\n ? prev\n : undefined;\n const keys = Object.keys(current);\n let changed = !prevObj || Object.keys(prevObj).length !== keys.length;\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n result[key] = snap(current[key], prevObj?.[key]);\n if (!changed && result[key] !== prevObj[key]) {\n changed = true;\n }\n }\n return changed ? result : prevObj;\n}\nfunction snapshotReactivePromise(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' ? prev : undefined;\n const value = snap(current.value, prevObj?.value);\n const error = current.error;\n const isPending = current.isPending;\n const isRejected = current.isRejected;\n const isResolved = current.isResolved;\n const isReady = current.isReady;\n const isSettled = current.isSettled;\n // `run` is set once in the task constructor and never mutated, so its identity\n // is stable for the lifetime of the underlying ReactivePromiseImpl. Carrying\n // it on the snapshot lets consumers (e.g. React components reading a task via\n // `useReactive`) invoke `result.run(...)` against the live task. For non-task\n // promises this is `undefined`; we still assign the slot so the resulting\n // object's hidden class is stable across task and non-task snapshots.\n const run = current.run;\n if (prevObj &&\n value === prevObj.value &&\n error === prevObj.error &&\n isPending === prevObj.isPending &&\n isRejected === prevObj.isRejected &&\n isResolved === prevObj.isResolved &&\n isReady === prevObj.isReady &&\n isSettled === prevObj.isSettled &&\n run === prevObj.run) {\n return prevObj;\n }\n return { value, error, isPending, isRejected, isResolved, isReady, isSettled, run };\n}\nfunction snapshotMap(current, prev, snap) {\n const prevMap = prev instanceof Map ? prev : undefined;\n let changed = !prevMap || prevMap.size !== current.size;\n const result = new Map();\n for (const [key, val] of current) {\n const snapped = snap(val, prevMap?.get(key));\n result.set(key, snapped);\n if (!changed && snapped !== prevMap.get(key)) {\n changed = true;\n }\n }\n return changed ? result : prevMap;\n}\nfunction snapshotSet(current, prev, _snap) {\n const prevSet = prev instanceof Set ? prev : undefined;\n let changed = !prevSet || prevSet.size !== current.size;\n const result = new Set();\n for (const val of current) {\n const snapped = snapshot(val, prevSet?.has(val) ? val : undefined);\n result.add(snapped);\n if (!changed && !prevSet.has(snapped)) {\n changed = true;\n }\n }\n return changed ? result : prevSet;\n}\n/**\n * Built-in handlers for plain structural types. Matched by exact prototype\n * only — subclasses of `Object` / `Array` / `Map` / `Set` are NOT routed\n * through these handlers (they fall through and, if no custom ancestor is\n * registered, are returned as-is). We use a Map here rather than installing\n * a symbol property on the built-in prototypes, because mutating built-in\n * prototypes (even with a symbol key) changes their hidden class and\n * invalidates V8's fast-path inline caches for every plain object / array\n * in the program.\n */\nconst BUILTIN_PROTO_TO_SNAPSHOT = new Map([\n [Object.prototype, snapshotPlainObject],\n [Array.prototype, snapshotArray],\n [Map.prototype, snapshotMap],\n [Set.prototype, snapshotSet],\n [null, snapshotPlainObject],\n]);\n/**\n * Custom registrations are stored as a non-enumerable symbol property on the\n * class prototype. JS prototype lookup walks the chain natively, so subclass\n * inheritance and override-by-redefinition are free — no resolver, no cache,\n * no invalidation. The symbol is module-private (created with `Symbol()`,\n * not `Symbol.for()`), so it cannot collide with anything else and cannot\n * be addressed by user code.\n */\nconst SNAPSHOT_HANDLER = Symbol('signalium.snapshot.handler');\n/**\n * Register a custom snapshot function for instances of a class.\n * The function receives the current value, the previous snapshot (or undefined),\n * and the recursive `snapshot` function for snapshotting nested values.\n *\n * Subclasses inherit the handler automatically via prototype lookup, so\n * registering once on a base class applies to all descendants. A descendant\n * can override by registering its own handler.\n *\n * Return `prev` when nothing has changed to preserve reference stability.\n *\n * @example\n * ```ts\n * registerCustomSnapshot(MyEntity, (current, prev, snapshot) => {\n * const name = snapshot(current.name, prev?.name);\n * const age = current.age;\n * if (prev && name === prev.name && age === prev.age) return prev;\n * return { name, age };\n * });\n * ```\n */\nexport const registerCustomSnapshot = (ctor, snapshotFn) => {\n // Use defineProperty so the handler is non-enumerable (it shouldn't show up\n // in `Reflect.ownKeys` walks any more than necessary) and so re-registration\n // overwrites cleanly even if a subclass has shadowed it.\n Object.defineProperty(ctor.prototype, SNAPSHOT_HANDLER, {\n value: snapshotFn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n};\n/**\n * Recursively snapshot a value with structural sharing.\n *\n * - Plain objects and arrays are deep-cloned; unchanged subtrees keep the same reference.\n * - ReactivePromise instances are read (establishing deps) and flattened to a plain object.\n * - Class instances are returned as-is unless a custom handler is registered\n * for the class or any of its ancestors via `registerCustomSnapshot`.\n * - Primitives are returned directly.\n */\nexport function snapshot(currentValue, prevValue) {\n if (currentValue === null || typeof currentValue !== 'object') {\n return currentValue;\n }\n if (isReactivePromise(currentValue)) {\n return snapshotReactivePromise(currentValue, prevValue, snapshot);\n }\n // Custom registrations check first: native prototype lookup walks the chain\n // for us, so subclasses inherit their ancestor's handler with no extra work.\n const customHandler = currentValue[SNAPSHOT_HANDLER];\n if (customHandler !== undefined) {\n return customHandler(currentValue, prevValue, snapshot);\n }\n // Built-in handlers are looked up by exact prototype only.\n const builtIn = BUILTIN_PROTO_TO_SNAPSHOT.get(getProto(currentValue));\n if (builtIn !== undefined) {\n return builtIn(currentValue, prevValue, snapshot);\n }\n return currentValue;\n}\n"],"names":["createReactiveDefinition","getCurrentScope","getScopeOwner","createRelay","createTask","SignalScope","createReactiveSignal","isReactivePromise"],"mappings":";;AAIO,MAAM,yBAAyB,oBAAI,QAAO;AAC1C,SAAS,2BAA2B,IAAI,MAAM;AACjD,MAAI,WAAW,uBAAuB,IAAI,EAAE;AAC5C,MAAI,CAAC,UAAU;AACX,UAAM,MAAMA,MAAAA,yBAAyB,MAAM,IAAI,MAAM,MAAM,IAAI,MAAM,QAAQ,OAAO,MAAM,UAAU,MAAS;AAC7G,UAAM,WAAWC,MAAAA,gBAAe;AAChC,UAAM,aAAa,IAAI,SAAS;AAC5B,YAAM,QAAQA,MAAAA,gBAAgB,QAAQ;AACtC,YAAM,SAAS,MAAM,IAAI,KAAK,IAAI;AAClC,aAAO,OAAO;AAAA,IAClB;AACA,eAAW,CAAC,YAAY,GAAG;AAC3B,2BAAuB,IAAI,IAAI,QAAQ;AAAA,EAC3C;AACA,SAAO;AACX;AACO,SAAS,SAAS,IAAI,MAAM;AAC/B,SAAO,2BAA2B,IAAI,IAAI,EAAE,CAAC;AACjD;AACY,MAAC,iBAAiB,CAAC,OAAO,IAAI,SAAS;AAC/C,QAAM,MAAMD,MAAAA,yBAAyB,MAAM,IAAI,MAAM,MAAM,IAAI,MAAM,QAAQ,OAAO,MAAM,UAAU,MAAS;AAC7G,QAAM,aAAa,IAAI,SAAS;AAC5B,WAAOE,MAAAA,cAAc,KAAK,EAAE,IAAI,KAAK,IAAI,EAAE;AAAA,EAC/C;AACA,yBAAuB,IAA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iBAAiB,QAAQ,OAAO,iBAAiB,UAAU;AAC3D,WAAO;AAAA,EACX;AACA,MAAIC,MAAAA,kBAAkB,YAAY,GAAG;AACjC,WAAO,wBAAwB,cAAc,WAAW,QAAQ;AAAA,EACpE;AAGA,QAAM,gBAAgB,aAAa,gBAAgB;AACnD,MAAI,kBAAkB,QAAW;AAC7B,WAAO,cAAc,cAAc,WAAW,QAAQ;AAAA,EAC1D;AAEA,QAAM,UAAU,0BAA0B,IAAI,SAAS,YAAY,CAAC;AACpE,MAAI,YAAY,QAAW;AACvB,WAAO,QAAQ,cAAc,WAAW,QAAQ;AAAA,EACpD;AACA,SAAO;AACX;;;;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const snapshot = require("./snapshot-
|
|
3
|
+
const snapshot = require("./snapshot-CbZ6IH3B.js");
|
|
4
4
|
const debug = require("./debug-C46WDxhL.js");
|
|
5
5
|
function watchOnce(fn) {
|
|
6
6
|
const signal = snapshot.watcher(fn);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const snapshot = require("./snapshot-
|
|
3
|
+
const snapshot = require("./snapshot-DWwH7_9y.js");
|
|
4
4
|
const contexts = require("./contexts-CM3QLfV8.js");
|
|
5
5
|
const utils = require("./utils.js");
|
|
6
6
|
exports.reactive = snapshot.reactive;
|
|
@@ -4,7 +4,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const contexts = require("../contexts-CM3QLfV8.js");
|
|
6
6
|
const componentShared = require("../component-shared-D0J85PUi.js");
|
|
7
|
-
const snapshot = require("../snapshot-
|
|
7
|
+
const snapshot = require("../snapshot-DWwH7_9y.js");
|
|
8
8
|
function _interopNamespaceDefault(e) {
|
|
9
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
10
|
if (e) {
|
|
@@ -81,10 +81,11 @@ function snapshotReactivePromise(current, prev, snap) {
|
|
|
81
81
|
const isResolved = current.isResolved;
|
|
82
82
|
const isReady = current.isReady;
|
|
83
83
|
const isSettled = current.isSettled;
|
|
84
|
-
|
|
84
|
+
const run = current.run;
|
|
85
|
+
if (prevObj && value === prevObj.value && error === prevObj.error && isPending === prevObj.isPending && isRejected === prevObj.isRejected && isResolved === prevObj.isResolved && isReady === prevObj.isReady && isSettled === prevObj.isSettled && run === prevObj.run) {
|
|
85
86
|
return prevObj;
|
|
86
87
|
}
|
|
87
|
-
return { value, error, isPending, isRejected, isResolved, isReady, isSettled };
|
|
88
|
+
return { value, error, isPending, isRejected, isResolved, isReady, isSettled, run };
|
|
88
89
|
}
|
|
89
90
|
function snapshotMap(current, prev, snap) {
|
|
90
91
|
const prevMap = prev instanceof Map ? prev : void 0;
|
|
@@ -154,4 +155,4 @@ exports.relay = relay;
|
|
|
154
155
|
exports.snapshot = snapshot;
|
|
155
156
|
exports.task = task;
|
|
156
157
|
exports.watcher = watcher;
|
|
157
|
-
//# sourceMappingURL=snapshot-
|
|
158
|
+
//# sourceMappingURL=snapshot-DWwH7_9y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-DWwH7_9y.js","sources":["../../../.tsc-out/internals/core-api.js","../../../.tsc-out/internals/utils/snapshot.js"],"sourcesContent":["import { getCurrentScope, getScopeOwner, SignalScope } from './contexts.js';\nimport { createReactiveDefinition, createReactiveSignal, } from './reactive.js';\nimport { createRelay, createTask } from './async.js';\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const DERIVED_DEFINITION_MAP = new WeakMap();\nexport function getReactiveFnAndDefinition(fn, opts) {\n let fnAndDef = DERIVED_DEFINITION_MAP.get(fn);\n if (!fnAndDef) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const defScope = getCurrentScope();\n const reactiveFn = (...args) => {\n const scope = getCurrentScope(defScope);\n const signal = scope.get(def, args);\n return signal.value;\n };\n fnAndDef = [reactiveFn, def];\n DERIVED_DEFINITION_MAP.set(fn, fnAndDef);\n }\n return fnAndDef;\n}\nexport function reactive(fn, opts) {\n return getReactiveFnAndDefinition(fn, opts)[0];\n}\nexport const reactiveMethod = (owner, fn, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const reactiveFn = (...args) => {\n return getScopeOwner(owner).get(def, args).value;\n };\n DERIVED_DEFINITION_MAP.set(reactiveFn, [reactiveFn, def]);\n return reactiveFn;\n};\nexport function relay(activate, opts) {\n const scope = getCurrentScope();\n return createRelay(activate, scope, opts);\n}\nexport const task = (fn, opts) => {\n const scope = getCurrentScope();\n return createTask(fn, scope, opts);\n};\nexport function watcher(fn, opts) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, undefined, opts?.tracer);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n}\n/**\n * Creates a reactive signal from a compute function. This is useful for when you\n * want to create a signal that does not receive parameters, but is still reactive.\n *\n * @param compute\n * @param opts\n * @returns\n */\nexport const reactiveSignal = (compute, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, compute, opts?.equals, false, undefined, undefined);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n};\n","import { isReactivePromise } from '../async.js';\nconst getProto = Object.getPrototypeOf;\nfunction snapshotArray(current, prev, snap) {\n const prevArr = Array.isArray(prev) ? prev : undefined;\n let changed = !prevArr || prevArr.length !== current.length;\n const result = new Array(current.length);\n for (let i = 0; i < current.length; i++) {\n result[i] = snap(current[i], prevArr?.[i]);\n if (!changed && result[i] !== prevArr[i]) {\n changed = true;\n }\n }\n return changed ? result : prevArr;\n}\nfunction snapshotPlainObject(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' && !Array.isArray(prev)\n ? prev\n : undefined;\n const keys = Object.keys(current);\n let changed = !prevObj || Object.keys(prevObj).length !== keys.length;\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n result[key] = snap(current[key], prevObj?.[key]);\n if (!changed && result[key] !== prevObj[key]) {\n changed = true;\n }\n }\n return changed ? result : prevObj;\n}\nfunction snapshotReactivePromise(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' ? prev : undefined;\n const value = snap(current.value, prevObj?.value);\n const error = current.error;\n const isPending = current.isPending;\n const isRejected = current.isRejected;\n const isResolved = current.isResolved;\n const isReady = current.isReady;\n const isSettled = current.isSettled;\n // `run` is set once in the task constructor and never mutated, so its identity\n // is stable for the lifetime of the underlying ReactivePromiseImpl. Carrying\n // it on the snapshot lets consumers (e.g. React components reading a task via\n // `useReactive`) invoke `result.run(...)` against the live task. For non-task\n // promises this is `undefined`; we still assign the slot so the resulting\n // object's hidden class is stable across task and non-task snapshots.\n const run = current.run;\n if (prevObj &&\n value === prevObj.value &&\n error === prevObj.error &&\n isPending === prevObj.isPending &&\n isRejected === prevObj.isRejected &&\n isResolved === prevObj.isResolved &&\n isReady === prevObj.isReady &&\n isSettled === prevObj.isSettled &&\n run === prevObj.run) {\n return prevObj;\n }\n return { value, error, isPending, isRejected, isResolved, isReady, isSettled, run };\n}\nfunction snapshotMap(current, prev, snap) {\n const prevMap = prev instanceof Map ? prev : undefined;\n let changed = !prevMap || prevMap.size !== current.size;\n const result = new Map();\n for (const [key, val] of current) {\n const snapped = snap(val, prevMap?.get(key));\n result.set(key, snapped);\n if (!changed && snapped !== prevMap.get(key)) {\n changed = true;\n }\n }\n return changed ? result : prevMap;\n}\nfunction snapshotSet(current, prev, _snap) {\n const prevSet = prev instanceof Set ? prev : undefined;\n let changed = !prevSet || prevSet.size !== current.size;\n const result = new Set();\n for (const val of current) {\n const snapped = snapshot(val, prevSet?.has(val) ? val : undefined);\n result.add(snapped);\n if (!changed && !prevSet.has(snapped)) {\n changed = true;\n }\n }\n return changed ? result : prevSet;\n}\n/**\n * Built-in handlers for plain structural types. Matched by exact prototype\n * only — subclasses of `Object` / `Array` / `Map` / `Set` are NOT routed\n * through these handlers (they fall through and, if no custom ancestor is\n * registered, are returned as-is). We use a Map here rather than installing\n * a symbol property on the built-in prototypes, because mutating built-in\n * prototypes (even with a symbol key) changes their hidden class and\n * invalidates V8's fast-path inline caches for every plain object / array\n * in the program.\n */\nconst BUILTIN_PROTO_TO_SNAPSHOT = new Map([\n [Object.prototype, snapshotPlainObject],\n [Array.prototype, snapshotArray],\n [Map.prototype, snapshotMap],\n [Set.prototype, snapshotSet],\n [null, snapshotPlainObject],\n]);\n/**\n * Custom registrations are stored as a non-enumerable symbol property on the\n * class prototype. JS prototype lookup walks the chain natively, so subclass\n * inheritance and override-by-redefinition are free — no resolver, no cache,\n * no invalidation. The symbol is module-private (created with `Symbol()`,\n * not `Symbol.for()`), so it cannot collide with anything else and cannot\n * be addressed by user code.\n */\nconst SNAPSHOT_HANDLER = Symbol('signalium.snapshot.handler');\n/**\n * Register a custom snapshot function for instances of a class.\n * The function receives the current value, the previous snapshot (or undefined),\n * and the recursive `snapshot` function for snapshotting nested values.\n *\n * Subclasses inherit the handler automatically via prototype lookup, so\n * registering once on a base class applies to all descendants. A descendant\n * can override by registering its own handler.\n *\n * Return `prev` when nothing has changed to preserve reference stability.\n *\n * @example\n * ```ts\n * registerCustomSnapshot(MyEntity, (current, prev, snapshot) => {\n * const name = snapshot(current.name, prev?.name);\n * const age = current.age;\n * if (prev && name === prev.name && age === prev.age) return prev;\n * return { name, age };\n * });\n * ```\n */\nexport const registerCustomSnapshot = (ctor, snapshotFn) => {\n // Use defineProperty so the handler is non-enumerable (it shouldn't show up\n // in `Reflect.ownKeys` walks any more than necessary) and so re-registration\n // overwrites cleanly even if a subclass has shadowed it.\n Object.defineProperty(ctor.prototype, SNAPSHOT_HANDLER, {\n value: snapshotFn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n};\n/**\n * Recursively snapshot a value with structural sharing.\n *\n * - Plain objects and arrays are deep-cloned; unchanged subtrees keep the same reference.\n * - ReactivePromise instances are read (establishing deps) and flattened to a plain object.\n * - Class instances are returned as-is unless a custom handler is registered\n * for the class or any of its ancestors via `registerCustomSnapshot`.\n * - Primitives are returned directly.\n */\nexport function snapshot(currentValue, prevValue) {\n if (currentValue === null || typeof currentValue !== 'object') {\n return currentValue;\n }\n if (isReactivePromise(currentValue)) {\n return snapshotReactivePromise(currentValue, prevValue, snapshot);\n }\n // Custom registrations check first: native prototype lookup walks the chain\n // for us, so subclasses inherit their ancestor's handler with no extra work.\n const customHandler = currentValue[SNAPSHOT_HANDLER];\n if (customHandler !== undefined) {\n return customHandler(currentValue, prevValue, snapshot);\n }\n // Built-in handlers are looked up by exact prototype only.\n const builtIn = BUILTIN_PROTO_TO_SNAPSHOT.get(getProto(currentValue));\n if (builtIn !== undefined) {\n return builtIn(currentValue, prevValue, snapshot);\n }\n return currentValue;\n}\n"],"names":["createReactiveDefinition","getCurrentScope","getScopeOwner","createRelay","createTask","SignalScope","createReactiveSignal","isReactivePromise"],"mappings":";;AAIO,MAAM,yBAAyB,oBAAI,QAAO;AAC1C,SAAS,2BAA2B,IAAI,MAAM;AACjD,MAAI,WAAW,uBAAuB,IAAI,EAAE;AAC5C,MAAI,CAAC,UAAU;AACX,UAAM,MAAMA,SAAAA,yBAAyB,MAAM,IAAI,MAAM,MAAM,IAAI,MAAM,QAAQ,OAAO,MAAM,QAAmB;AAC7G,UAAM,WAAWC,SAAAA,gBAAe;AAChC,UAAM,aAAa,IAAI,SAAS;AAC5B,YAAM,QAAQA,SAAAA,gBAAgB,QAAQ;AACtC,YAAM,SAAS,MAAM,IAAI,KAAK,IAAI;AAClC,aAAO,OAAO;AAAA,IAClB;AACA,eAAW,CAAC,YAAY,GAAG;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AAA,EACtC,CAAC,MAAM,WAAW,aAAa;AAAA,EAC/B,CAAC,IAAI,WAAW,WAAW;AAAA,EAC3B,CAAC,IAAI,WAAW,WAAW;AAAA,EAC3B,CAAC,MAAM,mBAAmB;AAC9B,CAAC;AASD,MAAM,mBAAmB,uBAAO,4BAA4B;AAsBhD,MAAC,yBAAyB,CAAC,MAAM,eAAe;AAIxD,SAAO,eAAe,KAAK,WAAW,kBAAkB;AAAA,IACpD,OAAO;AAAA,IACP,UAAU;AAAA,IACV,cAAc;AAAA,IACd,YAAY;AAAA,EACpB,CAAK;AACL;AAUO,SAAS,SAAS,cAAc,WAAW;AAC9C,MAAI,iBAAiB,QAAQ,OAAO,iBAAiB,UAAU;AAC3D,WAAO;AAAA,EACX;AACA,MAAIC,SAAAA,kBAAkB,YAAY,GAAG;AACjC,WAAO,wBAAwB,cAAc,WAAW,QAAQ;AAAA,EACpE;AAGA,QAAM,gBAAgB,aAAa,gBAAgB;AACnD,MAAI,kBAAkB,QAAW;AAC7B,WAAO,cAAc,cAAc,WAAW,QAAQ;AAAA,EAC1D;AAEA,QAAM,UAAU,0BAA0B,IAAI,SAAS,YAAY,CAAC;AACpE,MAAI,YAAY,QAAW;AACvB,WAAO,QAAQ,cAAc,WAAW,QAAQ;AAAA,EACpD;AACA,SAAO;AACX;;;;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const snapshot = require("./snapshot-
|
|
3
|
+
const snapshot = require("./snapshot-DWwH7_9y.js");
|
|
4
4
|
const contexts = require("./contexts-CM3QLfV8.js");
|
|
5
5
|
function watchOnce(fn) {
|
|
6
6
|
const signal = snapshot.watcher(fn);
|
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import React__default, { createContext, useContext as useContext$1, useMemo, useRef, useEffect, useSyncExternalStore } from "react";
|
|
4
4
|
import { b as getCurrentConsumer, k as getGlobalScope, S as SignalScope, l as hashValue, u as unwatchSignal, w as watchSignal, m as schedulePull, s as setCurrentConsumer, j as isReactivePromise, n as isPromise, o as isThennable, c as createReactiveSignal, r as runSignal, d as setRequestScopeGetter, p as signal } from "../debug-BTLbgTPK.js";
|
|
5
5
|
import { i as isAsyncFunctionWithoutTransform, a as isGeneratorFunction, c as createServerAsyncComponentWrapper } from "../component-shared-CLSmdnGU.js";
|
|
6
|
-
import { g as getReactiveFnAndDefinition, r as reactiveSignal, s as snapshot } from "../snapshot-
|
|
6
|
+
import { g as getReactiveFnAndDefinition, r as reactiveSignal, s as snapshot } from "../snapshot-CkndI4Hh.js";
|
|
7
7
|
const ScopeContext = createContext(void 0);
|
|
8
8
|
function useScope() {
|
|
9
9
|
return useContext$1(ScopeContext);
|
|
@@ -80,10 +80,11 @@ function snapshotReactivePromise(current, prev, snap) {
|
|
|
80
80
|
const isResolved = current.isResolved;
|
|
81
81
|
const isReady = current.isReady;
|
|
82
82
|
const isSettled = current.isSettled;
|
|
83
|
-
|
|
83
|
+
const run = current.run;
|
|
84
|
+
if (prevObj && value === prevObj.value && error === prevObj.error && isPending === prevObj.isPending && isRejected === prevObj.isRejected && isResolved === prevObj.isResolved && isReady === prevObj.isReady && isSettled === prevObj.isSettled && run === prevObj.run) {
|
|
84
85
|
return prevObj;
|
|
85
86
|
}
|
|
86
|
-
return { value, error, isPending, isRejected, isResolved, isReady, isSettled };
|
|
87
|
+
return { value, error, isPending, isRejected, isResolved, isReady, isSettled, run };
|
|
87
88
|
}
|
|
88
89
|
function snapshotMap(current, prev, snap) {
|
|
89
90
|
const prevMap = prev instanceof Map ? prev : void 0;
|
|
@@ -155,4 +156,4 @@ export {
|
|
|
155
156
|
task as t,
|
|
156
157
|
watcher as w
|
|
157
158
|
};
|
|
158
|
-
//# sourceMappingURL=snapshot-
|
|
159
|
+
//# sourceMappingURL=snapshot-CkndI4Hh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-CkndI4Hh.js","sources":["../../../.tsc-out/internals/core-api.js","../../../.tsc-out/internals/utils/snapshot.js"],"sourcesContent":["import { getCurrentScope, getScopeOwner, SignalScope } from './contexts.js';\nimport { createReactiveDefinition, createReactiveSignal, } from './reactive.js';\nimport { createRelay, createTask } from './async.js';\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const DERIVED_DEFINITION_MAP = new WeakMap();\nexport function getReactiveFnAndDefinition(fn, opts) {\n let fnAndDef = DERIVED_DEFINITION_MAP.get(fn);\n if (!fnAndDef) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const defScope = getCurrentScope();\n const reactiveFn = (...args) => {\n const scope = getCurrentScope(defScope);\n const signal = scope.get(def, args);\n return signal.value;\n };\n fnAndDef = [reactiveFn, def];\n DERIVED_DEFINITION_MAP.set(fn, fnAndDef);\n }\n return fnAndDef;\n}\nexport function reactive(fn, opts) {\n return getReactiveFnAndDefinition(fn, opts)[0];\n}\nexport const reactiveMethod = (owner, fn, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const reactiveFn = (...args) => {\n return getScopeOwner(owner).get(def, args).value;\n };\n DERIVED_DEFINITION_MAP.set(reactiveFn, [reactiveFn, def]);\n return reactiveFn;\n};\nexport function relay(activate, opts) {\n const scope = getCurrentScope();\n return createRelay(activate, scope, opts);\n}\nexport const task = (fn, opts) => {\n const scope = getCurrentScope();\n return createTask(fn, scope, opts);\n};\nexport function watcher(fn, opts) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, undefined, opts?.tracer);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n}\n/**\n * Creates a reactive signal from a compute function. This is useful for when you\n * want to create a signal that does not receive parameters, but is still reactive.\n *\n * @param compute\n * @param opts\n * @returns\n */\nexport const reactiveSignal = (compute, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, compute, opts?.equals, false, undefined, undefined);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n};\n","import { isReactivePromise } from '../async.js';\nconst getProto = Object.getPrototypeOf;\nfunction snapshotArray(current, prev, snap) {\n const prevArr = Array.isArray(prev) ? prev : undefined;\n let changed = !prevArr || prevArr.length !== current.length;\n const result = new Array(current.length);\n for (let i = 0; i < current.length; i++) {\n result[i] = snap(current[i], prevArr?.[i]);\n if (!changed && result[i] !== prevArr[i]) {\n changed = true;\n }\n }\n return changed ? result : prevArr;\n}\nfunction snapshotPlainObject(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' && !Array.isArray(prev)\n ? prev\n : undefined;\n const keys = Object.keys(current);\n let changed = !prevObj || Object.keys(prevObj).length !== keys.length;\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n result[key] = snap(current[key], prevObj?.[key]);\n if (!changed && result[key] !== prevObj[key]) {\n changed = true;\n }\n }\n return changed ? result : prevObj;\n}\nfunction snapshotReactivePromise(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' ? prev : undefined;\n const value = snap(current.value, prevObj?.value);\n const error = current.error;\n const isPending = current.isPending;\n const isRejected = current.isRejected;\n const isResolved = current.isResolved;\n const isReady = current.isReady;\n const isSettled = current.isSettled;\n // `run` is set once in the task constructor and never mutated, so its identity\n // is stable for the lifetime of the underlying ReactivePromiseImpl. Carrying\n // it on the snapshot lets consumers (e.g. React components reading a task via\n // `useReactive`) invoke `result.run(...)` against the live task. For non-task\n // promises this is `undefined`; we still assign the slot so the resulting\n // object's hidden class is stable across task and non-task snapshots.\n const run = current.run;\n if (prevObj &&\n value === prevObj.value &&\n error === prevObj.error &&\n isPending === prevObj.isPending &&\n isRejected === prevObj.isRejected &&\n isResolved === prevObj.isResolved &&\n isReady === prevObj.isReady &&\n isSettled === prevObj.isSettled &&\n run === prevObj.run) {\n return prevObj;\n }\n return { value, error, isPending, isRejected, isResolved, isReady, isSettled, run };\n}\nfunction snapshotMap(current, prev, snap) {\n const prevMap = prev instanceof Map ? prev : undefined;\n let changed = !prevMap || prevMap.size !== current.size;\n const result = new Map();\n for (const [key, val] of current) {\n const snapped = snap(val, prevMap?.get(key));\n result.set(key, snapped);\n if (!changed && snapped !== prevMap.get(key)) {\n changed = true;\n }\n }\n return changed ? result : prevMap;\n}\nfunction snapshotSet(current, prev, _snap) {\n const prevSet = prev instanceof Set ? prev : undefined;\n let changed = !prevSet || prevSet.size !== current.size;\n const result = new Set();\n for (const val of current) {\n const snapped = snapshot(val, prevSet?.has(val) ? val : undefined);\n result.add(snapped);\n if (!changed && !prevSet.has(snapped)) {\n changed = true;\n }\n }\n return changed ? result : prevSet;\n}\n/**\n * Built-in handlers for plain structural types. Matched by exact prototype\n * only — subclasses of `Object` / `Array` / `Map` / `Set` are NOT routed\n * through these handlers (they fall through and, if no custom ancestor is\n * registered, are returned as-is). We use a Map here rather than installing\n * a symbol property on the built-in prototypes, because mutating built-in\n * prototypes (even with a symbol key) changes their hidden class and\n * invalidates V8's fast-path inline caches for every plain object / array\n * in the program.\n */\nconst BUILTIN_PROTO_TO_SNAPSHOT = new Map([\n [Object.prototype, snapshotPlainObject],\n [Array.prototype, snapshotArray],\n [Map.prototype, snapshotMap],\n [Set.prototype, snapshotSet],\n [null, snapshotPlainObject],\n]);\n/**\n * Custom registrations are stored as a non-enumerable symbol property on the\n * class prototype. JS prototype lookup walks the chain natively, so subclass\n * inheritance and override-by-redefinition are free — no resolver, no cache,\n * no invalidation. The symbol is module-private (created with `Symbol()`,\n * not `Symbol.for()`), so it cannot collide with anything else and cannot\n * be addressed by user code.\n */\nconst SNAPSHOT_HANDLER = Symbol('signalium.snapshot.handler');\n/**\n * Register a custom snapshot function for instances of a class.\n * The function receives the current value, the previous snapshot (or undefined),\n * and the recursive `snapshot` function for snapshotting nested values.\n *\n * Subclasses inherit the handler automatically via prototype lookup, so\n * registering once on a base class applies to all descendants. A descendant\n * can override by registering its own handler.\n *\n * Return `prev` when nothing has changed to preserve reference stability.\n *\n * @example\n * ```ts\n * registerCustomSnapshot(MyEntity, (current, prev, snapshot) => {\n * const name = snapshot(current.name, prev?.name);\n * const age = current.age;\n * if (prev && name === prev.name && age === prev.age) return prev;\n * return { name, age };\n * });\n * ```\n */\nexport const registerCustomSnapshot = (ctor, snapshotFn) => {\n // Use defineProperty so the handler is non-enumerable (it shouldn't show up\n // in `Reflect.ownKeys` walks any more than necessary) and so re-registration\n // overwrites cleanly even if a subclass has shadowed it.\n Object.defineProperty(ctor.prototype, SNAPSHOT_HANDLER, {\n value: snapshotFn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n};\n/**\n * Recursively snapshot a value with structural sharing.\n *\n * - Plain objects and arrays are deep-cloned; unchanged subtrees keep the same reference.\n * - ReactivePromise instances are read (establishing deps) and flattened to a plain object.\n * - Class instances are returned as-is unless a custom handler is registered\n * for the class or any of its ancestors via `registerCustomSnapshot`.\n * - Primitives are returned directly.\n */\nexport function snapshot(currentValue, prevValue) {\n if (currentValue === null || typeof currentValue !== 'object') {\n return currentValue;\n }\n if (isReactivePromise(currentValue)) {\n return snapshotReactivePromise(currentValue, prevValue, snapshot);\n }\n // Custom registrations check first: native prototype lookup walks the chain\n // for us, so subclasses inherit their ancestor's handler with no extra work.\n const customHandler = currentValue[SNAPSHOT_HANDLER];\n if (customHandler !== undefined) {\n return customHandler(currentValue, prevValue, snapshot);\n }\n // Built-in handlers are looked up by exact prototype only.\n const builtIn = BUILTIN_PROTO_TO_SNAPSHOT.get(getProto(currentValue));\n if (builtIn !== undefined) {\n return builtIn(currentValue, prevValue, snapshot);\n }\n return currentValue;\n}\n"],"names":[],"mappings":";AAIO,MAAM,yBAAyB,oBAAI,QAAO;AAC1C,SAAS,2BAA2B,IAAI,MAAM;AACjD,MAAI,WAAW,uBAAuB,IAAI,EAAE;AAC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MAAS;AACjE,WAAO,IAAI,OAAO;AAClB,QAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,OAAO,GAAG;AACnC,gBAAU;AAAA,IACd;AAAA,EACJ;AACA,SAAO,UAAU,SAAS;AAC9B;AAWA,MAAM,4BAA4B,oBAAI,IAAI;AAAA,EACtC,CAAC,OAAO,WAAW,mBAAmB;AAAA,EACtC,CAAC,MAAM,WAAW,aAAa;AAAA,EAC/B,CAAC,IAAI,WAAW,WAAW;AAAA,EAC3B,CAAC,IAAI,WAAW,WAAW;AAAA,EAC3B,CAAC,MAAM,mBAAmB;AAC9B,CAAC;AASD,MAAM,mBAAmB,uBAAO,4BAA4B;AAsBhD,MAAC,yBAAyB,CAAC,MAAM,eAAe;AAIxD,SAAO,eAAe,KAAK,WAAW,kBAAkB;AAAA,IACpD,OAAO;AAAA,IACP,UAAU;AAAA,IACV,cAAc;AAAA,IACd,YAAY;AAAA,EACpB,CAAK;AACL;AAUO,SAAS,SAAS,cAAc,WAAW;AAC9C,MAAI,iBAAiB,QAAQ,OAAO,iBAAiB,UAAU;AAC3D,WAAO;AAAA,EACX;AACA,MAAI,kBAAkB,YAAY,GAAG;AACjC,WAAO,wBAAwB,cAAc,WAAW,QAAQ;AAAA,EACpE;AAGA,QAAM,gBAAgB,aAAa,gBAAgB;AACnD,MAAI,kBAAkB,QAAW;AAC7B,WAAO,cAAc,cAAc,WAAW,QAAQ;AAAA,EAC1D;AAEA,QAAM,UAAU,0BAA0B,IAAI,SAAS,YAAY,CAAC;AACpE,MAAI,YAAY,QAAW;AACvB,WAAO,QAAQ,cAAc,WAAW,QAAQ;AAAA,EACpD;AACA,SAAO;AACX;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { w as watcher } from "./snapshot-
|
|
2
|
-
import { a, s } from "./snapshot-
|
|
1
|
+
import { w as watcher } from "./snapshot-CkndI4Hh.js";
|
|
2
|
+
import { a, s } from "./snapshot-CkndI4Hh.js";
|
|
3
3
|
import { w as watchSignal, q as getSignal, j as isReactivePromise, n as isPromise, u as unwatchSignal } from "./debug-BTLbgTPK.js";
|
|
4
4
|
import { l, t, v } from "./debug-BTLbgTPK.js";
|
|
5
5
|
function watchOnce(fn) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../../src/internals/utils/snapshot.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../../src/internals/utils/snapshot.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;AAkJtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,MAAM,QAC/C,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,cACnB,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,EAAE,QAAQ,EAAE,UAAU,KAAK,CAAC,KACvE,IAUF,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAuB3E"}
|
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import React__default, { createContext, useContext as useContext$1, useMemo, useRef, useEffect, useSyncExternalStore } from "react";
|
|
4
4
|
import { d as getCurrentConsumer, l as getGlobalScope, S as SignalScope, m as hashValue, u as unwatchSignal, w as watchSignal, n as schedulePull, b as setCurrentConsumer, k as isReactivePromise, o as isPromise, p as isThennable, c as createReactiveSignal, r as runSignal, e as setRequestScopeGetter, q as signal } from "../contexts-FxCndlvf.js";
|
|
5
5
|
import { i as isAsyncFunctionWithoutTransform, a as isGeneratorFunction, c as createServerAsyncComponentWrapper } from "../component-shared-Dva0S5e3.js";
|
|
6
|
-
import { g as getReactiveFnAndDefinition, r as reactiveSignal, s as snapshot } from "../snapshot-
|
|
6
|
+
import { g as getReactiveFnAndDefinition, r as reactiveSignal, s as snapshot } from "../snapshot-CdCaJJ0L.js";
|
|
7
7
|
const ScopeContext = createContext(void 0);
|
|
8
8
|
function useScope() {
|
|
9
9
|
return useContext$1(ScopeContext);
|
|
@@ -80,10 +80,11 @@ function snapshotReactivePromise(current, prev, snap) {
|
|
|
80
80
|
const isResolved = current.isResolved;
|
|
81
81
|
const isReady = current.isReady;
|
|
82
82
|
const isSettled = current.isSettled;
|
|
83
|
-
|
|
83
|
+
const run = current.run;
|
|
84
|
+
if (prevObj && value === prevObj.value && error === prevObj.error && isPending === prevObj.isPending && isRejected === prevObj.isRejected && isResolved === prevObj.isResolved && isReady === prevObj.isReady && isSettled === prevObj.isSettled && run === prevObj.run) {
|
|
84
85
|
return prevObj;
|
|
85
86
|
}
|
|
86
|
-
return { value, error, isPending, isRejected, isResolved, isReady, isSettled };
|
|
87
|
+
return { value, error, isPending, isRejected, isResolved, isReady, isSettled, run };
|
|
87
88
|
}
|
|
88
89
|
function snapshotMap(current, prev, snap) {
|
|
89
90
|
const prevMap = prev instanceof Map ? prev : void 0;
|
|
@@ -155,4 +156,4 @@ export {
|
|
|
155
156
|
task as t,
|
|
156
157
|
watcher as w
|
|
157
158
|
};
|
|
158
|
-
//# sourceMappingURL=snapshot-
|
|
159
|
+
//# sourceMappingURL=snapshot-CdCaJJ0L.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-CdCaJJ0L.js","sources":["../../../.tsc-out/internals/core-api.js","../../../.tsc-out/internals/utils/snapshot.js"],"sourcesContent":["import { getCurrentScope, getScopeOwner, SignalScope } from './contexts.js';\nimport { createReactiveDefinition, createReactiveSignal, } from './reactive.js';\nimport { createRelay, createTask } from './async.js';\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const DERIVED_DEFINITION_MAP = new WeakMap();\nexport function getReactiveFnAndDefinition(fn, opts) {\n let fnAndDef = DERIVED_DEFINITION_MAP.get(fn);\n if (!fnAndDef) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const defScope = getCurrentScope();\n const reactiveFn = (...args) => {\n const scope = getCurrentScope(defScope);\n const signal = scope.get(def, args);\n return signal.value;\n };\n fnAndDef = [reactiveFn, def];\n DERIVED_DEFINITION_MAP.set(fn, fnAndDef);\n }\n return fnAndDef;\n}\nexport function reactive(fn, opts) {\n return getReactiveFnAndDefinition(fn, opts)[0];\n}\nexport const reactiveMethod = (owner, fn, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const reactiveFn = (...args) => {\n return getScopeOwner(owner).get(def, args).value;\n };\n DERIVED_DEFINITION_MAP.set(reactiveFn, [reactiveFn, def]);\n return reactiveFn;\n};\nexport function relay(activate, opts) {\n const scope = getCurrentScope();\n return createRelay(activate, scope, opts);\n}\nexport const task = (fn, opts) => {\n const scope = getCurrentScope();\n return createTask(fn, scope, opts);\n};\nexport function watcher(fn, opts) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, undefined, opts?.tracer);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n}\n/**\n * Creates a reactive signal from a compute function. This is useful for when you\n * want to create a signal that does not receive parameters, but is still reactive.\n *\n * @param compute\n * @param opts\n * @returns\n */\nexport const reactiveSignal = (compute, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, compute, opts?.equals, false, undefined, undefined);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n};\n","import { isReactivePromise } from '../async.js';\nconst getProto = Object.getPrototypeOf;\nfunction snapshotArray(current, prev, snap) {\n const prevArr = Array.isArray(prev) ? prev : undefined;\n let changed = !prevArr || prevArr.length !== current.length;\n const result = new Array(current.length);\n for (let i = 0; i < current.length; i++) {\n result[i] = snap(current[i], prevArr?.[i]);\n if (!changed && result[i] !== prevArr[i]) {\n changed = true;\n }\n }\n return changed ? result : prevArr;\n}\nfunction snapshotPlainObject(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' && !Array.isArray(prev)\n ? prev\n : undefined;\n const keys = Object.keys(current);\n let changed = !prevObj || Object.keys(prevObj).length !== keys.length;\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n result[key] = snap(current[key], prevObj?.[key]);\n if (!changed && result[key] !== prevObj[key]) {\n changed = true;\n }\n }\n return changed ? result : prevObj;\n}\nfunction snapshotReactivePromise(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' ? prev : undefined;\n const value = snap(current.value, prevObj?.value);\n const error = current.error;\n const isPending = current.isPending;\n const isRejected = current.isRejected;\n const isResolved = current.isResolved;\n const isReady = current.isReady;\n const isSettled = current.isSettled;\n // `run` is set once in the task constructor and never mutated, so its identity\n // is stable for the lifetime of the underlying ReactivePromiseImpl. Carrying\n // it on the snapshot lets consumers (e.g. React components reading a task via\n // `useReactive`) invoke `result.run(...)` against the live task. For non-task\n // promises this is `undefined`; we still assign the slot so the resulting\n // object's hidden class is stable across task and non-task snapshots.\n const run = current.run;\n if (prevObj &&\n value === prevObj.value &&\n error === prevObj.error &&\n isPending === prevObj.isPending &&\n isRejected === prevObj.isRejected &&\n isResolved === prevObj.isResolved &&\n isReady === prevObj.isReady &&\n isSettled === prevObj.isSettled &&\n run === prevObj.run) {\n return prevObj;\n }\n return { value, error, isPending, isRejected, isResolved, isReady, isSettled, run };\n}\nfunction snapshotMap(current, prev, snap) {\n const prevMap = prev instanceof Map ? prev : undefined;\n let changed = !prevMap || prevMap.size !== current.size;\n const result = new Map();\n for (const [key, val] of current) {\n const snapped = snap(val, prevMap?.get(key));\n result.set(key, snapped);\n if (!changed && snapped !== prevMap.get(key)) {\n changed = true;\n }\n }\n return changed ? result : prevMap;\n}\nfunction snapshotSet(current, prev, _snap) {\n const prevSet = prev instanceof Set ? prev : undefined;\n let changed = !prevSet || prevSet.size !== current.size;\n const result = new Set();\n for (const val of current) {\n const snapped = snapshot(val, prevSet?.has(val) ? val : undefined);\n result.add(snapped);\n if (!changed && !prevSet.has(snapped)) {\n changed = true;\n }\n }\n return changed ? result : prevSet;\n}\n/**\n * Built-in handlers for plain structural types. Matched by exact prototype\n * only — subclasses of `Object` / `Array` / `Map` / `Set` are NOT routed\n * through these handlers (they fall through and, if no custom ancestor is\n * registered, are returned as-is). We use a Map here rather than installing\n * a symbol property on the built-in prototypes, because mutating built-in\n * prototypes (even with a symbol key) changes their hidden class and\n * invalidates V8's fast-path inline caches for every plain object / array\n * in the program.\n */\nconst BUILTIN_PROTO_TO_SNAPSHOT = new Map([\n [Object.prototype, snapshotPlainObject],\n [Array.prototype, snapshotArray],\n [Map.prototype, snapshotMap],\n [Set.prototype, snapshotSet],\n [null, snapshotPlainObject],\n]);\n/**\n * Custom registrations are stored as a non-enumerable symbol property on the\n * class prototype. JS prototype lookup walks the chain natively, so subclass\n * inheritance and override-by-redefinition are free — no resolver, no cache,\n * no invalidation. The symbol is module-private (created with `Symbol()`,\n * not `Symbol.for()`), so it cannot collide with anything else and cannot\n * be addressed by user code.\n */\nconst SNAPSHOT_HANDLER = Symbol('signalium.snapshot.handler');\n/**\n * Register a custom snapshot function for instances of a class.\n * The function receives the current value, the previous snapshot (or undefined),\n * and the recursive `snapshot` function for snapshotting nested values.\n *\n * Subclasses inherit the handler automatically via prototype lookup, so\n * registering once on a base class applies to all descendants. A descendant\n * can override by registering its own handler.\n *\n * Return `prev` when nothing has changed to preserve reference stability.\n *\n * @example\n * ```ts\n * registerCustomSnapshot(MyEntity, (current, prev, snapshot) => {\n * const name = snapshot(current.name, prev?.name);\n * const age = current.age;\n * if (prev && name === prev.name && age === prev.age) return prev;\n * return { name, age };\n * });\n * ```\n */\nexport const registerCustomSnapshot = (ctor, snapshotFn) => {\n // Use defineProperty so the handler is non-enumerable (it shouldn't show up\n // in `Reflect.ownKeys` walks any more than necessary) and so re-registration\n // overwrites cleanly even if a subclass has shadowed it.\n Object.defineProperty(ctor.prototype, SNAPSHOT_HANDLER, {\n value: snapshotFn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n};\n/**\n * Recursively snapshot a value with structural sharing.\n *\n * - Plain objects and arrays are deep-cloned; unchanged subtrees keep the same reference.\n * - ReactivePromise instances are read (establishing deps) and flattened to a plain object.\n * - Class instances are returned as-is unless a custom handler is registered\n * for the class or any of its ancestors via `registerCustomSnapshot`.\n * - Primitives are returned directly.\n */\nexport function snapshot(currentValue, prevValue) {\n if (currentValue === null || typeof currentValue !== 'object') {\n return currentValue;\n }\n if (isReactivePromise(currentValue)) {\n return snapshotReactivePromise(currentValue, prevValue, snapshot);\n }\n // Custom registrations check first: native prototype lookup walks the chain\n // for us, so subclasses inherit their ancestor's handler with no extra work.\n const customHandler = currentValue[SNAPSHOT_HANDLER];\n if (customHandler !== undefined) {\n return customHandler(currentValue, prevValue, snapshot);\n }\n // Built-in handlers are looked up by exact prototype only.\n const builtIn = BUILTIN_PROTO_TO_SNAPSHOT.get(getProto(currentValue));\n if (builtIn !== undefined) {\n return builtIn(currentValue, prevValue, snapshot);\n }\n return currentValue;\n}\n"],"names":[],"mappings":";AAIO,MAAM,yBAAyB,oBAAI,QAAO;AAC1C,SAAS,2BAA2B,IAAI,MAAM;AACjD,MAAI,WAAW,uBAAuB,IAAI,EAAE;AAC5C,MAAI,CAAC,UAAU;AACX,UAAM,MAAM,yBAAyB,MAAM,IAAI,MAAM,MAAM,IAAI,MAAM,QAAQ,OAAO,MAAM,QAAmB;AAC7G,UAAM,WAAW,gBAAe;AAChC,UAAM,aAAa,IAAI,SAAS;AAC5B,YAAM,QAAQ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AC,OAAO,WAAW,mBAAmB;AAAA,EACtC,CAAC,MAAM,WAAW,aAAa;AAAA,EAC/B,CAAC,IAAI,WAAW,WAAW;AAAA,EAC3B,CAAC,IAAI,WAAW,WAAW;AAAA,EAC3B,CAAC,MAAM,mBAAmB;AAC9B,CAAC;AASD,MAAM,mBAAmB,uBAAO,4BAA4B;AAsBhD,MAAC,yBAAyB,CAAC,MAAM,eAAe;AAIxD,SAAO,eAAe,KAAK,WAAW,kBAAkB;AAAA,IACpD,OAAO;AAAA,IACP,UAAU;AAAA,IACV,cAAc;AAAA,IACd,YAAY;AAAA,EACpB,CAAK;AACL;AAUO,SAAS,SAAS,cAAc,WAAW;AAC9C,MAAI,iBAAiB,QAAQ,OAAO,iBAAiB,UAAU;AAC3D,WAAO;AAAA,EACX;AACA,MAAI,kBAAkB,YAAY,GAAG;AACjC,WAAO,wBAAwB,cAAc,WAAW,QAAQ;AAAA,EACpE;AAGA,QAAM,gBAAgB,aAAa,gBAAgB;AACnD,MAAI,kBAAkB,QAAW;AAC7B,WAAO,cAAc,cAAc,WAAW,QAAQ;AAAA,EAC1D;AAEA,QAAM,UAAU,0BAA0B,IAAI,SAAS,YAAY,CAAC;AACpE,MAAI,YAAY,QAAW;AACvB,WAAO,QAAQ,cAAc,WAAW,QAAQ;AAAA,EACpD;AACA,SAAO;AACX;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { w as watcher } from "./snapshot-
|
|
2
|
-
import { a, s } from "./snapshot-
|
|
1
|
+
import { w as watcher } from "./snapshot-CdCaJJ0L.js";
|
|
2
|
+
import { a, s } from "./snapshot-CdCaJJ0L.js";
|
|
3
3
|
import { w as watchSignal, t as getSignal, k as isReactivePromise, o as isPromise, u as unwatchSignal } from "./contexts-FxCndlvf.js";
|
|
4
4
|
import { m, v, x } from "./contexts-FxCndlvf.js";
|
|
5
5
|
function watchOnce(fn) {
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-BfP4w3lC.js","sources":["../../../.tsc-out/internals/core-api.js","../../../.tsc-out/internals/utils/snapshot.js"],"sourcesContent":["import { getCurrentScope, getScopeOwner, SignalScope } from './contexts.js';\nimport { createReactiveDefinition, createReactiveSignal, } from './reactive.js';\nimport { createRelay, createTask } from './async.js';\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const DERIVED_DEFINITION_MAP = new WeakMap();\nexport function getReactiveFnAndDefinition(fn, opts) {\n let fnAndDef = DERIVED_DEFINITION_MAP.get(fn);\n if (!fnAndDef) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const defScope = getCurrentScope();\n const reactiveFn = (...args) => {\n const scope = getCurrentScope(defScope);\n const signal = scope.get(def, args);\n return signal.value;\n };\n fnAndDef = [reactiveFn, def];\n DERIVED_DEFINITION_MAP.set(fn, fnAndDef);\n }\n return fnAndDef;\n}\nexport function reactive(fn, opts) {\n return getReactiveFnAndDefinition(fn, opts)[0];\n}\nexport const reactiveMethod = (owner, fn, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const reactiveFn = (...args) => {\n return getScopeOwner(owner).get(def, args).value;\n };\n DERIVED_DEFINITION_MAP.set(reactiveFn, [reactiveFn, def]);\n return reactiveFn;\n};\nexport function relay(activate, opts) {\n const scope = getCurrentScope();\n return createRelay(activate, scope, opts);\n}\nexport const task = (fn, opts) => {\n const scope = getCurrentScope();\n return createTask(fn, scope, opts);\n};\nexport function watcher(fn, opts) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, undefined, opts?.tracer);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n}\n/**\n * Creates a reactive signal from a compute function. This is useful for when you\n * want to create a signal that does not receive parameters, but is still reactive.\n *\n * @param compute\n * @param opts\n * @returns\n */\nexport const reactiveSignal = (compute, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, compute, opts?.equals, false, undefined, undefined);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n};\n","import { isReactivePromise } from '../async.js';\nconst getProto = Object.getPrototypeOf;\nfunction snapshotArray(current, prev, snap) {\n const prevArr = Array.isArray(prev) ? prev : undefined;\n let changed = !prevArr || prevArr.length !== current.length;\n const result = new Array(current.length);\n for (let i = 0; i < current.length; i++) {\n result[i] = snap(current[i], prevArr?.[i]);\n if (!changed && result[i] !== prevArr[i]) {\n changed = true;\n }\n }\n return changed ? result : prevArr;\n}\nfunction snapshotPlainObject(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' && !Array.isArray(prev)\n ? prev\n : undefined;\n const keys = Object.keys(current);\n let changed = !prevObj || Object.keys(prevObj).length !== keys.length;\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n result[key] = snap(current[key], prevObj?.[key]);\n if (!changed && result[key] !== prevObj[key]) {\n changed = true;\n }\n }\n return changed ? result : prevObj;\n}\nfunction snapshotReactivePromise(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' ? prev : undefined;\n const value = snap(current.value, prevObj?.value);\n const error = current.error;\n const isPending = current.isPending;\n const isRejected = current.isRejected;\n const isResolved = current.isResolved;\n const isReady = current.isReady;\n const isSettled = current.isSettled;\n if (prevObj &&\n value === prevObj.value &&\n error === prevObj.error &&\n isPending === prevObj.isPending &&\n isRejected === prevObj.isRejected &&\n isResolved === prevObj.isResolved &&\n isReady === prevObj.isReady &&\n isSettled === prevObj.isSettled) {\n return prevObj;\n }\n return { value, error, isPending, isRejected, isResolved, isReady, isSettled };\n}\nfunction snapshotMap(current, prev, snap) {\n const prevMap = prev instanceof Map ? prev : undefined;\n let changed = !prevMap || prevMap.size !== current.size;\n const result = new Map();\n for (const [key, val] of current) {\n const snapped = snap(val, prevMap?.get(key));\n result.set(key, snapped);\n if (!changed && snapped !== prevMap.get(key)) {\n changed = true;\n }\n }\n return changed ? result : prevMap;\n}\nfunction snapshotSet(current, prev, _snap) {\n const prevSet = prev instanceof Set ? prev : undefined;\n let changed = !prevSet || prevSet.size !== current.size;\n const result = new Set();\n for (const val of current) {\n const snapped = snapshot(val, prevSet?.has(val) ? val : undefined);\n result.add(snapped);\n if (!changed && !prevSet.has(snapped)) {\n changed = true;\n }\n }\n return changed ? result : prevSet;\n}\n/**\n * Built-in handlers for plain structural types. Matched by exact prototype\n * only — subclasses of `Object` / `Array` / `Map` / `Set` are NOT routed\n * through these handlers (they fall through and, if no custom ancestor is\n * registered, are returned as-is). We use a Map here rather than installing\n * a symbol property on the built-in prototypes, because mutating built-in\n * prototypes (even with a symbol key) changes their hidden class and\n * invalidates V8's fast-path inline caches for every plain object / array\n * in the program.\n */\nconst BUILTIN_PROTO_TO_SNAPSHOT = new Map([\n [Object.prototype, snapshotPlainObject],\n [Array.prototype, snapshotArray],\n [Map.prototype, snapshotMap],\n [Set.prototype, snapshotSet],\n [null, snapshotPlainObject],\n]);\n/**\n * Custom registrations are stored as a non-enumerable symbol property on the\n * class prototype. JS prototype lookup walks the chain natively, so subclass\n * inheritance and override-by-redefinition are free — no resolver, no cache,\n * no invalidation. The symbol is module-private (created with `Symbol()`,\n * not `Symbol.for()`), so it cannot collide with anything else and cannot\n * be addressed by user code.\n */\nconst SNAPSHOT_HANDLER = Symbol('signalium.snapshot.handler');\n/**\n * Register a custom snapshot function for instances of a class.\n * The function receives the current value, the previous snapshot (or undefined),\n * and the recursive `snapshot` function for snapshotting nested values.\n *\n * Subclasses inherit the handler automatically via prototype lookup, so\n * registering once on a base class applies to all descendants. A descendant\n * can override by registering its own handler.\n *\n * Return `prev` when nothing has changed to preserve reference stability.\n *\n * @example\n * ```ts\n * registerCustomSnapshot(MyEntity, (current, prev, snapshot) => {\n * const name = snapshot(current.name, prev?.name);\n * const age = current.age;\n * if (prev && name === prev.name && age === prev.age) return prev;\n * return { name, age };\n * });\n * ```\n */\nexport const registerCustomSnapshot = (ctor, snapshotFn) => {\n // Use defineProperty so the handler is non-enumerable (it shouldn't show up\n // in `Reflect.ownKeys` walks any more than necessary) and so re-registration\n // overwrites cleanly even if a subclass has shadowed it.\n Object.defineProperty(ctor.prototype, SNAPSHOT_HANDLER, {\n value: snapshotFn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n};\n/**\n * Recursively snapshot a value with structural sharing.\n *\n * - Plain objects and arrays are deep-cloned; unchanged subtrees keep the same reference.\n * - ReactivePromise instances are read (establishing deps) and flattened to a plain object.\n * - Class instances are returned as-is unless a custom handler is registered\n * for the class or any of its ancestors via `registerCustomSnapshot`.\n * - Primitives are returned directly.\n */\nexport function snapshot(currentValue, prevValue) {\n if (currentValue === null || typeof currentValue !== 'object') {\n return currentValue;\n }\n if (isReactivePromise(currentValue)) {\n return snapshotReactivePromise(currentValue, prevValue, snapshot);\n }\n // Custom registrations check first: native prototype lookup walks the chain\n // for us, so subclasses inherit their ancestor's handler with no extra work.\n const customHandler = currentValue[SNAPSHOT_HANDLER];\n if (customHandler !== undefined) {\n return customHandler(currentValue, prevValue, snapshot);\n }\n // Built-in handlers are looked up by exact prototype only.\n const builtIn = BUILTIN_PROTO_TO_SNAPSHOT.get(getProto(currentValue));\n if (builtIn !== undefined) {\n return builtIn(currentValue, prevValue, snapshot);\n }\n return currentValue;\n}\n"],"names":["createReactiveDefinition","getCurrentScope","getScopeOwner","createRelay","createTask","SignalScope","createReactiveSignal","isReactivePromise"],"mappings":";;AAIO,MAAM,yBAAyB,oBAAI,QAAO;AAC1C,SAAS,2BAA2B,IAAI,MAAM;AACjD,MAAI,WAAW,uBAAuB,IAAI,EAAE;AAC5C,MAAI,CAAC,UAAU;AACX,UAAM,MAAMA,MAAAA,yBAAyB,MAAM,IAAI,MAAM,MAAM,IAAI,MAAM,QAAQ,OAAO,MAAM,UAAU,MAAS;AAC7G,UAAM,WAAWC,MAAAA,gBAAe;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BAAU;AAAA,IACd;AAAA,EACJ;AACA,SAAO,UAAU,SAAS;AAC9B;AAWA,MAAM,4BAA4B,oBAAI,IAAI;AAAA,EACtC,CAAC,OAAO,WAAW,mBAAmB;AAAA,EACtC,CAAC,MAAM,WAAW,aAAa;AAAA,EAC/B,CAAC,IAAI,WAAW,WAAW;AAAA,EAC3B,CAAC,IAAI,WAAW,WAAW;AAAA,EAC3B,CAAC,MAAM,mBAAmB;AAC9B,CAAC;AASD,MAAM,mBAAmB,uBAAO,4BAA4B;AAsBhD,MAAC,yBAAyB,CAAC,MAAM,eAAe;AAIxD,SAAO,eAAe,KAAK,WAAW,kBAAkB;AAAA,IACpD,OAAO;AAAA,IACP,UAAU;AAAA,IACV,cAAc;AAAA,IACd,YAAY;AAAA,EACpB,CAAK;AACL;AAUO,SAAS,SAAS,cAAc,WAAW;AAC9C,MAAI,iBAAiB,QAAQ,OAAO,iBAAiB,UAAU;AAC3D,WAAO;AAAA,EACX;AACA,MAAIC,MAAAA,kBAAkB,YAAY,GAAG;AACjC,WAAO,wBAAwB,cAAc,WAAW,QAAQ;AAAA,EACpE;AAGA,QAAM,gBAAgB,aAAa,gBAAgB;AACnD,MAAI,kBAAkB,QAAW;AAC7B,WAAO,cAAc,cAAc,WAAW,QAAQ;AAAA,EAC1D;AAEA,QAAM,UAAU,0BAA0B,IAAI,SAAS,YAAY,CAAC;AACpE,MAAI,YAAY,QAAW;AACvB,WAAO,QAAQ,cAAc,WAAW,QAAQ;AAAA,EACpD;AACA,SAAO;AACX;;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-DnzyLNij.js","sources":["../../../.tsc-out/internals/core-api.js","../../../.tsc-out/internals/utils/snapshot.js"],"sourcesContent":["import { getCurrentScope, getScopeOwner, SignalScope } from './contexts.js';\nimport { createReactiveDefinition, createReactiveSignal, } from './reactive.js';\nimport { createRelay, createTask } from './async.js';\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const DERIVED_DEFINITION_MAP = new WeakMap();\nexport function getReactiveFnAndDefinition(fn, opts) {\n let fnAndDef = DERIVED_DEFINITION_MAP.get(fn);\n if (!fnAndDef) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const defScope = getCurrentScope();\n const reactiveFn = (...args) => {\n const scope = getCurrentScope(defScope);\n const signal = scope.get(def, args);\n return signal.value;\n };\n fnAndDef = [reactiveFn, def];\n DERIVED_DEFINITION_MAP.set(fn, fnAndDef);\n }\n return fnAndDef;\n}\nexport function reactive(fn, opts) {\n return getReactiveFnAndDefinition(fn, opts)[0];\n}\nexport const reactiveMethod = (owner, fn, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const reactiveFn = (...args) => {\n return getScopeOwner(owner).get(def, args).value;\n };\n DERIVED_DEFINITION_MAP.set(reactiveFn, [reactiveFn, def]);\n return reactiveFn;\n};\nexport function relay(activate, opts) {\n const scope = getCurrentScope();\n return createRelay(activate, scope, opts);\n}\nexport const task = (fn, opts) => {\n const scope = getCurrentScope();\n return createTask(fn, scope, opts);\n};\nexport function watcher(fn, opts) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, undefined, opts?.tracer);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n}\n/**\n * Creates a reactive signal from a compute function. This is useful for when you\n * want to create a signal that does not receive parameters, but is still reactive.\n *\n * @param compute\n * @param opts\n * @returns\n */\nexport const reactiveSignal = (compute, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, compute, opts?.equals, false, undefined, undefined);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n};\n","import { isReactivePromise } from '../async.js';\nconst getProto = Object.getPrototypeOf;\nfunction snapshotArray(current, prev, snap) {\n const prevArr = Array.isArray(prev) ? prev : undefined;\n let changed = !prevArr || prevArr.length !== current.length;\n const result = new Array(current.length);\n for (let i = 0; i < current.length; i++) {\n result[i] = snap(current[i], prevArr?.[i]);\n if (!changed && result[i] !== prevArr[i]) {\n changed = true;\n }\n }\n return changed ? result : prevArr;\n}\nfunction snapshotPlainObject(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' && !Array.isArray(prev)\n ? prev\n : undefined;\n const keys = Object.keys(current);\n let changed = !prevObj || Object.keys(prevObj).length !== keys.length;\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n result[key] = snap(current[key], prevObj?.[key]);\n if (!changed && result[key] !== prevObj[key]) {\n changed = true;\n }\n }\n return changed ? result : prevObj;\n}\nfunction snapshotReactivePromise(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' ? prev : undefined;\n const value = snap(current.value, prevObj?.value);\n const error = current.error;\n const isPending = current.isPending;\n const isRejected = current.isRejected;\n const isResolved = current.isResolved;\n const isReady = current.isReady;\n const isSettled = current.isSettled;\n if (prevObj &&\n value === prevObj.value &&\n error === prevObj.error &&\n isPending === prevObj.isPending &&\n isRejected === prevObj.isRejected &&\n isResolved === prevObj.isResolved &&\n isReady === prevObj.isReady &&\n isSettled === prevObj.isSettled) {\n return prevObj;\n }\n return { value, error, isPending, isRejected, isResolved, isReady, isSettled };\n}\nfunction snapshotMap(current, prev, snap) {\n const prevMap = prev instanceof Map ? prev : undefined;\n let changed = !prevMap || prevMap.size !== current.size;\n const result = new Map();\n for (const [key, val] of current) {\n const snapped = snap(val, prevMap?.get(key));\n result.set(key, snapped);\n if (!changed && snapped !== prevMap.get(key)) {\n changed = true;\n }\n }\n return changed ? result : prevMap;\n}\nfunction snapshotSet(current, prev, _snap) {\n const prevSet = prev instanceof Set ? prev : undefined;\n let changed = !prevSet || prevSet.size !== current.size;\n const result = new Set();\n for (const val of current) {\n const snapped = snapshot(val, prevSet?.has(val) ? val : undefined);\n result.add(snapped);\n if (!changed && !prevSet.has(snapped)) {\n changed = true;\n }\n }\n return changed ? result : prevSet;\n}\n/**\n * Built-in handlers for plain structural types. Matched by exact prototype\n * only — subclasses of `Object` / `Array` / `Map` / `Set` are NOT routed\n * through these handlers (they fall through and, if no custom ancestor is\n * registered, are returned as-is). We use a Map here rather than installing\n * a symbol property on the built-in prototypes, because mutating built-in\n * prototypes (even with a symbol key) changes their hidden class and\n * invalidates V8's fast-path inline caches for every plain object / array\n * in the program.\n */\nconst BUILTIN_PROTO_TO_SNAPSHOT = new Map([\n [Object.prototype, snapshotPlainObject],\n [Array.prototype, snapshotArray],\n [Map.prototype, snapshotMap],\n [Set.prototype, snapshotSet],\n [null, snapshotPlainObject],\n]);\n/**\n * Custom registrations are stored as a non-enumerable symbol property on the\n * class prototype. JS prototype lookup walks the chain natively, so subclass\n * inheritance and override-by-redefinition are free — no resolver, no cache,\n * no invalidation. The symbol is module-private (created with `Symbol()`,\n * not `Symbol.for()`), so it cannot collide with anything else and cannot\n * be addressed by user code.\n */\nconst SNAPSHOT_HANDLER = Symbol('signalium.snapshot.handler');\n/**\n * Register a custom snapshot function for instances of a class.\n * The function receives the current value, the previous snapshot (or undefined),\n * and the recursive `snapshot` function for snapshotting nested values.\n *\n * Subclasses inherit the handler automatically via prototype lookup, so\n * registering once on a base class applies to all descendants. A descendant\n * can override by registering its own handler.\n *\n * Return `prev` when nothing has changed to preserve reference stability.\n *\n * @example\n * ```ts\n * registerCustomSnapshot(MyEntity, (current, prev, snapshot) => {\n * const name = snapshot(current.name, prev?.name);\n * const age = current.age;\n * if (prev && name === prev.name && age === prev.age) return prev;\n * return { name, age };\n * });\n * ```\n */\nexport const registerCustomSnapshot = (ctor, snapshotFn) => {\n // Use defineProperty so the handler is non-enumerable (it shouldn't show up\n // in `Reflect.ownKeys` walks any more than necessary) and so re-registration\n // overwrites cleanly even if a subclass has shadowed it.\n Object.defineProperty(ctor.prototype, SNAPSHOT_HANDLER, {\n value: snapshotFn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n};\n/**\n * Recursively snapshot a value with structural sharing.\n *\n * - Plain objects and arrays are deep-cloned; unchanged subtrees keep the same reference.\n * - ReactivePromise instances are read (establishing deps) and flattened to a plain object.\n * - Class instances are returned as-is unless a custom handler is registered\n * for the class or any of its ancestors via `registerCustomSnapshot`.\n * - Primitives are returned directly.\n */\nexport function snapshot(currentValue, prevValue) {\n if (currentValue === null || typeof currentValue !== 'object') {\n return currentValue;\n }\n if (isReactivePromise(currentValue)) {\n return snapshotReactivePromise(currentValue, prevValue, snapshot);\n }\n // Custom registrations check first: native prototype lookup walks the chain\n // for us, so subclasses inherit their ancestor's handler with no extra work.\n const customHandler = currentValue[SNAPSHOT_HANDLER];\n if (customHandler !== undefined) {\n return customHandler(currentValue, prevValue, snapshot);\n }\n // Built-in handlers are looked up by exact prototype only.\n const builtIn = BUILTIN_PROTO_TO_SNAPSHOT.get(getProto(currentValue));\n if (builtIn !== undefined) {\n return builtIn(currentValue, prevValue, snapshot);\n }\n return currentValue;\n}\n"],"names":["createReactiveDefinition","getCurrentScope","getScopeOwner","createRelay","createTask","SignalScope","createReactiveSignal","isReactivePromise"],"mappings":";;AAIO,MAAM,yBAAyB,oBAAI,QAAO;AAC1C,SAAS,2BAA2B,IAAI,MAAM;AACjD,MAAI,WAAW,uBAAuB,IAAI,EAAE;AAC5C,MAAI,CAAC,UAAU;AACX,UAAM,MAAMA,SAAAA,yBAAyB,MAAM,IAAI,MAAM,MAAM,IAAI,MAAM,QAAQ,OAAO,MAAM,QAAmB;AAC7G,UAAM,WAAWC,SAAAA,gBAAe;AAChC,UAAM,aAAa,IAAI,SAAS;AAC5B,YAAM,QAAQA,SAAAA,gBAAgB,QAAQ;AACtC,YAAM,SAAS,MAAM,IAAI,KAAK,IAAI;AAClC,aAAO,OAAO;AAAA,IAClB;AACA,eAAW,CAAC,YAAY,GAAG;AAC3B,2BAAuB,IAAI,IAAI,QAAQ;AAAA,EAC3C;AACA,SAA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;AAAA,EAC3B,CAAC,MAAM,mBAAmB;AAC9B,CAAC;AASD,MAAM,mBAAmB,uBAAO,4BAA4B;AAsBhD,MAAC,yBAAyB,CAAC,MAAM,eAAe;AAIxD,SAAO,eAAe,KAAK,WAAW,kBAAkB;AAAA,IACpD,OAAO;AAAA,IACP,UAAU;AAAA,IACV,cAAc;AAAA,IACd,YAAY;AAAA,EACpB,CAAK;AACL;AAUO,SAAS,SAAS,cAAc,WAAW;AAC9C,MAAI,iBAAiB,QAAQ,OAAO,iBAAiB,UAAU;AAC3D,WAAO;AAAA,EACX;AACA,MAAIC,SAAAA,kBAAkB,YAAY,GAAG;AACjC,WAAO,wBAAwB,cAAc,WAAW,QAAQ;AAAA,EACpE;AAGA,QAAM,gBAAgB,aAAa,gBAAgB;AACnD,MAAI,kBAAkB,QAAW;AAC7B,WAAO,cAAc,cAAc,WAAW,QAAQ;AAAA,EAC1D;AAEA,QAAM,UAAU,0BAA0B,IAAI,SAAS,YAAY,CAAC;AACpE,MAAI,YAAY,QAAW;AACvB,WAAO,QAAQ,cAAc,WAAW,QAAQ;AAAA,EACpD;AACA,SAAO;AACX;;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-DbLBnoC8.js","sources":["../../../.tsc-out/internals/core-api.js","../../../.tsc-out/internals/utils/snapshot.js"],"sourcesContent":["import { getCurrentScope, getScopeOwner, SignalScope } from './contexts.js';\nimport { createReactiveDefinition, createReactiveSignal, } from './reactive.js';\nimport { createRelay, createTask } from './async.js';\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const DERIVED_DEFINITION_MAP = new WeakMap();\nexport function getReactiveFnAndDefinition(fn, opts) {\n let fnAndDef = DERIVED_DEFINITION_MAP.get(fn);\n if (!fnAndDef) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const defScope = getCurrentScope();\n const reactiveFn = (...args) => {\n const scope = getCurrentScope(defScope);\n const signal = scope.get(def, args);\n return signal.value;\n };\n fnAndDef = [reactiveFn, def];\n DERIVED_DEFINITION_MAP.set(fn, fnAndDef);\n }\n return fnAndDef;\n}\nexport function reactive(fn, opts) {\n return getReactiveFnAndDefinition(fn, opts)[0];\n}\nexport const reactiveMethod = (owner, fn, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const reactiveFn = (...args) => {\n return getScopeOwner(owner).get(def, args).value;\n };\n DERIVED_DEFINITION_MAP.set(reactiveFn, [reactiveFn, def]);\n return reactiveFn;\n};\nexport function relay(activate, opts) {\n const scope = getCurrentScope();\n return createRelay(activate, scope, opts);\n}\nexport const task = (fn, opts) => {\n const scope = getCurrentScope();\n return createTask(fn, scope, opts);\n};\nexport function watcher(fn, opts) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, undefined, opts?.tracer);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n}\n/**\n * Creates a reactive signal from a compute function. This is useful for when you\n * want to create a signal that does not receive parameters, but is still reactive.\n *\n * @param compute\n * @param opts\n * @returns\n */\nexport const reactiveSignal = (compute, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, compute, opts?.equals, false, undefined, undefined);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n};\n","import { isReactivePromise } from '../async.js';\nconst getProto = Object.getPrototypeOf;\nfunction snapshotArray(current, prev, snap) {\n const prevArr = Array.isArray(prev) ? prev : undefined;\n let changed = !prevArr || prevArr.length !== current.length;\n const result = new Array(current.length);\n for (let i = 0; i < current.length; i++) {\n result[i] = snap(current[i], prevArr?.[i]);\n if (!changed && result[i] !== prevArr[i]) {\n changed = true;\n }\n }\n return changed ? result : prevArr;\n}\nfunction snapshotPlainObject(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' && !Array.isArray(prev)\n ? prev\n : undefined;\n const keys = Object.keys(current);\n let changed = !prevObj || Object.keys(prevObj).length !== keys.length;\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n result[key] = snap(current[key], prevObj?.[key]);\n if (!changed && result[key] !== prevObj[key]) {\n changed = true;\n }\n }\n return changed ? result : prevObj;\n}\nfunction snapshotReactivePromise(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' ? prev : undefined;\n const value = snap(current.value, prevObj?.value);\n const error = current.error;\n const isPending = current.isPending;\n const isRejected = current.isRejected;\n const isResolved = current.isResolved;\n const isReady = current.isReady;\n const isSettled = current.isSettled;\n if (prevObj &&\n value === prevObj.value &&\n error === prevObj.error &&\n isPending === prevObj.isPending &&\n isRejected === prevObj.isRejected &&\n isResolved === prevObj.isResolved &&\n isReady === prevObj.isReady &&\n isSettled === prevObj.isSettled) {\n return prevObj;\n }\n return { value, error, isPending, isRejected, isResolved, isReady, isSettled };\n}\nfunction snapshotMap(current, prev, snap) {\n const prevMap = prev instanceof Map ? prev : undefined;\n let changed = !prevMap || prevMap.size !== current.size;\n const result = new Map();\n for (const [key, val] of current) {\n const snapped = snap(val, prevMap?.get(key));\n result.set(key, snapped);\n if (!changed && snapped !== prevMap.get(key)) {\n changed = true;\n }\n }\n return changed ? result : prevMap;\n}\nfunction snapshotSet(current, prev, _snap) {\n const prevSet = prev instanceof Set ? prev : undefined;\n let changed = !prevSet || prevSet.size !== current.size;\n const result = new Set();\n for (const val of current) {\n const snapped = snapshot(val, prevSet?.has(val) ? val : undefined);\n result.add(snapped);\n if (!changed && !prevSet.has(snapped)) {\n changed = true;\n }\n }\n return changed ? result : prevSet;\n}\n/**\n * Built-in handlers for plain structural types. Matched by exact prototype\n * only — subclasses of `Object` / `Array` / `Map` / `Set` are NOT routed\n * through these handlers (they fall through and, if no custom ancestor is\n * registered, are returned as-is). We use a Map here rather than installing\n * a symbol property on the built-in prototypes, because mutating built-in\n * prototypes (even with a symbol key) changes their hidden class and\n * invalidates V8's fast-path inline caches for every plain object / array\n * in the program.\n */\nconst BUILTIN_PROTO_TO_SNAPSHOT = new Map([\n [Object.prototype, snapshotPlainObject],\n [Array.prototype, snapshotArray],\n [Map.prototype, snapshotMap],\n [Set.prototype, snapshotSet],\n [null, snapshotPlainObject],\n]);\n/**\n * Custom registrations are stored as a non-enumerable symbol property on the\n * class prototype. JS prototype lookup walks the chain natively, so subclass\n * inheritance and override-by-redefinition are free — no resolver, no cache,\n * no invalidation. The symbol is module-private (created with `Symbol()`,\n * not `Symbol.for()`), so it cannot collide with anything else and cannot\n * be addressed by user code.\n */\nconst SNAPSHOT_HANDLER = Symbol('signalium.snapshot.handler');\n/**\n * Register a custom snapshot function for instances of a class.\n * The function receives the current value, the previous snapshot (or undefined),\n * and the recursive `snapshot` function for snapshotting nested values.\n *\n * Subclasses inherit the handler automatically via prototype lookup, so\n * registering once on a base class applies to all descendants. A descendant\n * can override by registering its own handler.\n *\n * Return `prev` when nothing has changed to preserve reference stability.\n *\n * @example\n * ```ts\n * registerCustomSnapshot(MyEntity, (current, prev, snapshot) => {\n * const name = snapshot(current.name, prev?.name);\n * const age = current.age;\n * if (prev && name === prev.name && age === prev.age) return prev;\n * return { name, age };\n * });\n * ```\n */\nexport const registerCustomSnapshot = (ctor, snapshotFn) => {\n // Use defineProperty so the handler is non-enumerable (it shouldn't show up\n // in `Reflect.ownKeys` walks any more than necessary) and so re-registration\n // overwrites cleanly even if a subclass has shadowed it.\n Object.defineProperty(ctor.prototype, SNAPSHOT_HANDLER, {\n value: snapshotFn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n};\n/**\n * Recursively snapshot a value with structural sharing.\n *\n * - Plain objects and arrays are deep-cloned; unchanged subtrees keep the same reference.\n * - ReactivePromise instances are read (establishing deps) and flattened to a plain object.\n * - Class instances are returned as-is unless a custom handler is registered\n * for the class or any of its ancestors via `registerCustomSnapshot`.\n * - Primitives are returned directly.\n */\nexport function snapshot(currentValue, prevValue) {\n if (currentValue === null || typeof currentValue !== 'object') {\n return currentValue;\n }\n if (isReactivePromise(currentValue)) {\n return snapshotReactivePromise(currentValue, prevValue, snapshot);\n }\n // Custom registrations check first: native prototype lookup walks the chain\n // for us, so subclasses inherit their ancestor's handler with no extra work.\n const customHandler = currentValue[SNAPSHOT_HANDLER];\n if (customHandler !== undefined) {\n return customHandler(currentValue, prevValue, snapshot);\n }\n // Built-in handlers are looked up by exact prototype only.\n const builtIn = BUILTIN_PROTO_TO_SNAPSHOT.get(getProto(currentValue));\n if (builtIn !== undefined) {\n return builtIn(currentValue, prevValue, snapshot);\n }\n return currentValue;\n}\n"],"names":[],"mappings":";AAIO,MAAM,yBAAyB,oBAAI,QAAO;AAC1C,SAAS,2BAA2B,IAAI,MAAM;AACjD,MAAI,WAAW,uBAAuB,IAAI,EAAE;AAC5C,MAAI,CAAC,UAAU;AACX,UAAM,MAAM,yBAAyB,MAAM,IAAI,MAAM,MAAM,IAAI,MAAM,QAAQ,OAAO,MAAM,UAAU,MAAS;AAC7G,UAAM,WAAW,gBAAe;AAChC,UAAM,aAAa,IAAI,SAAS;AAC5B,YAAM,QAAQ,gBAAgB,QAAQ;AACtC,YAAM,SAAS,MAAM,IAAI,KAAK,IAAI;AAClC,aAAO,OAAO;AAAA,IAClB;AACA,eAAW,CAAC,YAAY,GAAG;AAC3B,2BAAuB,IAAI,IAAI,QAAQ;AAAA,EAC3C;AACA,SAAO;AACX;AACO,SAAS,SAAS,IAAI,MAAM;AAC/B,SAAO,2BAA2B,IAAI,IAAI,EAAE,CAAC;AACjD;AACY,MAAC,iBAAiB,CAAC,OAAO,IAAI,SAAS;AAC/C,QAAM,MAAM,yBAAyB,MAAM,IAAI,MAAM,MAAM,IAAI,MAAM,QAAQ,OAAO,MAAM,UAAU,MAAS;AAC7G,QAAM,aAAa,IAAI,SAAS;AAC5B,WAAO,cAAc,KAAK,EAAE,IAAI,KAAK,IAAI,EAAE;AAAA,EAC/C;AACA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Ac,WAAW,QAAQ;AAAA,EACpE;AAGA,QAAM,gBAAgB,aAAa,gBAAgB;AACnD,MAAI,kBAAkB,QAAW;AAC7B,WAAO,cAAc,cAAc,WAAW,QAAQ;AAAA,EAC1D;AAEA,QAAM,UAAU,0BAA0B,IAAI,SAAS,YAAY,CAAC;AACpE,MAAI,YAAY,QAAW;AACvB,WAAO,QAAQ,cAAc,WAAW,QAAQ;AAAA,EACpD;AACA,SAAO;AACX;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-DzqbjLXg.js","sources":["../../../.tsc-out/internals/core-api.js","../../../.tsc-out/internals/utils/snapshot.js"],"sourcesContent":["import { getCurrentScope, getScopeOwner, SignalScope } from './contexts.js';\nimport { createReactiveDefinition, createReactiveSignal, } from './reactive.js';\nimport { createRelay, createTask } from './async.js';\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const DERIVED_DEFINITION_MAP = new WeakMap();\nexport function getReactiveFnAndDefinition(fn, opts) {\n let fnAndDef = DERIVED_DEFINITION_MAP.get(fn);\n if (!fnAndDef) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const defScope = getCurrentScope();\n const reactiveFn = (...args) => {\n const scope = getCurrentScope(defScope);\n const signal = scope.get(def, args);\n return signal.value;\n };\n fnAndDef = [reactiveFn, def];\n DERIVED_DEFINITION_MAP.set(fn, fnAndDef);\n }\n return fnAndDef;\n}\nexport function reactive(fn, opts) {\n return getReactiveFnAndDefinition(fn, opts)[0];\n}\nexport const reactiveMethod = (owner, fn, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, opts?.paramKey, undefined);\n const reactiveFn = (...args) => {\n return getScopeOwner(owner).get(def, args).value;\n };\n DERIVED_DEFINITION_MAP.set(reactiveFn, [reactiveFn, def]);\n return reactiveFn;\n};\nexport function relay(activate, opts) {\n const scope = getCurrentScope();\n return createRelay(activate, scope, opts);\n}\nexport const task = (fn, opts) => {\n const scope = getCurrentScope();\n return createTask(fn, scope, opts);\n};\nexport function watcher(fn, opts) {\n const def = createReactiveDefinition(opts?.id, opts?.desc, fn, opts?.equals, false, undefined, opts?.tracer);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n}\n/**\n * Creates a reactive signal from a compute function. This is useful for when you\n * want to create a signal that does not receive parameters, but is still reactive.\n *\n * @param compute\n * @param opts\n * @returns\n */\nexport const reactiveSignal = (compute, opts) => {\n const def = createReactiveDefinition(opts?.id, opts?.desc, compute, opts?.equals, false, undefined, undefined);\n const scope = opts?.isolate ? new SignalScope([]) : getCurrentScope();\n return createReactiveSignal(def, undefined, undefined, scope);\n};\n","import { isReactivePromise } from '../async.js';\nconst getProto = Object.getPrototypeOf;\nfunction snapshotArray(current, prev, snap) {\n const prevArr = Array.isArray(prev) ? prev : undefined;\n let changed = !prevArr || prevArr.length !== current.length;\n const result = new Array(current.length);\n for (let i = 0; i < current.length; i++) {\n result[i] = snap(current[i], prevArr?.[i]);\n if (!changed && result[i] !== prevArr[i]) {\n changed = true;\n }\n }\n return changed ? result : prevArr;\n}\nfunction snapshotPlainObject(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' && !Array.isArray(prev)\n ? prev\n : undefined;\n const keys = Object.keys(current);\n let changed = !prevObj || Object.keys(prevObj).length !== keys.length;\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n result[key] = snap(current[key], prevObj?.[key]);\n if (!changed && result[key] !== prevObj[key]) {\n changed = true;\n }\n }\n return changed ? result : prevObj;\n}\nfunction snapshotReactivePromise(current, prev, snap) {\n const prevObj = prev !== null && prev !== undefined && typeof prev === 'object' ? prev : undefined;\n const value = snap(current.value, prevObj?.value);\n const error = current.error;\n const isPending = current.isPending;\n const isRejected = current.isRejected;\n const isResolved = current.isResolved;\n const isReady = current.isReady;\n const isSettled = current.isSettled;\n if (prevObj &&\n value === prevObj.value &&\n error === prevObj.error &&\n isPending === prevObj.isPending &&\n isRejected === prevObj.isRejected &&\n isResolved === prevObj.isResolved &&\n isReady === prevObj.isReady &&\n isSettled === prevObj.isSettled) {\n return prevObj;\n }\n return { value, error, isPending, isRejected, isResolved, isReady, isSettled };\n}\nfunction snapshotMap(current, prev, snap) {\n const prevMap = prev instanceof Map ? prev : undefined;\n let changed = !prevMap || prevMap.size !== current.size;\n const result = new Map();\n for (const [key, val] of current) {\n const snapped = snap(val, prevMap?.get(key));\n result.set(key, snapped);\n if (!changed && snapped !== prevMap.get(key)) {\n changed = true;\n }\n }\n return changed ? result : prevMap;\n}\nfunction snapshotSet(current, prev, _snap) {\n const prevSet = prev instanceof Set ? prev : undefined;\n let changed = !prevSet || prevSet.size !== current.size;\n const result = new Set();\n for (const val of current) {\n const snapped = snapshot(val, prevSet?.has(val) ? val : undefined);\n result.add(snapped);\n if (!changed && !prevSet.has(snapped)) {\n changed = true;\n }\n }\n return changed ? result : prevSet;\n}\n/**\n * Built-in handlers for plain structural types. Matched by exact prototype\n * only — subclasses of `Object` / `Array` / `Map` / `Set` are NOT routed\n * through these handlers (they fall through and, if no custom ancestor is\n * registered, are returned as-is). We use a Map here rather than installing\n * a symbol property on the built-in prototypes, because mutating built-in\n * prototypes (even with a symbol key) changes their hidden class and\n * invalidates V8's fast-path inline caches for every plain object / array\n * in the program.\n */\nconst BUILTIN_PROTO_TO_SNAPSHOT = new Map([\n [Object.prototype, snapshotPlainObject],\n [Array.prototype, snapshotArray],\n [Map.prototype, snapshotMap],\n [Set.prototype, snapshotSet],\n [null, snapshotPlainObject],\n]);\n/**\n * Custom registrations are stored as a non-enumerable symbol property on the\n * class prototype. JS prototype lookup walks the chain natively, so subclass\n * inheritance and override-by-redefinition are free — no resolver, no cache,\n * no invalidation. The symbol is module-private (created with `Symbol()`,\n * not `Symbol.for()`), so it cannot collide with anything else and cannot\n * be addressed by user code.\n */\nconst SNAPSHOT_HANDLER = Symbol('signalium.snapshot.handler');\n/**\n * Register a custom snapshot function for instances of a class.\n * The function receives the current value, the previous snapshot (or undefined),\n * and the recursive `snapshot` function for snapshotting nested values.\n *\n * Subclasses inherit the handler automatically via prototype lookup, so\n * registering once on a base class applies to all descendants. A descendant\n * can override by registering its own handler.\n *\n * Return `prev` when nothing has changed to preserve reference stability.\n *\n * @example\n * ```ts\n * registerCustomSnapshot(MyEntity, (current, prev, snapshot) => {\n * const name = snapshot(current.name, prev?.name);\n * const age = current.age;\n * if (prev && name === prev.name && age === prev.age) return prev;\n * return { name, age };\n * });\n * ```\n */\nexport const registerCustomSnapshot = (ctor, snapshotFn) => {\n // Use defineProperty so the handler is non-enumerable (it shouldn't show up\n // in `Reflect.ownKeys` walks any more than necessary) and so re-registration\n // overwrites cleanly even if a subclass has shadowed it.\n Object.defineProperty(ctor.prototype, SNAPSHOT_HANDLER, {\n value: snapshotFn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n};\n/**\n * Recursively snapshot a value with structural sharing.\n *\n * - Plain objects and arrays are deep-cloned; unchanged subtrees keep the same reference.\n * - ReactivePromise instances are read (establishing deps) and flattened to a plain object.\n * - Class instances are returned as-is unless a custom handler is registered\n * for the class or any of its ancestors via `registerCustomSnapshot`.\n * - Primitives are returned directly.\n */\nexport function snapshot(currentValue, prevValue) {\n if (currentValue === null || typeof currentValue !== 'object') {\n return currentValue;\n }\n if (isReactivePromise(currentValue)) {\n return snapshotReactivePromise(currentValue, prevValue, snapshot);\n }\n // Custom registrations check first: native prototype lookup walks the chain\n // for us, so subclasses inherit their ancestor's handler with no extra work.\n const customHandler = currentValue[SNAPSHOT_HANDLER];\n if (customHandler !== undefined) {\n return customHandler(currentValue, prevValue, snapshot);\n }\n // Built-in handlers are looked up by exact prototype only.\n const builtIn = BUILTIN_PROTO_TO_SNAPSHOT.get(getProto(currentValue));\n if (builtIn !== undefined) {\n return builtIn(currentValue, prevValue, snapshot);\n }\n return currentValue;\n}\n"],"names":[],"mappings":";AAI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