preact-sigma 6.1.2 → 6.1.4
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,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as SigmaRef, c as castProtected, d as sigma, f as Draft, h as Cleanup, i as SigmaDefinition, l as query, m as typeSymbol, n as ReadableSigma, o as SigmaState, p as Immutable, r as Sigma, s as SigmaTarget, t as Protected, u as setAutoFreeze } from "./sigma-BfaJUPWw.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/defaults.d.ts
|
|
4
4
|
/**
|
|
@@ -58,4 +58,4 @@ type UseSigmaArgs<T extends Sigma<any>> = T extends {
|
|
|
58
58
|
*/
|
|
59
59
|
declare function useSigma<T extends Sigma<any>>(...args: UseSigmaArgs<T>): Protected<T>;
|
|
60
60
|
//#endregion
|
|
61
|
-
export { type Draft, type Immutable, InferEventType, InferListener, Listenable, Protected, Sigma, SigmaDefinition, SigmaListenable, SigmaRef, SigmaState, SigmaTarget, UseSigmaArgs, UseSigmaOptions, castProtected, listen, mergeDefaults, query, setAutoFreeze, sigma, useListener, useSigma };
|
|
61
|
+
export { type Draft, type Immutable, InferEventType, InferListener, Listenable, Protected, ReadableSigma, Sigma, SigmaDefinition, SigmaListenable, SigmaRef, SigmaState, SigmaTarget, UseSigmaArgs, UseSigmaOptions, castProtected, listen, mergeDefaults, query, setAutoFreeze, sigma, useListener, useSigma };
|
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-DEKK3bHd.mjs";
|
|
2
2
|
import { useEffect, useRef } from "preact/hooks";
|
|
3
3
|
//#region src/defaults.ts
|
|
4
4
|
/**
|
package/dist/persist.d.mts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as ReadableSigma, p as Immutable, r as Sigma } from "./sigma-BfaJUPWw.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/persist.d.ts
|
|
4
4
|
type MaybePromise<T> = T | Promise<T>;
|
|
5
|
-
/**
|
|
6
|
-
* Sigma instance or protected consumer view accepted by persistence helpers.
|
|
7
|
-
*
|
|
8
|
-
* Restore and hydrate helpers may replace committed state through this trusted owner boundary.
|
|
9
|
-
*/
|
|
10
|
-
type PersistInstance<TState extends object> = Sigma<TState> | Protected<Sigma<TState>>;
|
|
11
5
|
/** Decode-time context passed to persistence codecs. */
|
|
12
6
|
interface PersistDecodeContext<TState extends object> {
|
|
13
7
|
/** Storage key used to read the record being decoded. */
|
|
@@ -114,19 +108,19 @@ interface SyncHydrationHandle extends PersistenceHandle {
|
|
|
114
108
|
readonly restored: RestoreResult;
|
|
115
109
|
}
|
|
116
110
|
/** Restores committed state from a persisted record through an async store. */
|
|
117
|
-
declare function restore<TState extends object, TKey extends keyof TState>(instance:
|
|
118
|
-
declare function restore<TState extends object, TStored = Immutable<TState>>(instance:
|
|
111
|
+
declare function restore<TState extends object, TKey extends keyof TState>(instance: ReadableSigma<TState>, options: PickPersistOptions<TState, TKey>): Promise<RestoreResult>;
|
|
112
|
+
declare function restore<TState extends object, TStored = Immutable<TState>>(instance: ReadableSigma<TState>, options: PersistOptions<TState, TStored>): Promise<RestoreResult>;
|
|
119
113
|
/** Restores committed state from a persisted record through a sync store. */
|
|
120
|
-
declare function restoreSync<TState extends object, TKey extends keyof TState>(instance:
|
|
121
|
-
declare function restoreSync<TState extends object, TStored = Immutable<TState>>(instance:
|
|
114
|
+
declare function restoreSync<TState extends object, TKey extends keyof TState>(instance: ReadableSigma<TState>, options: SyncPickPersistOptions<TState, TKey>): RestoreResult;
|
|
115
|
+
declare function restoreSync<TState extends object, TStored = Immutable<TState>>(instance: ReadableSigma<TState>, options: SyncPersistOptions<TState, TStored>): RestoreResult;
|
|
122
116
|
/** Persists future committed state changes for one sigma instance. */
|
|
123
|
-
declare function persist<TState extends object, TKey extends keyof TState>(instance:
|
|
124
|
-
declare function persist<TState extends object, TStored = Immutable<TState>>(instance:
|
|
117
|
+
declare function persist<TState extends object, TKey extends keyof TState>(instance: ReadableSigma<TState>, options: PickPersistOptions<TState, TKey>): PersistenceHandle;
|
|
118
|
+
declare function persist<TState extends object, TStored = Immutable<TState>>(instance: ReadableSigma<TState>, options: PersistOptions<TState, TStored>): PersistenceHandle;
|
|
125
119
|
/** Restores state, then begins persisting future committed changes. */
|
|
126
|
-
declare function hydrate<TState extends object, TKey extends keyof TState>(instance:
|
|
127
|
-
declare function hydrate<TState extends object, TStored = Immutable<TState>>(instance:
|
|
120
|
+
declare function hydrate<TState extends object, TKey extends keyof TState>(instance: ReadableSigma<TState>, options: PickPersistOptions<TState, TKey>): HydrationHandle;
|
|
121
|
+
declare function hydrate<TState extends object, TStored = Immutable<TState>>(instance: ReadableSigma<TState>, options: PersistOptions<TState, TStored>): HydrationHandle;
|
|
128
122
|
/** Restores state synchronously, then begins persisting future committed changes. */
|
|
129
|
-
declare function hydrateSync<TState extends object, TKey extends keyof TState>(instance:
|
|
130
|
-
declare function hydrateSync<TState extends object, TStored = Immutable<TState>>(instance:
|
|
123
|
+
declare function hydrateSync<TState extends object, TKey extends keyof TState>(instance: ReadableSigma<TState>, options: SyncPickPersistOptions<TState, TKey>): SyncHydrationHandle;
|
|
124
|
+
declare function hydrateSync<TState extends object, TStored = Immutable<TState>>(instance: ReadableSigma<TState>, options: SyncPersistOptions<TState, TStored>): SyncHydrationHandle;
|
|
131
125
|
//#endregion
|
|
132
126
|
export { HydrationHandle, PersistCodec, PersistDecodeContext, PersistErrorContext, PersistOptions, PersistRecord, PersistSchedule, PersistStore, PersistenceHandle, PickPersistOptions, RestoreResult, SyncHydrationHandle, SyncPersistOptions, SyncPersistStore, SyncPickPersistOptions, hydrate, hydrateSync, persist, restore, restoreSync };
|
package/dist/persist.mjs
CHANGED
|
@@ -75,6 +75,7 @@ declare function setAutoFreeze(autoFreeze: boolean): void;
|
|
|
75
75
|
type SigmaRef<T extends object = {}> = T & {
|
|
76
76
|
[refSymbol]?: true;
|
|
77
77
|
};
|
|
78
|
+
type ReadableSigma<TState extends object> = Sigma<TState> | Protected<Sigma<TState>>;
|
|
78
79
|
/** Definition shape used by helper types that need both state and event maps. */
|
|
79
80
|
type SigmaDefinition = {
|
|
80
81
|
state: object;
|
|
@@ -88,6 +89,7 @@ type SigmaState<T extends SigmaDefinition> = Sigma<T["state"]> & {
|
|
|
88
89
|
* Base class for signal-backed state models.
|
|
89
90
|
*
|
|
90
91
|
* `TState` is the source of typing for top-level state keys, subscriptions, signals, and replacement snapshots.
|
|
92
|
+
* The initial state passed to `super(...)` can use either the mutable `TState` shape or an immutable snapshot.
|
|
91
93
|
* Private class fields stay ordinary instance storage and are not signal-backed, captured,
|
|
92
94
|
* persisted, or used for reactive invalidation by themselves.
|
|
93
95
|
* Merge a same-named interface with the class when direct property reads should be typed on the instance.
|
|
@@ -99,7 +101,7 @@ declare abstract class Sigma<TState extends object> {
|
|
|
99
101
|
};
|
|
100
102
|
[snapshotSymbol]: Record<string, unknown> | undefined;
|
|
101
103
|
protected get [instanceSymbol](): this;
|
|
102
|
-
constructor(initialState: TState);
|
|
104
|
+
constructor(initialState: TState | Immutable<TState>);
|
|
103
105
|
/** Optional setup hook that owns side effects and returns cleanup resources. */
|
|
104
106
|
onSetup?(...args: any[]): readonly AnyResource[];
|
|
105
107
|
/** Runs `onSetup(...)` and returns a cleanup that disposes returned resources in reverse order. */
|
|
@@ -127,7 +129,7 @@ declare class SigmaTarget<TEvents extends object = {}, TState extends object = {
|
|
|
127
129
|
events: TEvents;
|
|
128
130
|
};
|
|
129
131
|
protected [listenersSymbol]: SigmaListenerMap;
|
|
130
|
-
constructor(state?: TState);
|
|
132
|
+
constructor(state?: TState | Immutable<TState>);
|
|
131
133
|
/**
|
|
132
134
|
* Emits a typed event.
|
|
133
135
|
*
|
|
@@ -149,7 +151,7 @@ declare const sigma: Readonly<{
|
|
|
149
151
|
<TState extends object, TKey extends Extract<keyof TState, string>>(instance: Sigma<TState>, key: TKey, listener: (value: Immutable<TState[TKey]>) => void): Cleanup;
|
|
150
152
|
}; /** Returns the readonly signal backing one top-level state key. */
|
|
151
153
|
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:
|
|
154
|
+
captureState<TState extends object>(instance: ReadableSigma<TState>): Immutable<TState>; /** Publishes a plain-object snapshot, including readonly captured snapshots, as committed state. */
|
|
153
155
|
replaceState<TState extends object>(target: Sigma<TState>, nextState: TState | Immutable<TState>): void;
|
|
154
156
|
}>;
|
|
155
157
|
/**
|
|
@@ -170,4 +172,4 @@ type Protected<T extends Sigma<any>> = BrandProtected<T extends {
|
|
|
170
172
|
};
|
|
171
173
|
} ? { readonly [K in keyof T as K extends ProtectedKey ? never : K]: K extends typeof typeSymbol ? T[K] : K extends keyof TState ? Immutable<T[K]> : T[K] extends AnyFunction ? (...params: Parameters<T[K]>) => Immutable<ReturnType<T[K]>> : Immutable<T[K]> } : never>;
|
|
172
174
|
//#endregion
|
|
173
|
-
export {
|
|
175
|
+
export { SigmaRef as a, castProtected as c, sigma as d, Draft as f, Cleanup as h, SigmaDefinition as i, query as l, typeSymbol as m, ReadableSigma as n, SigmaState as o, Immutable as p, Sigma as r, SigmaTarget as s, Protected as t, setAutoFreeze as u };
|
|
@@ -114,9 +114,11 @@ function getStateSignal(instance, key) {
|
|
|
114
114
|
return instance[key + signalSuffix];
|
|
115
115
|
}
|
|
116
116
|
function createSnapshot(instance) {
|
|
117
|
-
|
|
117
|
+
const source = instance;
|
|
118
|
+
if (source[snapshotSymbol]) return source[snapshotSymbol];
|
|
118
119
|
const state = {};
|
|
119
|
-
for (const key in
|
|
120
|
+
for (const key in source) if (isStateKey(source, key)) state[key] = getStateSignal(source, key).value;
|
|
121
|
+
source[snapshotSymbol] = state;
|
|
120
122
|
return state;
|
|
121
123
|
}
|
|
122
124
|
function createDraft(instance) {
|
|
@@ -322,6 +324,7 @@ function defineSignalProperty(instance, key, value) {
|
|
|
322
324
|
* Base class for signal-backed state models.
|
|
323
325
|
*
|
|
324
326
|
* `TState` is the source of typing for top-level state keys, subscriptions, signals, and replacement snapshots.
|
|
327
|
+
* The initial state passed to `super(...)` can use either the mutable `TState` shape or an immutable snapshot.
|
|
325
328
|
* Private class fields stay ordinary instance storage and are not signal-backed, captured,
|
|
326
329
|
* persisted, or used for reactive invalidation by themselves.
|
|
327
330
|
* Merge a same-named interface with the class when direct property reads should be typed on the instance.
|
|
@@ -333,8 +336,9 @@ var Sigma = class {
|
|
|
333
336
|
constructor(initialState) {
|
|
334
337
|
initializeType(this.constructor);
|
|
335
338
|
if (initialState === emptySentinel) return;
|
|
336
|
-
|
|
337
|
-
|
|
339
|
+
const state = initialState;
|
|
340
|
+
for (const key in state) {
|
|
341
|
+
const initialValue = state[key];
|
|
338
342
|
if (autoFreezeEnabled) freeze(initialValue, true);
|
|
339
343
|
defineSignalProperty(this, key, initialValue);
|
|
340
344
|
}
|