@mmstack/primitives 19.3.8 → 19.3.9
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/fesm2022/mmstack-primitives.mjs +25 -1
- package/fesm2022/mmstack-primitives.mjs.map +1 -1
- package/index.d.ts +1 -1
- package/lib/store.d.ts +35 -4
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from './lib/mutable';
|
|
|
7
7
|
export * from './lib/pipeable/public_api';
|
|
8
8
|
export * from './lib/pooled';
|
|
9
9
|
export * from './lib/sensors';
|
|
10
|
-
export { isStore,
|
|
10
|
+
export { isStore, mutableStore, opaque, store, toStore, type MutableSignalStore, type Opaque, type SignalStore, type WritableSignalStore, } from './lib/store';
|
|
11
11
|
export * from './lib/stored';
|
|
12
12
|
export { tabSync } from './lib/tabSync';
|
|
13
13
|
export * from './lib/throttled';
|
package/lib/store.d.ts
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { Injector, type CreateSignalOptions, type Signal, type WritableSignal } from '@angular/core';
|
|
2
2
|
import { type MutableSignal } from './mutable';
|
|
3
3
|
import { type Vivify } from './util';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Runtime marker + compile-time brand for an opaque value. A `const`-declared `Symbol`
|
|
6
|
+
* has a `unique symbol` type, so the same symbol serves as both the property key written
|
|
7
|
+
* by {@link opaque} and the type-level brand carried by {@link Opaque}.
|
|
8
|
+
*/
|
|
9
|
+
export declare const OPAQUE: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* An object marked via {@link opaque} — the store treats it as an indivisible leaf
|
|
12
|
+
* (like a `Date`), returning it whole instead of deep-proxying its keys.
|
|
13
|
+
*/
|
|
14
|
+
export type Opaque<T> = T & {
|
|
15
|
+
readonly [OPAQUE]: true;
|
|
16
|
+
};
|
|
17
|
+
/** @internal Strips the opaque brand from the value a leaf signal carries. */
|
|
18
|
+
type Unwrap<T> = T extends {
|
|
19
|
+
readonly [OPAQUE]: true;
|
|
20
|
+
} ? Omit<T, typeof OPAQUE> : T;
|
|
21
|
+
type BaseType = string | number | boolean | symbol | undefined | null | Function | Date | RegExp | {
|
|
22
|
+
readonly [OPAQUE]: true;
|
|
23
|
+
};
|
|
5
24
|
type Key = string | number;
|
|
6
25
|
type AnyRecord = Record<Key, any>;
|
|
7
26
|
/**
|
|
@@ -83,11 +102,11 @@ type MutableSignalStoreObject<T> = Simplify<Readonly<{
|
|
|
83
102
|
<L extends AnyRecord>(props: L): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
|
|
84
103
|
};
|
|
85
104
|
}>;
|
|
86
|
-
export type SignalStore<T> = Signal<T
|
|
87
|
-
export type WritableSignalStore<T> = WritableSignal<T
|
|
105
|
+
export type SignalStore<T> = Signal<Unwrap<T>> & (IsAny<T> extends true ? SignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? SignalArrayStore<NonNullable<T>> : SignalStoreObject<T>);
|
|
106
|
+
export type WritableSignalStore<T> = WritableSignal<Unwrap<T>> & {
|
|
88
107
|
readonly asReadonlyStore: () => SignalStore<T>;
|
|
89
108
|
} & (IsAny<T> extends true ? WritableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? WritableArrayStore<NonNullable<T>> : WritableSignalStoreObject<T>);
|
|
90
|
-
export type MutableSignalStore<T> = MutableSignal<T
|
|
109
|
+
export type MutableSignalStore<T> = MutableSignal<Unwrap<T>> & {
|
|
91
110
|
readonly asReadonlyStore: () => SignalStore<T>;
|
|
92
111
|
} & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
|
|
93
112
|
export declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify): MutableSignalStore<T>;
|
|
@@ -129,4 +148,16 @@ export declare function mutableStore<T extends AnyRecord>(value: T, opt?: Create
|
|
|
129
148
|
*/
|
|
130
149
|
vivify?: Vivify;
|
|
131
150
|
}): MutableSignalStore<T>;
|
|
151
|
+
/**
|
|
152
|
+
* Marks a plain object as opaque so {@link store} treats it as an indivisible leaf
|
|
153
|
+
* (returned whole, never deep-proxied) — the same way it treats a `Date` or `RegExp`.
|
|
154
|
+
* The marker is a non-enumerable symbol, so it never appears in spreads or iteration.
|
|
155
|
+
* Idempotent. Call before freezing (`defineProperty` fails on a frozen object).
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const s = store({ config: opaque({ theme: 'dark', nested: { a: 1 } }) });
|
|
159
|
+
* s.config(); // the whole object, not a child store
|
|
160
|
+
* s.config.set(opaque({ theme: 'light', nested: { a: 2 } }));
|
|
161
|
+
*/
|
|
162
|
+
export declare function opaque<T extends object>(value: T): Opaque<T>;
|
|
132
163
|
export {};
|