preact-sigma 6.0.1 → 6.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/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/persist.d.mts +1 -1
- package/dist/persist.mjs +1 -1
- package/dist/{sigma-D1V3m1xk.d.mts → sigma-BhmvUxp9.d.mts} +7 -2
- package/dist/{sigma-DTMODzf8.mjs → sigma-tZ0xhlG3.mjs} +7 -2
- package/docs/context.md +3 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as SigmaState, c as query, d as Draft, f as Immutable, i as SigmaRef, l as setAutoFreeze, m as Cleanup, n as Sigma, o as SigmaTarget, p as typeSymbol, r as SigmaDefinition, s as castProtected, t as Protected, u as sigma } from "./sigma-
|
|
1
|
+
import { a as SigmaState, c as query, d as Draft, f as Immutable, i as SigmaRef, l as setAutoFreeze, m as Cleanup, n as Sigma, o as SigmaTarget, p as typeSymbol, r as SigmaDefinition, s as castProtected, t as Protected, u as sigma } from "./sigma-BhmvUxp9.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/defaults.d.ts
|
|
4
4
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as setAutoFreeze, c as listenersSymbol, i as query, n as SigmaTarget, o as sigma, r as castProtected, t as Sigma } from "./sigma-
|
|
1
|
+
import { a as setAutoFreeze, c as listenersSymbol, i as query, n as SigmaTarget, o as sigma, r as castProtected, t as Sigma } from "./sigma-tZ0xhlG3.mjs";
|
|
2
2
|
import { useEffect, useRef } from "preact/hooks";
|
|
3
3
|
//#region src/defaults.ts
|
|
4
4
|
/**
|
package/dist/persist.d.mts
CHANGED
package/dist/persist.mjs
CHANGED
|
@@ -88,7 +88,8 @@ type SigmaState<T extends SigmaDefinition> = Sigma<T["state"]> & {
|
|
|
88
88
|
* Base class for signal-backed state models.
|
|
89
89
|
*
|
|
90
90
|
* `TState` is the source of typing for top-level state keys, subscriptions, signals, and replacement snapshots.
|
|
91
|
-
* Private class fields stay ordinary instance storage and are not signal-backed, captured,
|
|
91
|
+
* Private class fields stay ordinary instance storage and are not signal-backed, captured,
|
|
92
|
+
* persisted, or used for reactive invalidation by themselves.
|
|
92
93
|
* Merge a same-named interface with the class when direct property reads should be typed on the instance.
|
|
93
94
|
*/
|
|
94
95
|
declare abstract class Sigma<TState extends object> {
|
|
@@ -146,7 +147,11 @@ declare const sigma: Readonly<{
|
|
|
146
147
|
captureState<TState extends object>(instance: Sigma<TState>): Immutable<TState>; /** Publishes a plain-object snapshot as the current committed state. */
|
|
147
148
|
replaceState<TState extends object>(target: Sigma<TState>, nextState: TState): void;
|
|
148
149
|
}>;
|
|
149
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Marks a class method as a committed-state reactive read with arguments instead of an action.
|
|
152
|
+
*
|
|
153
|
+
* Each call creates a reactive read at the call site. Query calls do not memoize results across invocations.
|
|
154
|
+
*/
|
|
150
155
|
declare function query<TThis extends object, TArgs extends any[], TReturn>(method: (this: TThis, ...args: TArgs) => TReturn): (this: TThis, ...args: TArgs) => TReturn;
|
|
151
156
|
declare const protectedSymbol: unique symbol;
|
|
152
157
|
type ProtectedKey = typeof listenersSymbol | typeof snapshotSymbol | "act" | "commit" | "emit" | "onSetup";
|
|
@@ -322,7 +322,8 @@ function defineSignalProperty(instance, key, value) {
|
|
|
322
322
|
* Base class for signal-backed state models.
|
|
323
323
|
*
|
|
324
324
|
* `TState` is the source of typing for top-level state keys, subscriptions, signals, and replacement snapshots.
|
|
325
|
-
* Private class fields stay ordinary instance storage and are not signal-backed, captured,
|
|
325
|
+
* Private class fields stay ordinary instance storage and are not signal-backed, captured,
|
|
326
|
+
* persisted, or used for reactive invalidation by themselves.
|
|
326
327
|
* Merge a same-named interface with the class when direct property reads should be typed on the instance.
|
|
327
328
|
*/
|
|
328
329
|
var Sigma = class {
|
|
@@ -443,7 +444,11 @@ const sigma = /* @__PURE__ */ Object.freeze({
|
|
|
443
444
|
publishState(instance, nextState, baseState, patches, inversePatches);
|
|
444
445
|
}
|
|
445
446
|
});
|
|
446
|
-
/**
|
|
447
|
+
/**
|
|
448
|
+
* Marks a class method as a committed-state reactive read with arguments instead of an action.
|
|
449
|
+
*
|
|
450
|
+
* Each call creates a reactive read at the call site. Query calls do not memoize results across invocations.
|
|
451
|
+
*/
|
|
447
452
|
function query(method) {
|
|
448
453
|
queries.add(method);
|
|
449
454
|
function queryMethod(...args) {
|
package/docs/context.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
- Sigma class: a class that extends `Sigma<TState>` and passes its initial top-level state to `super(...)`. The `TState` argument drives helper typing for subscriptions, signals, and replacement snapshots; a same-named merged interface gives direct property reads their instance types.
|
|
23
23
|
- Sigma target: a class that extends `SigmaTarget<TEvents, TState>` when it also emits typed events. Use `SigmaTarget<TEvents>` for event-only targets.
|
|
24
24
|
- State property: a top-level key from `TState`. Each key becomes a reactive public property and has its own signal.
|
|
25
|
-
- Private field: an ECMAScript `#field` on the model class. Private fields are ordinary instance storage, not
|
|
25
|
+
- Private field: an ECMAScript `#field` on the model class. Private fields are ordinary instance storage. They can be read from model members, but they do not create signals or invalidate reactive reads by themselves.
|
|
26
26
|
- Computed: an argument-free derived getter on the class prototype that reads committed state.
|
|
27
27
|
- Query: a reactive read method that accepts arguments, is marked with the `query` decorator, and reads committed state.
|
|
28
28
|
- Action: a prototype method that is not marked as a query. Actions read and write state properties through sigma's draft and commit semantics.
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
|
|
64
64
|
- Put the state shape in a named `State` type, pass it to `Sigma<TState>` or `SigmaTarget<TEvents, TState>`, then merge a same-named interface with the class for direct property typing.
|
|
65
65
|
- Keep frequently read values as separate top-level state properties. Each top-level key gets its own signal.
|
|
66
|
-
- Use private fields for ephemeral caches, handles, or bookkeeping
|
|
66
|
+
- Use private fields for ephemeral caches, handles, or bookkeeping when private-only changes should not be captured, restored, persisted, used as subscription keys, or published reactively.
|
|
67
67
|
- Use getters for argument-free derived reads.
|
|
68
68
|
- Use `@query` for tracked reads with arguments.
|
|
69
69
|
- Derive directly from state properties inside an action when the calculation needs unpublished draft values.
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
# Invariants and Constraints
|
|
97
97
|
|
|
98
98
|
- Sigma tracks top-level state properties. Each top-level key gets its own signal.
|
|
99
|
-
- Private fields are not top-level state properties. They do not create signals, appear in committed snapshots, participate in persistence helpers, or drive subscriptions by themselves.
|
|
99
|
+
- Private fields are not top-level state properties. They do not create signals, appear in committed snapshots, participate in persistence helpers, or drive subscriptions by themselves. Computeds and queries that read private fields update when their signal-backed state dependencies change; private-only changes do not invalidate those reads.
|
|
100
100
|
- Protected consumer views expose immutable state and callable actions.
|
|
101
101
|
- Published draftable public state is deep-frozen by default. `setAutoFreeze(false)` disables that behavior globally.
|
|
102
102
|
- Computeds and queries read committed state, including when called inside actions.
|