preact-sigma 2.1.1 → 2.1.3

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/README.md CHANGED
@@ -164,6 +164,6 @@ In Preact, the same constructor can be used with `useSigma(() => new TodoList(),
164
164
  - Use `computed(...)` for argument-free derived state, and use queries for reactive reads that need parameters.
165
165
  - Put writes in actions. A draft boundary is any point where sigma cannot keep reusing the current draft. `emit()`, `await`, and any action call other than a same-instance sync nested action call are draft boundaries, so call `this.commit()` before those boundaries when pending writes should become public.
166
166
  - Use `snapshot(instance)` and `replaceState(instance, snapshot)` for committed-state replay. They work on top-level state keys and stay outside action semantics.
167
- - Use `ref(value)` when a value should stay by reference in sigma's `Draft` and `Immutable` types. It only changes typing and does not change Immer's runtime drafting or freezing behavior.
167
+ - Use `SigmaRef<T>` when a value should stay by reference in sigma's `Draft` and `Immutable` types. A normal assignment to a `SigmaRef<T>`-typed value only changes typing and does not change Immer's runtime drafting or freezing behavior.
168
168
  - Use `immerable` on custom classes only when they should participate in Immer drafting. `setAutoFreeze(false)` disables sigma's runtime deep-freezing when you need published state to stay unfrozen.
169
169
  - Use `setup(...)` for owned side effects, and always return cleanup resources for anything the instance starts.
package/dist/index.d.mts CHANGED
@@ -50,7 +50,7 @@ type Disposable = {
50
50
  interface SigmaRefBrand {
51
51
  [sigmaRefBrand]?: true;
52
52
  }
53
- /** A type brand added by `ref(...)`. */
53
+ /** A type brand that keeps a value by reference in sigma's `Draft` and `Immutable` helpers. */
54
54
  type SigmaRef<T = unknown> = T & SigmaRefBrand;
55
55
  /** The event map shape used by sigma types. */
56
56
  type AnyEvents = Record<string, object | void>;
@@ -150,11 +150,6 @@ declare function replaceState<T extends AnySigmaState>(publicInstance: T, nextSt
150
150
  //#region src/framework.d.ts
151
151
  /** Checks whether a value is a sigma-state instance. */
152
152
  declare function isSigmaState(value: unknown): value is AnySigmaState;
153
- /**
154
- * Returns `value` unchanged and marks its type so sigma's Draft and Immutable
155
- * helpers keep it by reference instead of recursively immerizing it.
156
- */
157
- declare function ref<T extends object>(value: T): SigmaRef<T>;
158
153
  /** Creates a standalone tracked query function with the same signature as `fn`. */
159
154
  declare function query<TArgs extends any[], TResult>(fn: (this: void, ...args: TArgs) => TResult): typeof fn;
160
155
  /**
@@ -238,4 +233,4 @@ declare function useSigma<T extends AnySigmaState>(create: () => T, setupArgs?:
238
233
  /** Attaches an event listener in a component and cleans it up when dependencies change. */
239
234
  declare function useListener<TTarget extends EventTarget | AnySigmaState, TEvent extends InferEventType<TTarget>>(target: TTarget | null, name: TEvent, listener: InferListener<TTarget, TEvent>): void;
240
235
  //#endregion
241
- export { type AnyDefaultState, type AnyEvents, type AnyResource, type AnySigmaState, type AnySigmaStateWithEvents, type AnyState, InferEventType, InferListener, type InferSetupArgs, type SigmaObserveChange, type SigmaObserveOptions, type SigmaState, SigmaType, action, batch, computed, effect, freeze, immerable, isSigmaState, listen, query, ref, replaceState, setAutoFreeze, snapshot, untracked, useListener, useSigma };
236
+ export { type AnyDefaultState, type AnyEvents, type AnyResource, type AnySigmaState, type AnySigmaStateWithEvents, type AnyState, InferEventType, InferListener, type InferSetupArgs, type SigmaObserveChange, type SigmaObserveOptions, type SigmaRef, type SigmaState, SigmaType, action, batch, computed, effect, freeze, immerable, isSigmaState, listen, query, replaceState, setAutoFreeze, snapshot, untracked, useListener, useSigma };
package/dist/index.mjs CHANGED
@@ -520,13 +520,6 @@ Object.defineProperty(Sigma.prototype, sigmaStateBrand, { value: true });
520
520
  function isSigmaState(value) {
521
521
  return Boolean(value && typeof value === "object" && value[sigmaStateBrand]);
522
522
  }
523
- /**
524
- * Returns `value` unchanged and marks its type so sigma's Draft and Immutable
525
- * helpers keep it by reference instead of recursively immerizing it.
526
- */
527
- function ref(value) {
528
- return value;
529
- }
530
523
  /** Creates a standalone tracked query function with the same signature as `fn`. */
531
524
  function query(fn) {
532
525
  return ((...args) => computed$1(() => fn(...args)).value);
@@ -633,4 +626,4 @@ function useListener(target, name, listener) {
633
626
  }, [target, name]);
634
627
  }
635
628
  //#endregion
636
- export { SigmaType, action, batch, computed, effect, freeze, immerable, isSigmaState, listen, query, ref, replaceState, setAutoFreeze, snapshot, untracked, useListener, useSigma };
629
+ export { SigmaType, action, batch, computed, effect, freeze, immerable, isSigmaState, listen, query, replaceState, setAutoFreeze, snapshot, untracked, useListener, useSigma };
package/llms.txt CHANGED
@@ -7,7 +7,6 @@
7
7
  - `state property`: A top-level property from `TState`, such as `draft` in `{ draft: string }`.
8
8
  - `computed`: A tracked getter declared with `.computed({ ... })`.
9
9
  - `query`: A tracked method declared with `.queries({ ... })` or created with `query(fn)`.
10
- - `ref`: A helper that keeps a value by reference in sigma's `Draft` and `Immutable` types without changing runtime behavior.
11
10
  - `action`: A method declared with `.actions({ ... })` that reads and writes through one Immer draft for one synchronous call.
12
11
  - `draft boundary`: Any point where sigma cannot keep reusing the current draft.
13
12
  - `setup handler`: A function declared with `.setup(fn)` that returns an array of cleanup resources.
@@ -18,7 +17,7 @@
18
17
 
19
18
  - For state shape, inference, and instance shape, read `Start Here`, `Inference`, `SigmaType`, and `Public Instance Shape`.
20
19
  - For mutation semantics, read `Critical Rules`, `actions`, `immerable`, and `setAutoFreeze`.
21
- - For type-level by-reference values, read `ref`.
20
+ - For type-level by-reference values, see `SigmaRef<T>`.
22
21
  - For side effects and events, read `setup`, `Events`, `listen`, `useListener`, and `useSigma`.
23
22
  - For committed-state utilities, read `observe`, `snapshot`, and `replaceState`.
24
23
 
@@ -62,7 +61,7 @@ import {
62
61
  isSigmaState,
63
62
  listen,
64
63
  query,
65
- ref,
64
+ type SigmaRef,
66
65
  replaceState,
67
66
  setAutoFreeze,
68
67
  snapshot,
@@ -328,13 +327,13 @@ Behavior:
328
327
  - custom class instances without a true `[immerable]` property stay outside that freeze path
329
328
  - plain objects, arrays, `Map`, and `Set` already participate in normal Immer drafting without extra markers
330
329
 
331
- ## `ref(value)`
330
+ ## `SigmaRef<T>`
332
331
 
333
- `ref(value)` returns `value` unchanged and marks its type so sigma's `Draft` and `Immutable` helpers keep that value by reference.
332
+ `SigmaRef<T>` marks a value's type so sigma's `Draft` and `Immutable` helpers keep that value by reference.
334
333
 
335
334
  Behavior:
336
335
 
337
- - it has no runtime effect
336
+ - assigning to a `SigmaRef<T>`-typed value has no runtime effect
338
337
  - it only changes sigma's local `Draft` and `Immutable` typing
339
338
  - it prevents type-level recursive immerization for that value
340
339
  - it does not change whether Immer drafts or freezes the value at runtime
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "preact-sigma",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "keywords": [],
5
5
  "license": "MIT",
6
6
  "author": "Alec Larson",