@silvery/signals 0.25.0 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { computed, effect, effectScope, endBatch, getActiveSub, getBatchDepth, isComputed, isEffect, isEffectScope, isSignal, setActiveSub, signal, startBatch, trigger } from "alien-signals";
2
-
3
2
  //#region src/index.d.ts
4
3
  /**
5
4
  * A reactive value — callable getter/setter.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;AAuDA;;;;;KAbY,MAAA;EAAA,IACN,CAAA;EAAA,CACH,KAAA,EAAO,CAAA;AAAA;;;;;;KAQE,UAAA,YAAsB,CAAA;;iBAGlB,KAAA,CAAM,EAAA;;AAsCtB;;UA1BiB,YAAA;EA2BH;EAzBZ,SAAA;EA0B0B;EAxB1B,MAAA,IAAU,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA;AAAA;;;;;;;;;;;;;;;;;;;;iBAsBL,KAAA,GAAA,CACd,IAAA,QAAY,CAAA,EACZ,QAAA,GAAW,IAAA,EAAM,CAAA,EAAG,IAAA,EAAM,CAAA,WAC1B,IAAA,GAAM,YAAA,CAAa,CAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;KA0CY,OAAO;MACb;GACH,OAAO;;;;;;;KAQE,WAAW,WAAW;;iBAGlB,MAAM;;;;UAYL,aAAa;;EAE5B;;EAEA,UAAU,GAAG,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;iBAsBL,MAAM,GACpB,YAAY,GACZ,WAAW,MAAM,GAAG,MAAM,YAC1B,OAAM,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["effect"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @silvery/signals — Reactive signals for silvery.\n *\n * Thin wrapper around alien-signals providing:\n * - signal(value) — create a reactive value (call to read, call with arg to write)\n * - computed(fn) — derived reactive value that recomputes on dependency changes\n * - effect(fn) — side effect that re-runs when dependencies change\n * - effectScope(fn) — group effects for collective disposal\n * - batch(fn) — batch multiple signal updates into one notification\n * - watch(read, onChange) — change-only subscription (skips the seed fire)\n *\n * @packageDocumentation\n */\n\nexport {\n signal,\n computed,\n effect,\n effectScope,\n startBatch,\n endBatch,\n trigger,\n isSignal,\n isComputed,\n isEffect,\n isEffectScope,\n getActiveSub,\n setActiveSub,\n getBatchDepth,\n} from \"alien-signals\"\n\nimport { effect, startBatch, endBatch } from \"alien-signals\"\n\n/**\n * A reactive value — callable getter/setter.\n *\n * - `sig()` reads the current value (and subscribes the active effect/computed).\n * - `sig(next)` writes a new value; subscribers re-run only if `next !== current`.\n *\n * Matches the return shape of `signal<T>(initial)` from alien-signals, so any\n * `signal()` result is assignable to `Signal<T>`.\n */\nexport type Signal<T> = {\n (): T\n (value: T): void\n}\n\n/**\n * A read-only reactive value — callable getter that subscribes the active\n * effect/computed but cannot be written to. Matches the return shape of\n * `computed<T>(fn)` from alien-signals.\n */\nexport type ReadSignal<T> = () => T\n\n/** Batch multiple signal updates, notifying subscribers once at the end. */\nexport function batch(fn: () => void): void {\n startBatch()\n try {\n fn()\n } finally {\n endBatch()\n }\n}\n\n/**\n * Options for {@link watch}.\n */\nexport interface WatchOptions<T> {\n /** If true, fire `onChange` on the seed read with `(next, next)`. Default false (change-only). */\n immediate?: boolean\n /** Equality predicate — handler fires only when `equals(next, prev)` is false. Default `Object.is`. */\n equals?: (a: T, b: T) => boolean\n}\n\n/**\n * Subscribe to signal changes via an imperative callback.\n *\n * alien-signals' `effect()` runs once eagerly to establish dependencies,\n * which means an `effect(() => { handler(sig()) })` fires with the seed\n * value. `watch()` swallows that first fire and only calls `onChange` when\n * the value actually changes — matching the old `.subscribe(handler)`\n * semantic consumers often want.\n *\n * ```ts\n * const stop = watch(\n * () => size.snapshot(),\n * (next, prev) => { emit({ cols: next.cols, rows: next.rows }) },\n * )\n * // stop() to unsubscribe\n * ```\n *\n * Returns the effect's stop function.\n */\nexport function watch<T>(\n read: () => T,\n onChange: (next: T, prev: T) => void,\n opts: WatchOptions<T> = {},\n): () => void {\n const equals = opts.equals ?? Object.is\n let seeded = false\n let prev!: T\n return effect(() => {\n const next = read()\n if (!seeded) {\n seeded = true\n prev = next\n if (opts.immediate) onChange(next, next)\n return\n }\n if (equals(next, prev)) return\n const old = prev\n prev = next\n onChange(next, old)\n })\n}\n"],"mappings":";;;AAuDA,SAAgB,MAAM,IAAsB;AAC1C,eAAY;AACZ,KAAI;AACF,MAAI;WACI;AACR,cAAU;;;;;;;;;;;;;;;;;;;;;;AAiCd,SAAgB,MACd,MACA,UACA,OAAwB,EAAE,EACd;CACZ,MAAM,SAAS,KAAK,UAAU,OAAO;CACrC,IAAI,SAAS;CACb,IAAI;AACJ,QAAOA,eAAa;EAClB,MAAM,OAAO,MAAM;AACnB,MAAI,CAAC,QAAQ;AACX,YAAS;AACT,UAAO;AACP,OAAI,KAAK,UAAW,UAAS,MAAM,KAAK;AACxC;;AAEF,MAAI,OAAO,MAAM,KAAK,CAAE;EACxB,MAAM,MAAM;AACZ,SAAO;AACP,WAAS,MAAM,IAAI;GACnB"}
1
+ {"version":3,"file":"index.mjs","names":["effect"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @silvery/signals — Reactive signals for silvery.\n *\n * Thin wrapper around alien-signals providing:\n * - signal(value) — create a reactive value (call to read, call with arg to write)\n * - computed(fn) — derived reactive value that recomputes on dependency changes\n * - effect(fn) — side effect that re-runs when dependencies change\n * - effectScope(fn) — group effects for collective disposal\n * - batch(fn) — batch multiple signal updates into one notification\n * - watch(read, onChange) — change-only subscription (skips the seed fire)\n *\n * @packageDocumentation\n */\n\nexport {\n signal,\n computed,\n effect,\n effectScope,\n startBatch,\n endBatch,\n trigger,\n isSignal,\n isComputed,\n isEffect,\n isEffectScope,\n getActiveSub,\n setActiveSub,\n getBatchDepth,\n} from \"alien-signals\"\n\nimport { effect, startBatch, endBatch } from \"alien-signals\"\n\n/**\n * A reactive value — callable getter/setter.\n *\n * - `sig()` reads the current value (and subscribes the active effect/computed).\n * - `sig(next)` writes a new value; subscribers re-run only if `next !== current`.\n *\n * Matches the return shape of `signal<T>(initial)` from alien-signals, so any\n * `signal()` result is assignable to `Signal<T>`.\n */\nexport type Signal<T> = {\n (): T\n (value: T): void\n}\n\n/**\n * A read-only reactive value — callable getter that subscribes the active\n * effect/computed but cannot be written to. Matches the return shape of\n * `computed<T>(fn)` from alien-signals.\n */\nexport type ReadSignal<T> = () => T\n\n/** Batch multiple signal updates, notifying subscribers once at the end. */\nexport function batch(fn: () => void): void {\n startBatch()\n try {\n fn()\n } finally {\n endBatch()\n }\n}\n\n/**\n * Options for {@link watch}.\n */\nexport interface WatchOptions<T> {\n /** If true, fire `onChange` on the seed read with `(next, next)`. Default false (change-only). */\n immediate?: boolean\n /** Equality predicate — handler fires only when `equals(next, prev)` is false. Default `Object.is`. */\n equals?: (a: T, b: T) => boolean\n}\n\n/**\n * Subscribe to signal changes via an imperative callback.\n *\n * alien-signals' `effect()` runs once eagerly to establish dependencies,\n * which means an `effect(() => { handler(sig()) })` fires with the seed\n * value. `watch()` swallows that first fire and only calls `onChange` when\n * the value actually changes — matching the old `.subscribe(handler)`\n * semantic consumers often want.\n *\n * ```ts\n * const stop = watch(\n * () => size.snapshot(),\n * (next, prev) => { emit({ cols: next.cols, rows: next.rows }) },\n * )\n * // stop() to unsubscribe\n * ```\n *\n * Returns the effect's stop function.\n */\nexport function watch<T>(\n read: () => T,\n onChange: (next: T, prev: T) => void,\n opts: WatchOptions<T> = {},\n): () => void {\n const equals = opts.equals ?? Object.is\n let seeded = false\n let prev!: T\n return effect(() => {\n const next = read()\n if (!seeded) {\n seeded = true\n prev = next\n if (opts.immediate) onChange(next, next)\n return\n }\n if (equals(next, prev)) return\n const old = prev\n prev = next\n onChange(next, old)\n })\n}\n"],"mappings":";;;AAuDA,SAAgB,MAAM,IAAsB;CAC1C,aAAW;CACX,IAAI;EACF,GAAG;CACL,UAAU;EACR,WAAS;CACX;AACF;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,MACd,MACA,UACA,OAAwB,CAAC,GACb;CACZ,MAAM,SAAS,KAAK,UAAU,OAAO;CACrC,IAAI,SAAS;CACb,IAAI;CACJ,OAAOA,eAAa;EAClB,MAAM,OAAO,KAAK;EAClB,IAAI,CAAC,QAAQ;GACX,SAAS;GACT,OAAO;GACP,IAAI,KAAK,WAAW,SAAS,MAAM,IAAI;GACvC;EACF;EACA,IAAI,OAAO,MAAM,IAAI,GAAG;EACxB,MAAM,MAAM;EACZ,OAAO;EACP,SAAS,MAAM,GAAG;CACpB,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silvery/signals",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "description": "Reactive signals for silvery — thin wrapper around alien-signals",
5
5
  "license": "MIT",
6
6
  "author": "Bjørn Stabell <bjorn@stabell.org>",