@mmstack/primitives 19.3.7 → 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/README.md +52 -0
- package/fesm2022/mmstack-primitives.mjs +330 -55
- package/fesm2022/mmstack-primitives.mjs.map +1 -1
- package/index.d.ts +2 -2
- package/lib/derived.d.ts +17 -7
- package/lib/pooled/index.d.ts +2 -0
- package/lib/{provided-pools.d.ts → pooled/provided-pools.d.ts} +1 -1
- package/lib/store.d.ts +119 -14
- package/lib/util/index.d.ts +2 -0
- package/lib/util/is-index-prop.d.ts +7 -0
- package/lib/util/vivify.d.ts +63 -0
- package/package.json +1 -1
- /package/lib/{pooled.d.ts → pooled/pooled.d.ts} +0 -0
package/index.d.ts
CHANGED
|
@@ -6,12 +6,12 @@ export * from './lib/mappers';
|
|
|
6
6
|
export * from './lib/mutable';
|
|
7
7
|
export * from './lib/pipeable/public_api';
|
|
8
8
|
export * from './lib/pooled';
|
|
9
|
-
export * from './lib/provided-pools';
|
|
10
9
|
export * from './lib/sensors';
|
|
11
|
-
export
|
|
10
|
+
export { isStore, mutableStore, opaque, store, toStore, type MutableSignalStore, type Opaque, type SignalStore, type WritableSignalStore, } from './lib/store';
|
|
12
11
|
export * from './lib/stored';
|
|
13
12
|
export { tabSync } from './lib/tabSync';
|
|
14
13
|
export * from './lib/throttled';
|
|
15
14
|
export * from './lib/to-writable';
|
|
16
15
|
export * from './lib/until';
|
|
16
|
+
export type { Vivify, WithVivify } from './lib/util';
|
|
17
17
|
export * from './lib/with-history';
|
package/lib/derived.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CreateSignalOptions, type WritableSignal } from '@angular/core';
|
|
2
2
|
import { type MutableSignal } from './mutable';
|
|
3
|
+
import { type WithVivify } from './util';
|
|
3
4
|
/**
|
|
4
5
|
* Options for creating a derived signal using the full `derived` function signature.
|
|
5
6
|
* @typeParam T - The type of the source signal's value (parent).
|
|
@@ -62,7 +63,10 @@ export declare function derived<T, U>(source: WritableSignal<T>, opt: CreateDeri
|
|
|
62
63
|
* @typeParam TKey The key of the property to derive.
|
|
63
64
|
* @param source The source `WritableSignal` (holding an object).
|
|
64
65
|
* @param key The key of the property to derive.
|
|
65
|
-
* @param options Optional signal options for the derived signal.
|
|
66
|
+
* @param options Optional signal options for the derived signal. Also accepts a
|
|
67
|
+
* {@link Vivify} `vivify` flag (off by default) that, when set, creates the missing
|
|
68
|
+
* container instead of dropping a write made through a `null`/`undefined` source —
|
|
69
|
+
* e.g. `derived(user, 'name', { vivify: 'object' })`. See {@link WithVivify}.
|
|
66
70
|
* @returns A `DerivedSignal` instance.
|
|
67
71
|
*
|
|
68
72
|
* @example
|
|
@@ -78,7 +82,7 @@ export declare function derived<T, U>(source: WritableSignal<T>, opt: CreateDeri
|
|
|
78
82
|
* console.log(user().name); // Outputs: Jane
|
|
79
83
|
* ```
|
|
80
84
|
*/
|
|
81
|
-
export declare function derived<T extends object, TKey extends keyof T>(source: MutableSignal<T>, key: TKey, opt?: CreateSignalOptions<T[TKey]>): DerivedSignal<T, T[TKey]> & MutableSignal<T[TKey]>;
|
|
85
|
+
export declare function derived<T extends object, TKey extends keyof T>(source: MutableSignal<T>, key: TKey, opt?: CreateSignalOptions<T[TKey]> & WithVivify<T>): DerivedSignal<T, T[TKey]> & MutableSignal<T[TKey]>;
|
|
82
86
|
/**
|
|
83
87
|
* Creates a `DerivedSignal` that derives a property from an object held by the source signal.
|
|
84
88
|
* This overload is a convenient shorthand for accessing object properties.
|
|
@@ -87,7 +91,10 @@ export declare function derived<T extends object, TKey extends keyof T>(source:
|
|
|
87
91
|
* @typeParam TKey The key of the property to derive.
|
|
88
92
|
* @param source The source `WritableSignal` (holding an object).
|
|
89
93
|
* @param key The key of the property to derive.
|
|
90
|
-
* @param options Optional signal options for the derived signal.
|
|
94
|
+
* @param options Optional signal options for the derived signal. Also accepts a
|
|
95
|
+
* {@link Vivify} `vivify` flag (off by default) that, when set, creates the missing
|
|
96
|
+
* container instead of dropping a write made through a `null`/`undefined` source —
|
|
97
|
+
* e.g. `derived(user, 'name', { vivify: 'object' })`. See {@link WithVivify}.
|
|
91
98
|
* @returns A `DerivedSignal` instance.
|
|
92
99
|
*
|
|
93
100
|
* @example
|
|
@@ -103,7 +110,7 @@ export declare function derived<T extends object, TKey extends keyof T>(source:
|
|
|
103
110
|
* console.log(user().name); // Outputs: Jane
|
|
104
111
|
* ```
|
|
105
112
|
*/
|
|
106
|
-
export declare function derived<T extends object, TKey extends keyof T>(source: WritableSignal<T>, key: TKey, opt?: CreateSignalOptions<T[TKey]>): DerivedSignal<T, T[TKey]>;
|
|
113
|
+
export declare function derived<T extends object, TKey extends keyof T>(source: WritableSignal<T>, key: TKey, opt?: CreateSignalOptions<T[TKey]> & WithVivify<T>): DerivedSignal<T, T[TKey]>;
|
|
107
114
|
/**
|
|
108
115
|
* Creates a `DerivedSignal` that derives its value from another `MutableSignal`.
|
|
109
116
|
* Use mutuable signals with caution, but very useful for deeply nested structures.
|
|
@@ -126,7 +133,7 @@ export declare function derived<T extends object, TKey extends keyof T>(source:
|
|
|
126
133
|
* console.log(user().name); // Outputs: Jane
|
|
127
134
|
* ```
|
|
128
135
|
*/
|
|
129
|
-
export declare function derived<T, U>(source: MutableSignal<T>, optOrKey: CreateDerivedOptions<T, U> | keyof T, opt?: CreateSignalOptions<U>): DerivedSignal<T, U> & MutableSignal<U>;
|
|
136
|
+
export declare function derived<T, U>(source: MutableSignal<T>, optOrKey: CreateDerivedOptions<T, U> | keyof T, opt?: CreateSignalOptions<U> & WithVivify<T>): DerivedSignal<T, U> & MutableSignal<U>;
|
|
130
137
|
/**
|
|
131
138
|
* Creates a `DerivedSignal` from an array, deriving an element by its index.
|
|
132
139
|
* This overload is a convenient shorthand for accessing array elements.
|
|
@@ -134,7 +141,10 @@ export declare function derived<T, U>(source: MutableSignal<T>, optOrKey: Create
|
|
|
134
141
|
* @typeParam T The type of the source signal's value (must be an array).
|
|
135
142
|
* @param source The source `WritableSignal` (holding an array).
|
|
136
143
|
* @param index The index of the element to derive.
|
|
137
|
-
* @param options Optional signal options for the derived signal.
|
|
144
|
+
* @param options Optional signal options for the derived signal. Also accepts a
|
|
145
|
+
* {@link Vivify} `vivify` flag (off by default) that, when set, creates the missing
|
|
146
|
+
* container instead of dropping a write made through a `null`/`undefined` source —
|
|
147
|
+
* e.g. `derived(user, 'name', { vivify: 'object' })`. See {@link WithVivify}.
|
|
138
148
|
* @returns A `DerivedSignal` instance.
|
|
139
149
|
*
|
|
140
150
|
* @example
|
|
@@ -150,7 +160,7 @@ export declare function derived<T, U>(source: MutableSignal<T>, optOrKey: Create
|
|
|
150
160
|
* console.log(numbers()); // Outputs: [1, 5, 3]
|
|
151
161
|
* ```
|
|
152
162
|
*/
|
|
153
|
-
export declare function derived<T extends any[]>(source: WritableSignal<T>, index: number, opt?: CreateSignalOptions<T[number]>): DerivedSignal<T, T[number]>;
|
|
163
|
+
export declare function derived<T extends any[]>(source: WritableSignal<T>, index: number, opt?: CreateSignalOptions<T[number]> & WithVivify<T>): DerivedSignal<T, T[number]>;
|
|
154
164
|
/**
|
|
155
165
|
* Creates a "fake" `DerivedSignal` from a simple value. This is useful for creating
|
|
156
166
|
* `FormControlSignal` instances that are not directly derived from another signal.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CreateSignalOptions, Signal } from '@angular/core';
|
|
2
|
-
import { type Computation, type CreatePooledOptions } from '
|
|
2
|
+
import { type Computation, type CreatePooledOptions } from '.';
|
|
3
3
|
/**
|
|
4
4
|
* Options for the preset pool helpers. Same shape as
|
|
5
5
|
* {@link CreatePooledOptions}, with `create` and `reset` made optional — each
|
package/lib/store.d.ts
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
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
|
+
/**
|
|
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
|
+
};
|
|
4
24
|
type Key = string | number;
|
|
5
25
|
type AnyRecord = Record<Key, any>;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
* Test-only handle on the proxy cache (deliberately NOT re-exported from the public barrel).
|
|
29
|
+
* Maps a store's backing signal to its lazily-built child proxies, each held via a `WeakRef`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const PROXY_CACHE: WeakMap<object, Map<PropertyKey, WeakRef<Signal<any>>>>;
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
* Test-only handle on the finalization registry (deliberately NOT re-exported from the public
|
|
35
|
+
* barrel). Prunes a cache entry once its proxy is reclaimed by the GC.
|
|
36
|
+
*/
|
|
37
|
+
export declare const PROXY_CLEANUP: FinalizationRegistry<{
|
|
38
|
+
target: object;
|
|
39
|
+
prop: PropertyKey;
|
|
40
|
+
}>;
|
|
6
41
|
/**
|
|
7
42
|
* @internal
|
|
8
43
|
* Validates whether a value is a Signal Store.
|
|
@@ -25,28 +60,75 @@ type MutableArrayStore<T extends any[]> = MutableSignal<T> & {
|
|
|
25
60
|
readonly length: Signal<number>;
|
|
26
61
|
[Symbol.iterator](): Iterator<MutableSignalStore<T[number]>>;
|
|
27
62
|
};
|
|
28
|
-
|
|
63
|
+
/**
|
|
64
|
+
* @internal Resolves to `true` only for `any`. In a conditional type, `any` distributes across
|
|
65
|
+
* *both* branches (`unknown | object`), and `unknown | X` collapses to `unknown` — which would
|
|
66
|
+
* erase a store's property access and `extend`. Guarding on this routes an `any`-typed store to
|
|
67
|
+
* the full object shape instead.
|
|
68
|
+
*/
|
|
69
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
70
|
+
/**
|
|
71
|
+
* @internal Flattens an intersection (`A & B & C`) into a single object literal so editor
|
|
72
|
+
* tooltips show the resolved members instead of the raw intersection chain. Display-only —
|
|
73
|
+
* structurally identical to its input.
|
|
74
|
+
*/
|
|
75
|
+
type Simplify<T> = {
|
|
76
|
+
[K in keyof T]: T[K];
|
|
77
|
+
} & {};
|
|
78
|
+
/** @internal The object shape of a readonly store: a child store per key, plus `extend`. */
|
|
79
|
+
type SignalStoreObject<T> = Simplify<Readonly<{
|
|
29
80
|
[K in keyof Required<T>]: SignalStore<NonNullable<T>[K]>;
|
|
30
|
-
}>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
81
|
+
}> & {
|
|
82
|
+
readonly extend: {
|
|
83
|
+
<L extends AnyRecord>(source: Signal<L>): SignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
|
|
84
|
+
<L extends AnyRecord>(props: L): SignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
|
|
85
|
+
};
|
|
86
|
+
}>;
|
|
87
|
+
/** @internal The object shape of a writable store. */
|
|
88
|
+
type WritableSignalStoreObject<T> = Simplify<Readonly<{
|
|
34
89
|
[K in keyof Required<T>]: WritableSignalStore<NonNullable<T>[K]>;
|
|
35
|
-
}>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
90
|
+
}> & {
|
|
91
|
+
readonly extend: {
|
|
92
|
+
<L extends AnyRecord>(source: WritableSignal<L>): WritableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
|
|
93
|
+
<L extends AnyRecord>(props: L): WritableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
|
|
94
|
+
};
|
|
95
|
+
}>;
|
|
96
|
+
/** @internal The object shape of a mutable store. */
|
|
97
|
+
type MutableSignalStoreObject<T> = Simplify<Readonly<{
|
|
39
98
|
[K in keyof Required<T>]: MutableSignalStore<NonNullable<T>[K]>;
|
|
40
|
-
}>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
99
|
+
}> & {
|
|
100
|
+
readonly extend: {
|
|
101
|
+
<L extends AnyRecord>(source: MutableSignal<L>): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
|
|
102
|
+
<L extends AnyRecord>(props: L): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
|
|
103
|
+
};
|
|
104
|
+
}>;
|
|
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>> & {
|
|
107
|
+
readonly asReadonlyStore: () => SignalStore<T>;
|
|
108
|
+
} & (IsAny<T> extends true ? WritableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? WritableArrayStore<NonNullable<T>> : WritableSignalStoreObject<T>);
|
|
109
|
+
export type MutableSignalStore<T> = MutableSignal<Unwrap<T>> & {
|
|
110
|
+
readonly asReadonlyStore: () => SignalStore<T>;
|
|
111
|
+
} & (IsAny<T> extends true ? MutableSignalStoreObject<T> : NonNullable<T> extends BaseType ? unknown : NonNullable<T> extends Array<any> ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
|
|
112
|
+
export declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify): MutableSignalStore<T>;
|
|
113
|
+
export declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, injector?: Injector, vivify?: Vivify): WritableSignalStore<T>;
|
|
114
|
+
export declare function toStore<T extends AnyRecord>(source: Signal<T>, injector?: Injector, vivify?: Vivify): SignalStore<T>;
|
|
44
115
|
/**
|
|
45
116
|
* Creates a WritableSignalStore from a value.
|
|
46
117
|
* @see {@link toStore}
|
|
47
118
|
*/
|
|
48
119
|
export declare function store<T extends AnyRecord>(value: T, opt?: CreateSignalOptions<T> & {
|
|
49
120
|
injector?: Injector;
|
|
121
|
+
/**
|
|
122
|
+
* Opt-in autovivification: when writing through a `null`/`undefined` path, create the
|
|
123
|
+
* missing intermediate containers instead of dropping the write. Off by default.
|
|
124
|
+
*
|
|
125
|
+
* Levels whose current value is a known object/array re-vivify as that same shape — the
|
|
126
|
+
* knowledge is captured when the path is first accessed and cached, so it holds even after
|
|
127
|
+
* the value is later nulled. This option governs only genuinely-unknown (currently
|
|
128
|
+
* `null`/`undefined`) levels: `'auto'` (an array for index keys, an object otherwise), an
|
|
129
|
+
* explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
|
|
130
|
+
*/
|
|
131
|
+
vivify?: Vivify;
|
|
50
132
|
}): WritableSignalStore<T>;
|
|
51
133
|
/**
|
|
52
134
|
* Creates a MutableSignalStore from a value.
|
|
@@ -54,5 +136,28 @@ export declare function store<T extends AnyRecord>(value: T, opt?: CreateSignalO
|
|
|
54
136
|
*/
|
|
55
137
|
export declare function mutableStore<T extends AnyRecord>(value: T, opt?: CreateSignalOptions<T> & {
|
|
56
138
|
injector?: Injector;
|
|
139
|
+
/**
|
|
140
|
+
* Opt-in autovivification: when writing through a `null`/`undefined` path, create the
|
|
141
|
+
* missing intermediate containers instead of dropping the write. Off by default.
|
|
142
|
+
*
|
|
143
|
+
* Levels whose current value is a known object/array re-vivify as that same shape — the
|
|
144
|
+
* knowledge is captured when the path is first accessed and cached, so it holds even after
|
|
145
|
+
* the value is later nulled. This option governs only genuinely-unknown (currently
|
|
146
|
+
* `null`/`undefined`) levels: `'auto'` (an array for index keys, an object otherwise), an
|
|
147
|
+
* explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
|
|
148
|
+
*/
|
|
149
|
+
vivify?: Vivify;
|
|
57
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>;
|
|
58
163
|
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* Type guard for an array-index-like property key: a non-empty string that parses to a finite
|
|
4
|
+
* number (e.g. `'0'`, `'42'`). Used to choose array-vs-object shape during autovivification and
|
|
5
|
+
* deep store proxying.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isIndexProp(prop: PropertyKey): prop is `${number}`;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** @internal Narrows `'array'` so it is only assignable when `T` is an array type. */
|
|
2
|
+
type VivifyArray<T> = T extends any[] ? 'array' : never;
|
|
3
|
+
/** @internal Narrows `'object'` so it is only assignable when `T` is an object type. */
|
|
4
|
+
type VivifyObject<T> = T extends object ? 'object' : never;
|
|
5
|
+
/**
|
|
6
|
+
* Controls **autovivification** — whether, and as what shape, a writable `derived` (or `store`)
|
|
7
|
+
* creates a missing container when the source value is `null`/`undefined` at the moment of a
|
|
8
|
+
* write. Without it, writing through a nullish value is a no-op; with it, a deep write such as
|
|
9
|
+
* `derived(user, 'name', { vivify: 'object' }).set('Ada')` materializes the missing object
|
|
10
|
+
* instead of silently dropping the write.
|
|
11
|
+
*
|
|
12
|
+
* A **present** value is always preserved — updated in place for a `MutableSignal` source,
|
|
13
|
+
* copied for an immutable one. Vivification only ever *creates*, it never *replaces*.
|
|
14
|
+
*
|
|
15
|
+
* Variants:
|
|
16
|
+
* - `false` — **default.** Off; a write through a nullish source does nothing.
|
|
17
|
+
* - `true` / `'auto'` — infer the shape from the key: an array (`[]`) for a numeric / index key,
|
|
18
|
+
* a plain object (`{}`) otherwise.
|
|
19
|
+
* - `'object'` — always create a plain object (`{}`). Only assignable when `T` is an object.
|
|
20
|
+
* - `'array'` — always create an array (`[]`). Only assignable when `T` is an array.
|
|
21
|
+
* - `() => T` — a factory producing the container to create. Called only on a nullish source,
|
|
22
|
+
* once per vivification (a fresh instance each time), so a present value is never clobbered.
|
|
23
|
+
* Useful for seeding defaults, e.g. `() => ({ items: [], total: 0 })`.
|
|
24
|
+
*
|
|
25
|
+
* @typeParam T - The type of the container that may be created (the source/parent value).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const user = signal<{ name: string } | null>(null);
|
|
30
|
+
*
|
|
31
|
+
* derived(user, 'name').set('Ada'); // off: dropped, user() === null
|
|
32
|
+
* derived(user, 'name', { vivify: 'object' }).set('Ada'); // user() === { name: 'Ada' }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export type Vivify<T = any> = 'auto' | boolean | (() => T) | VivifyArray<T> | VivifyObject<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Options mix-in that adds an optional {@link Vivify} setting to the `options` argument of the
|
|
38
|
+
* `derived` / `store` key & index overloads.
|
|
39
|
+
*
|
|
40
|
+
* @typeParam T - The type of the container that may be vivified (the source/parent value).
|
|
41
|
+
*/
|
|
42
|
+
export type WithVivify<T> = {
|
|
43
|
+
/**
|
|
44
|
+
* Whether, and as what shape, to create a missing container when the source value is
|
|
45
|
+
* `null`/`undefined` at write time. Defaults to `false` (no vivification). See {@link Vivify}.
|
|
46
|
+
*/
|
|
47
|
+
vivify?: Vivify<T>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
* A resolved vivification function, produced by {@link createVivify}. Given the `current` value
|
|
52
|
+
* and the `key` about to be written, it returns the container to write into: the current value
|
|
53
|
+
* when present, or a freshly created one when `current` is `null`/`undefined`.
|
|
54
|
+
*/
|
|
55
|
+
export type VivifyFn<T> = (current: T, key: PropertyKey) => T;
|
|
56
|
+
/**
|
|
57
|
+
* @internal
|
|
58
|
+
* Resolves a {@link Vivify} option into a {@link VivifyFn}. The returned function leaves a
|
|
59
|
+
* present value untouched and only creates a new container — object, array, or factory result —
|
|
60
|
+
* when the current value is `null`/`undefined`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createVivify<T>(option: Vivify<T>): VivifyFn<T>;
|
|
63
|
+
export {};
|
package/package.json
CHANGED
|
File without changes
|