preact-sigma 6.1.1 → 6.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/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-c48-qjsH.d.mts → sigma-Dki3T7re.d.mts} +5 -4
- package/dist/{sigma-0X8yJrUR.mjs → sigma-Oviv0rzP.mjs} +8 -5
- package/docs/persist.md +1 -1
- 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-Dki3T7re.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-Oviv0rzP.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,6 +88,7 @@ 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
|
+
* The initial state passed to `super(...)` can use either the mutable `TState` shape or an immutable snapshot.
|
|
91
92
|
* Private class fields stay ordinary instance storage and are not signal-backed, captured,
|
|
92
93
|
* persisted, or used for reactive invalidation by themselves.
|
|
93
94
|
* Merge a same-named interface with the class when direct property reads should be typed on the instance.
|
|
@@ -99,7 +100,7 @@ declare abstract class Sigma<TState extends object> {
|
|
|
99
100
|
};
|
|
100
101
|
[snapshotSymbol]: Record<string, unknown> | undefined;
|
|
101
102
|
protected get [instanceSymbol](): this;
|
|
102
|
-
constructor(initialState: TState);
|
|
103
|
+
constructor(initialState: TState | Immutable<TState>);
|
|
103
104
|
/** Optional setup hook that owns side effects and returns cleanup resources. */
|
|
104
105
|
onSetup?(...args: any[]): readonly AnyResource[];
|
|
105
106
|
/** Runs `onSetup(...)` and returns a cleanup that disposes returned resources in reverse order. */
|
|
@@ -127,7 +128,7 @@ declare class SigmaTarget<TEvents extends object = {}, TState extends object = {
|
|
|
127
128
|
events: TEvents;
|
|
128
129
|
};
|
|
129
130
|
protected [listenersSymbol]: SigmaListenerMap;
|
|
130
|
-
constructor(state?: TState);
|
|
131
|
+
constructor(state?: TState | Immutable<TState>);
|
|
131
132
|
/**
|
|
132
133
|
* Emits a typed event.
|
|
133
134
|
*
|
|
@@ -149,8 +150,8 @@ declare const sigma: Readonly<{
|
|
|
149
150
|
<TState extends object, TKey extends Extract<keyof TState, string>>(instance: Sigma<TState>, key: TKey, listener: (value: Immutable<TState[TKey]>) => void): Cleanup;
|
|
150
151
|
}; /** Returns the readonly signal backing one top-level state key. */
|
|
151
152
|
getSignal<TState extends object, TKey extends Extract<keyof TState, string>>(instance: Sigma<TState>, key: TKey): ReadonlySignal<Immutable<TState[TKey]>>; /** Captures the current committed top-level state snapshot. */
|
|
152
|
-
captureState<TState extends object>(instance: Sigma<TState>): Immutable<TState>; /** Publishes a plain-object snapshot
|
|
153
|
-
replaceState<TState extends object>(target: Sigma<TState>, nextState: TState): void;
|
|
153
|
+
captureState<TState extends object>(instance: Sigma<TState>): Immutable<TState>; /** Publishes a plain-object snapshot, including readonly captured snapshots, as committed state. */
|
|
154
|
+
replaceState<TState extends object>(target: Sigma<TState>, nextState: TState | Immutable<TState>): void;
|
|
154
155
|
}>;
|
|
155
156
|
/**
|
|
156
157
|
* Marks a class method as a committed-state reactive read with arguments instead of an action.
|
|
@@ -322,6 +322,7 @@ 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
|
+
* The initial state passed to `super(...)` can use either the mutable `TState` shape or an immutable snapshot.
|
|
325
326
|
* Private class fields stay ordinary instance storage and are not signal-backed, captured,
|
|
326
327
|
* persisted, or used for reactive invalidation by themselves.
|
|
327
328
|
* Merge a same-named interface with the class when direct property reads should be typed on the instance.
|
|
@@ -333,8 +334,9 @@ var Sigma = class {
|
|
|
333
334
|
constructor(initialState) {
|
|
334
335
|
initializeType(this.constructor);
|
|
335
336
|
if (initialState === emptySentinel) return;
|
|
336
|
-
|
|
337
|
-
|
|
337
|
+
const state = initialState;
|
|
338
|
+
for (const key in state) {
|
|
339
|
+
const initialValue = state[key];
|
|
338
340
|
if (autoFreezeEnabled) freeze(initialValue, true);
|
|
339
341
|
defineSignalProperty(this, key, initialValue);
|
|
340
342
|
}
|
|
@@ -443,12 +445,13 @@ const sigma = /* @__PURE__ */ Object.freeze({
|
|
|
443
445
|
if (activeDraft) throw new Error(`[preact-sigma] replaceState() cannot run while an action has unpublished changes.`);
|
|
444
446
|
const instance = getActionInstance(target);
|
|
445
447
|
const baseState = createSnapshot(instance);
|
|
446
|
-
|
|
447
|
-
|
|
448
|
+
const replacement = nextState;
|
|
449
|
+
if (!hasStateChanges(baseState, replacement)) return;
|
|
450
|
+
const { inversePatches, patches } = hasPatchListeners(instance) ? createReplacementPatches(baseState, replacement) : {
|
|
448
451
|
inversePatches: void 0,
|
|
449
452
|
patches: void 0
|
|
450
453
|
};
|
|
451
|
-
publishState(instance,
|
|
454
|
+
publishState(instance, replacement, baseState, patches, inversePatches);
|
|
452
455
|
}
|
|
453
456
|
});
|
|
454
457
|
/**
|
package/docs/persist.md
CHANGED
|
@@ -56,7 +56,7 @@ Use the persist module when those primitives are the right boundary, but you do
|
|
|
56
56
|
## Constraints
|
|
57
57
|
|
|
58
58
|
- Persistence helpers are trusted external model owners. Restore and hydrate helpers may replace committed state even when they receive a protected consumer view.
|
|
59
|
-
- `sigma.replaceState(...)` requires a plain object replacement snapshot. In supported TypeScript usage, pass the class's full `TState` shape.
|
|
59
|
+
- `sigma.replaceState(...)` requires a plain object replacement snapshot. In supported TypeScript usage, pass the class's full `TState` or `Immutable<TState>` shape.
|
|
60
60
|
- Custom partial persistence codecs should reconstruct a full replacement snapshot before restore finishes.
|
|
61
61
|
- Nested sigma-state values are stored only if the chosen codec and payload format support them explicitly.
|
|
62
62
|
- Async restore failures reject through `restore(...)` or the `restored` promise from `hydrate(...)`.
|