@expressive/mvc 0.88.0 → 0.89.0
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 +18 -18
- package/dist/component.d.ts +11 -19
- package/dist/component.js +5 -51
- package/dist/component.js.map +1 -1
- package/dist/context.d.ts +27 -27
- package/dist/context.js +18 -18
- package/dist/context.js.map +1 -1
- package/dist/field/def.d.ts +3 -3
- package/dist/field/def.js +6 -6
- package/dist/field/def.js.map +1 -1
- package/dist/field/get.d.ts +16 -16
- package/dist/field/get.js +3 -3
- package/dist/field/get.js.map +1 -1
- package/dist/field/has.d.ts +8 -8
- package/dist/field/has.js +3 -3
- package/dist/field/has.js.map +1 -1
- package/dist/field/map.d.ts +2 -2
- package/dist/field/map.js +2 -2
- package/dist/field/map.js.map +1 -1
- package/dist/field/ref.d.ts +8 -8
- package/dist/field/ref.js +3 -3
- package/dist/field/ref.js.map +1 -1
- package/dist/field/set.js.map +1 -1
- package/dist/hot.d.ts +4 -4
- package/dist/hot.js +7 -11
- package/dist/hot.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/jsx-runtime.js +1 -3
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/observable.d.ts +7 -4
- package/dist/observable.js +94 -27
- package/dist/observable.js.map +1 -1
- package/dist/state.d.ts +110 -96
- package/dist/state.js +53 -39
- package/dist/state.js.map +1 -1
- package/package.json +1 -1
package/dist/state.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { event } from "./observable.js";
|
|
|
3
3
|
|
|
4
4
|
//#region src/state.d.ts
|
|
5
5
|
/** Internal state assigned to states. */
|
|
6
|
-
declare const STORE: WeakMap<
|
|
7
|
-
/**
|
|
6
|
+
declare const STORE: WeakMap<Model, Record<string | number | symbol, unknown>>;
|
|
7
|
+
/** Models under construction - added on `new`, removed when activated or released.
|
|
8
8
|
* Also carries work to run at the deadline, which `def` uses to bound its registry. */
|
|
9
|
-
declare const PENDING: Set<
|
|
10
|
-
/** External lifecycle listeners for any given
|
|
11
|
-
type Handler =
|
|
12
|
-
declare const SETUP: WeakMap<
|
|
9
|
+
declare const PENDING: Set<Model | (() => void)>;
|
|
10
|
+
/** External lifecycle listeners for any given Model class. */
|
|
11
|
+
type Handler = Model.On<any>;
|
|
12
|
+
declare const SETUP: WeakMap<Model.Extends<Model>, Set<Handler>>;
|
|
13
13
|
/** Reference bound instance methods, or their getter, to real one. */
|
|
14
14
|
declare const UNBIND: WeakMap<any, any>;
|
|
15
15
|
/** List of methods defined by a given type. */
|
|
@@ -18,43 +18,44 @@ declare const METHODS: WeakMap<Function, Map<string, (value: any) => void>>;
|
|
|
18
18
|
declare const GETTERS: WeakMap<Function, Map<string, () => unknown>>;
|
|
19
19
|
/** Replacement for a getter captured by live computed properties, for hot patching. */
|
|
20
20
|
declare const LATEST: WeakMap<Function, Function>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
type Overlay<T> = Record<string, unknown> & { [K in Model.Property<T>]?: T[K] extends ((...args: infer A) => infer R) ? (this: T, ...args: A) => R : T[K] };
|
|
22
|
+
declare namespace Model {
|
|
23
|
+
/** Any type of Model, using own class constructor as its identifier. */
|
|
24
|
+
type Extends<T extends Model = Model> = (abstract new (...args: any[]) => T) & typeof Model;
|
|
25
|
+
/** A Model constructor which may be instanciated. */
|
|
26
|
+
type Type<T extends Model = Model> = (new (...args: Model.Args<T>) => T) & Omit<typeof Model, never>;
|
|
27
|
+
/** Model constructor arguments */
|
|
28
|
+
type Args<T extends Model = any> = (Args<T> | Init<T> | Overlay<T> | void)[];
|
|
28
29
|
/**
|
|
29
|
-
* Value of `static global`. A boolean opts a
|
|
30
|
+
* Value of `static global`. A boolean opts a Model in or out of the
|
|
30
31
|
* process-global root; a resolver decides at activation, receiving the
|
|
31
32
|
* instance and returning whether it registers - use it to make the choice
|
|
32
33
|
* conditional (e.g. per environment). A bare literal (`= true` / `= false`)
|
|
33
34
|
* seals the choice for subclasses; widen a subclass's `static global` type to
|
|
34
|
-
* `
|
|
35
|
+
* `Model.Global` to permit a resolver or a later override.
|
|
35
36
|
*/
|
|
36
|
-
type Global<T extends
|
|
37
|
+
type Global<T extends Model = any> = boolean | ((self: T) => boolean);
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
+
* Model constructor callback - runs during activation, in argument order,
|
|
39
40
|
* before the `new()` lifecycle hook (so it may configure state `new()`
|
|
40
41
|
* will observe). Returned function will run when state is destroyed.
|
|
41
42
|
*/
|
|
42
|
-
type Init<T extends
|
|
43
|
-
/** Lifecycle handlers for `
|
|
44
|
-
interface On<T extends
|
|
43
|
+
type Init<T extends Model = Model> = (this: T, thisArg: T) => Promise<void> | (() => void) | Args<T> | Overlay<T> | void;
|
|
44
|
+
/** Lifecycle handlers for `Model.on`, keyed by when they run. */
|
|
45
|
+
interface On<T extends Model = Model> {
|
|
45
46
|
/**
|
|
46
47
|
* Per-class setup, run once when the class is first bootstrapped - before
|
|
47
48
|
* its members are classified and bound. Receives the class, so a handler
|
|
48
49
|
* may inspect or reshape the prototype first. A handler registered on a
|
|
49
50
|
* base class runs for each subclass too.
|
|
50
51
|
*/
|
|
51
|
-
type?(type:
|
|
52
|
+
type?(type: Model.Extends<T>): void;
|
|
52
53
|
/**
|
|
53
54
|
* Per-instance, once constructed - before own values are observed and
|
|
54
55
|
* before constructor args and `new()`. May return a cleanup, constructor
|
|
55
56
|
* args, or an assign overlay.
|
|
56
57
|
*/
|
|
57
|
-
setup?(this: T, self: T): void | (() => void) | Promise<void> | Args<T> |
|
|
58
|
+
setup?(this: T, self: T): void | (() => void) | Promise<void> | Args<T> | Overlay<T>;
|
|
58
59
|
/**
|
|
59
60
|
* Per-instance, once ready - after own values are observed, constructor
|
|
60
61
|
* args applied and `new()` has run. May return a cleanup function.
|
|
@@ -67,7 +68,7 @@ declare namespace State {
|
|
|
67
68
|
*/
|
|
68
69
|
method?(this: T, key: string, fn: Function, self: T): void;
|
|
69
70
|
/**
|
|
70
|
-
* Receives what an effect, refreshing getter or async initializer of this
|
|
71
|
+
* Receives what an effect, refreshing getter or async initializer of this Model
|
|
71
72
|
* or a subclass threw, a destroyed write, or an instance never activated - with
|
|
72
73
|
* its `kind` (`effect`, `getter`, `setup`, `dead`, `unused`) and `key` where
|
|
73
74
|
* one applies. Most-derived class first, last registered first, each once. Return the error
|
|
@@ -78,17 +79,17 @@ declare namespace State {
|
|
|
78
79
|
catch?(this: T, error: unknown, kind: 'effect' | 'getter' | 'setup' | 'dead' | 'unused', key?: string): unknown;
|
|
79
80
|
}
|
|
80
81
|
/** Object overlay to override values and methods on a state. */
|
|
81
|
-
type Assign<T> = Record<string, unknown> & { [K in Property<T>]?: T[K]
|
|
82
|
-
/** Subset of `keyof T` not defined by base
|
|
83
|
-
type Property<T> = Exclude<keyof T, keyof
|
|
82
|
+
type Assign<T> = Record<string, unknown> & { [K in Property<T>]?: T[K] } & ThisType<T>;
|
|
83
|
+
/** Subset of `keyof T` not defined by base Model. **/
|
|
84
|
+
type Property<T> = Exclude<keyof T, keyof Model>;
|
|
84
85
|
/** Managed subset of Property<T> - excludes unmanaged `_` keys. **/
|
|
85
86
|
type Field<T> = Exclude<Property<T>, `_${string}`>;
|
|
86
87
|
/** Any valid key for state, including but not limited to Field<T>. */
|
|
87
|
-
type Event<T =
|
|
88
|
+
type Event<T = Model> = Field<T> | number | symbol | (string & {});
|
|
88
89
|
/** Any event signal dispatched to listeners, including lifecycle meta events. */
|
|
89
|
-
type Signal<T =
|
|
90
|
-
/** Export/Import compatible value for a given property in a
|
|
91
|
-
type Export<R> = R extends
|
|
90
|
+
type Signal<T = Model> = Event<T> | true | false | null;
|
|
91
|
+
/** Export/Import compatible value for a given property in a Model. */
|
|
92
|
+
type Export<R> = R extends Model ? Values<R> : R extends {
|
|
92
93
|
get(): infer T;
|
|
93
94
|
} ? T : R;
|
|
94
95
|
/**
|
|
@@ -100,18 +101,18 @@ declare namespace State {
|
|
|
100
101
|
/** Object comperable to data found in T. */
|
|
101
102
|
type Partial<T> = { [P in Field<T>]?: Export<T[P]> };
|
|
102
103
|
/** Value for a property applied by a state. */
|
|
103
|
-
type Value<T extends
|
|
104
|
+
type Value<T extends Model, K extends Model.Event<T>> = K extends keyof T ? Export<T[K]> : unknown;
|
|
104
105
|
type Setter<T> = (value: T, previous: T) => T | void;
|
|
105
106
|
/** Descriptor config for a managed property. */
|
|
106
107
|
type Apply<T = any> = {
|
|
107
108
|
value?: T;
|
|
108
|
-
get?: ((source:
|
|
109
|
+
get?: ((source: Model) => T) | boolean;
|
|
109
110
|
set?: Setter<T> | boolean;
|
|
110
111
|
enumerable?: boolean;
|
|
111
112
|
};
|
|
112
113
|
/** Descriptor config for set() overload - enforces type when key is a known field. */
|
|
113
114
|
type Define<T, K> = K extends Field<T> ? Apply<T[K] | Export<T[K]>> : Apply;
|
|
114
|
-
type OnEvent<T extends
|
|
115
|
+
type OnEvent<T extends Model> = (this: T, key: Signal<T>, source: T) => void | (() => void) | null;
|
|
115
116
|
/** Exotic value, where actual value is contained within. */
|
|
116
117
|
type Ref<T = any> = {
|
|
117
118
|
(next: T): void;
|
|
@@ -127,7 +128,13 @@ declare namespace State {
|
|
|
127
128
|
*
|
|
128
129
|
* @returns A callback function which will be called when this effect is stale.
|
|
129
130
|
*/
|
|
130
|
-
type Effect<T> = (this: T, current: T, update: readonly
|
|
131
|
+
type Effect<T, R = EffectCallback | Promise<void> | null | void> = (this: T, current: T, update: readonly Model.Event<T>[] | undefined) => R;
|
|
132
|
+
/**
|
|
133
|
+
* Returned by `get(effect)`. Call to stop the effect. Await to stop it once it
|
|
134
|
+
* has run clean and receive that run's value - a sync run's output, or what its
|
|
135
|
+
* promise resolved to.
|
|
136
|
+
*/
|
|
137
|
+
type Release<R = void> = (() => void) & PromiseLike<R>;
|
|
131
138
|
/**
|
|
132
139
|
* A callback function returned by effect. Will be called when effect is stale.
|
|
133
140
|
*
|
|
@@ -138,29 +145,29 @@ declare namespace State {
|
|
|
138
145
|
* A list of keys updated, or events fired, since last update.
|
|
139
146
|
* This may be awaited to get full list (same array) when update is settled.
|
|
140
147
|
*/
|
|
141
|
-
type Updated<T extends
|
|
148
|
+
type Updated<T extends Model> = readonly Event<T>[] & PromiseLike<readonly Event<T>[]>;
|
|
142
149
|
}
|
|
143
|
-
declare abstract class
|
|
150
|
+
declare abstract class Model {
|
|
144
151
|
/**
|
|
145
152
|
* Whether an instance activated with no enclosing context registers itself
|
|
146
153
|
* to the process-global root, where `get()` can resolve it from anywhere.
|
|
147
154
|
* `false` (the default) keeps a context-less instance fully functional but
|
|
148
155
|
* private - not injectable, though it can still read declared globals. Opt in
|
|
149
|
-
* with `static readonly global = true`; a resolver (see {@link
|
|
156
|
+
* with `static readonly global = true`; a resolver (see {@link Model.Global})
|
|
150
157
|
* makes the choice conditional. It must be declared per class - a subclass
|
|
151
158
|
* that would inherit a global without its own declaration throws on
|
|
152
|
-
* activation, so an accidental global (a forgotten
|
|
153
|
-
* global) cannot leak into the shared root.
|
|
159
|
+
* activation, so an accidental global (a forgotten `<Component for>`, an
|
|
160
|
+
* extended global) cannot leak into the shared root.
|
|
154
161
|
*/
|
|
155
|
-
static readonly global:
|
|
162
|
+
static readonly global: Model.Global;
|
|
156
163
|
/**
|
|
157
164
|
* Loopback to instance of this state. This is useful when in a subscribed context,
|
|
158
165
|
* to keep write access to `this` after a destructure. You can use it to read variables silently as well.
|
|
159
166
|
**/
|
|
160
167
|
is: this;
|
|
161
|
-
constructor(...args:
|
|
168
|
+
constructor(...args: Model.Args);
|
|
162
169
|
/**
|
|
163
|
-
* Optional lifecycle hook called during
|
|
170
|
+
* Optional lifecycle hook called during Model initialization.
|
|
164
171
|
* Can return a cleanup function to run when state is destroyed.
|
|
165
172
|
*
|
|
166
173
|
* It is recommended you protect this method.
|
|
@@ -171,16 +178,23 @@ declare abstract class State {
|
|
|
171
178
|
*
|
|
172
179
|
* @returns Object with all values from this state.
|
|
173
180
|
**/
|
|
174
|
-
get():
|
|
181
|
+
get(): Model.Values<this>;
|
|
175
182
|
/**
|
|
176
183
|
* Run a function to run automatically when accessed values change.
|
|
177
184
|
*
|
|
178
185
|
* @param effect Function to run, and whenever accessed values change.
|
|
179
186
|
* If effect returns a function, it will be called when a change occurs (syncronously),
|
|
180
|
-
* effect is cancelled, or parent state is destroyed.
|
|
181
|
-
*
|
|
187
|
+
* effect is cancelled, or parent state is destroyed. A returned promise
|
|
188
|
+
* defers re-runs until it settles; its resolved value is treated the same way.
|
|
189
|
+
* @returns Function to cancel listener - awaited, cancels and yields the effect's value.
|
|
190
|
+
*/
|
|
191
|
+
get(effect: Model.Effect<this>): Model.Release;
|
|
192
|
+
/**
|
|
193
|
+
* Run a function to run automatically when accessed values change, which
|
|
194
|
+
* produces a value - sync or async. Await the returned function to cancel the
|
|
195
|
+
* effect once a run completes and receive what it returned.
|
|
182
196
|
*/
|
|
183
|
-
get(effect:
|
|
197
|
+
get<R>(effect: Model.Effect<this, Promise<R>>): Model.Release<R>;
|
|
184
198
|
/**
|
|
185
199
|
* Get value of a property. Will fetch underlying value from exotic values like ref.Object.
|
|
186
200
|
*
|
|
@@ -190,7 +204,7 @@ declare abstract class State {
|
|
|
190
204
|
* @param required - If true, will throw an error if property is not available.
|
|
191
205
|
* @returns Value of property.
|
|
192
206
|
*/
|
|
193
|
-
get<T extends
|
|
207
|
+
get<T extends Model.Event<this>>(key: T, required?: boolean): Model.Value<this, T>;
|
|
194
208
|
/**
|
|
195
209
|
* Check if state is destroyed.
|
|
196
210
|
*
|
|
@@ -205,42 +219,42 @@ declare abstract class State {
|
|
|
205
219
|
* @returns Function to cancel listener.
|
|
206
220
|
*/
|
|
207
221
|
get(status: null, callback: () => void): () => void;
|
|
208
|
-
/** Fetch
|
|
209
|
-
get<T extends
|
|
210
|
-
/** Fetch a
|
|
211
|
-
get<T extends
|
|
222
|
+
/** Fetch Model of type from context. Throws if not found. */
|
|
223
|
+
get<T extends Model>(type: Model.Type<T>, required?: true): T;
|
|
224
|
+
/** Fetch a Model from context. Undefined if not found. */
|
|
225
|
+
get<T extends Model>(type: Model.Type<T>, required: boolean): T | undefined;
|
|
212
226
|
/**
|
|
213
|
-
* Subscribe to
|
|
227
|
+
* Subscribe to Model becoming available in context.
|
|
214
228
|
*
|
|
215
229
|
* Will search both up and downstream by default.
|
|
216
|
-
* Normally you can ignore this because
|
|
230
|
+
* Normally you can ignore this because Model you expect is rarely both.
|
|
217
231
|
*
|
|
218
|
-
* Specify downstream if you only want to watch for
|
|
232
|
+
* Specify downstream if you only want to watch for Model in children, which can be useful if you expect multiple of the same Model in different branches of the tree.
|
|
219
233
|
*
|
|
220
|
-
* @param type - Type of
|
|
221
|
-
* @param callback - Function to call when
|
|
222
|
-
* @param downstream - If true, will only watch for
|
|
234
|
+
* @param type - Type of Model to watch for.
|
|
235
|
+
* @param callback - Function to call when Model is found. Will be called immediately if Model is already available.
|
|
236
|
+
* @param downstream - If true, will only watch for Model in children, if false will only for parents.
|
|
223
237
|
* @returns Function to cancel listener.
|
|
224
238
|
*/
|
|
225
|
-
get<T extends
|
|
226
|
-
/** Owner of this
|
|
227
|
-
get<T extends typeof
|
|
228
|
-
/** Owner of this
|
|
229
|
-
get<T extends typeof
|
|
239
|
+
get<T extends Model>(type: Model.Type<T>, callback: Context.Expect<T>, downstream?: boolean): () => void;
|
|
240
|
+
/** Owner of this Model. Throws if it has none. */
|
|
241
|
+
get<T extends typeof Model>(type: T & (typeof Model extends T ? unknown : never), required?: true): Model;
|
|
242
|
+
/** Owner of this Model. Undefined if it has none. */
|
|
243
|
+
get<T extends typeof Model>(type: T & (typeof Model extends T ? unknown : never), required: boolean): Model | undefined;
|
|
230
244
|
/**
|
|
231
|
-
* Run a callback for each
|
|
232
|
-
* one as it activates. Callback may return a function, called when that
|
|
245
|
+
* Run a callback for each Model this one owns - those owned now, then each
|
|
246
|
+
* one as it activates. Callback may return a function, called when that Model
|
|
233
247
|
* is destroyed.
|
|
234
248
|
*
|
|
235
249
|
* @returns Function to stop watching.
|
|
236
250
|
*/
|
|
237
|
-
get<T extends typeof
|
|
251
|
+
get<T extends typeof Model>(type: T & (typeof Model extends T ? unknown : never), callback: (child: Model) => void | (() => void), downstream: true): () => void;
|
|
238
252
|
/**
|
|
239
253
|
* Get update in progress.
|
|
240
254
|
*
|
|
241
255
|
* @returns Promise which resolves object with updated values, `undefined` if there no update is pending.
|
|
242
256
|
**/
|
|
243
|
-
set():
|
|
257
|
+
set(): Model.Updated<this>;
|
|
244
258
|
/**
|
|
245
259
|
* Merge argument with current state, updating one or more properties at once.
|
|
246
260
|
* Properties which are not managed by this state will be ignored.
|
|
@@ -249,7 +263,7 @@ declare abstract class State {
|
|
|
249
263
|
* @param silent - If true, listeners will not be notified. If state is destroyed, stores the update without reporting it.
|
|
250
264
|
* @returns Array of keys updated, syncronously contains keys updated immediately and may be resolved (to itself) when all updates are settled.
|
|
251
265
|
*/
|
|
252
|
-
set(assign?:
|
|
266
|
+
set(assign?: Model.Assign<this>, silent?: boolean): Model.Updated<this>;
|
|
253
267
|
/**
|
|
254
268
|
* Call a function when update occurs.
|
|
255
269
|
*
|
|
@@ -263,7 +277,7 @@ declare abstract class State {
|
|
|
263
277
|
* @param callback - Function to call when update occurs.
|
|
264
278
|
* @returns Function to remove listener. Will return `true` if removed, `false` if inactive already.
|
|
265
279
|
*/
|
|
266
|
-
set(callback:
|
|
280
|
+
set(callback: Model.OnEvent<this>): () => boolean;
|
|
267
281
|
/**
|
|
268
282
|
* Push an update. This will not change the value of associated property.
|
|
269
283
|
*
|
|
@@ -278,7 +292,7 @@ declare abstract class State {
|
|
|
278
292
|
* @param key - Property or event to dispatch.
|
|
279
293
|
* @returns Promise resolves an array of keys updated.
|
|
280
294
|
*/
|
|
281
|
-
set(key:
|
|
295
|
+
set(key: Model.Event<this>): Model.Updated<this>;
|
|
282
296
|
/**
|
|
283
297
|
* Declare an end to updates. This event is final - later writes are stored but never dispatched.
|
|
284
298
|
* This event can be watched for as well, to run cleanup logic and internally will remove all listeners.
|
|
@@ -295,7 +309,7 @@ declare abstract class State {
|
|
|
295
309
|
* @param callback - Function to call when event occurs.
|
|
296
310
|
* @returns Function to remove listener.
|
|
297
311
|
*/
|
|
298
|
-
set<K extends
|
|
312
|
+
set<K extends Model.Event<this>>(event: K | null, callback: Model.OnEvent<this>): () => boolean;
|
|
299
313
|
/**
|
|
300
314
|
* Define or update a managed property using a descriptor config.
|
|
301
315
|
* If the property already is managed, config will only accept value.
|
|
@@ -305,9 +319,9 @@ declare abstract class State {
|
|
|
305
319
|
* @param config - Descriptor config with value, get, set, enumerable, and/or destroy.
|
|
306
320
|
* @returns Promise resolves an array of keys updated.
|
|
307
321
|
*/
|
|
308
|
-
set<K extends
|
|
322
|
+
set<K extends Model.Event<this>>(key: K, config: Model.Define<this, K>): Model.Updated<this>;
|
|
309
323
|
/**
|
|
310
|
-
* Iterate over managed properties in this instance of
|
|
324
|
+
* Iterate over managed properties in this instance of Model.
|
|
311
325
|
* Yeilds the key and current value for each property.
|
|
312
326
|
*/
|
|
313
327
|
[Symbol.iterator](): Iterator<[string, unknown]>;
|
|
@@ -318,16 +332,16 @@ declare abstract class State {
|
|
|
318
332
|
*
|
|
319
333
|
* @param args - arguments sent to constructor
|
|
320
334
|
*/
|
|
321
|
-
static new<T extends
|
|
335
|
+
static new<T extends Model>(this: Model.Type<T>, ...args: Model.Args<T>): T;
|
|
322
336
|
/**
|
|
323
337
|
* Static equivalent of `x instanceof this`.
|
|
324
338
|
* Determines if provided class is a subtype of this one.
|
|
325
339
|
* If so, language server will make available all static
|
|
326
340
|
* methods and properties of this class.
|
|
327
341
|
*/
|
|
328
|
-
static is<T extends
|
|
342
|
+
static is<T extends Model.Extends>(this: T, maybe: unknown): maybe is T;
|
|
329
343
|
/**
|
|
330
|
-
* Register a lifecycle handler for this
|
|
344
|
+
* Register a lifecycle handler for this Model and its subclasses.
|
|
331
345
|
*
|
|
332
346
|
* Hooks by cadence - `type` (per-class, at bootstrap), `setup` (per-instance,
|
|
333
347
|
* before values are observed), `ready` (per-instance, after `new()`), and
|
|
@@ -336,11 +350,11 @@ declare abstract class State {
|
|
|
336
350
|
*
|
|
337
351
|
* @returns Function to remove the handler.
|
|
338
352
|
*/
|
|
339
|
-
static on<T extends
|
|
340
|
-
static on<T extends
|
|
353
|
+
static on<T extends Model>(this: Model.Extends<T>, setup: NonNullable<Model.On<T>['setup']>): () => boolean;
|
|
354
|
+
static on<T extends Model>(this: Model.Extends<T>, handler: Model.On<T>): () => boolean;
|
|
341
355
|
}
|
|
342
356
|
/** Bind own configurable methods of a type and collect its reactive getters. */
|
|
343
|
-
declare function classify(type:
|
|
357
|
+
declare function classify(type: Model.Extends, keys: Map<string, (value: any) => void>, getters: Map<string, () => unknown>): void;
|
|
344
358
|
/**
|
|
345
359
|
* Install a reactive computed property on a state instance, derived from a prototype
|
|
346
360
|
* getter or an arity-bearing `set` factory.
|
|
@@ -349,34 +363,34 @@ declare function classify(type: State.Extends, keys: Map<string, (value: any) =>
|
|
|
349
363
|
* reads of managed properties through it create subscriptions. Result is cached and
|
|
350
364
|
* emits a keyed event when stale.
|
|
351
365
|
*/
|
|
352
|
-
declare function compute(this:
|
|
366
|
+
declare function compute(this: Model, getter: (self: any) => unknown, key: string): void;
|
|
353
367
|
/**
|
|
354
368
|
* Define or update a managed property using a descriptor config.
|
|
355
369
|
* If the property already is managed, config will only accept value.
|
|
356
370
|
* If the property does not exist, it will be created and made reactive.
|
|
357
371
|
*
|
|
358
|
-
* @param state -
|
|
372
|
+
* @param state - Model to apply property to.
|
|
359
373
|
* @param key - Property to define or update.
|
|
360
374
|
* @param config - Descriptor config with value, get, set, enumerable, and/or destroy.
|
|
361
375
|
* @param silent - If an update does occur, listeners will not be refreshed automatically.
|
|
362
376
|
*/
|
|
363
|
-
declare function apply(state:
|
|
377
|
+
declare function apply(state: Model, key: string, config: Model.Apply, silent?: boolean): void;
|
|
364
378
|
/**
|
|
365
|
-
* Pending
|
|
379
|
+
* Pending Models constructed after this one - in a parent, the products of
|
|
366
380
|
* its own initializers, until the last one it kept.
|
|
367
381
|
*/
|
|
368
|
-
declare function trailing(state:
|
|
382
|
+
declare function trailing(state: Model): Model[];
|
|
369
383
|
/**
|
|
370
|
-
* Report
|
|
384
|
+
* Report Models adopted by a parent - those already held, then each one
|
|
371
385
|
* claimed later. Returns a callback to stop watching.
|
|
372
386
|
*/
|
|
373
|
-
declare function children(state:
|
|
387
|
+
declare function children(state: Model, callback: (child: Model) => void): () => boolean;
|
|
374
388
|
/**
|
|
375
|
-
* Report
|
|
376
|
-
* activates. A function returned by `callback` runs when that
|
|
389
|
+
* Report Models owned by this one - those active now, then each one as it
|
|
390
|
+
* activates. A function returned by `callback` runs when that Model is destroyed.
|
|
377
391
|
*/
|
|
378
|
-
declare function owned(state:
|
|
379
|
-
declare function access(state:
|
|
392
|
+
declare function owned(state: Model, callback: (child: Model) => void | (() => void)): () => undefined;
|
|
393
|
+
declare function access(state: Model, property: string, required?: boolean): any;
|
|
380
394
|
/**
|
|
381
395
|
* Update a property on a state instance and notify listeners.
|
|
382
396
|
*
|
|
@@ -384,14 +398,14 @@ declare function access(state: State, property: string, required?: boolean): any
|
|
|
384
398
|
*
|
|
385
399
|
* A destroyed state stores the write without dispatch, reports it unless `silent`, and returns `false`.
|
|
386
400
|
*/
|
|
387
|
-
declare function update<T>(state:
|
|
401
|
+
declare function update<T>(state: Model, key: Model.Event<T>, value: T, silent?: boolean, own?: boolean): boolean;
|
|
388
402
|
/**
|
|
389
403
|
* Hand a value stored by an owning writer to that property's adopter,
|
|
390
|
-
* creating one the first time a
|
|
391
|
-
* held a
|
|
404
|
+
* creating one the first time a Model is stored there. A property which has
|
|
405
|
+
* held a Model keeps its adopter, so a later non-Model value releases the
|
|
392
406
|
* previous child.
|
|
393
407
|
*/
|
|
394
|
-
declare function adopt(state:
|
|
408
|
+
declare function adopt(state: Model, key: unknown, value: unknown): void;
|
|
395
409
|
/** Random alphanumberic of length 6; always starts with a letter. */
|
|
396
410
|
declare function uid(): string;
|
|
397
411
|
declare function unbind<T extends Function>(fn: T): T;
|
|
@@ -402,8 +416,8 @@ declare function unbind<T extends Function>(fn?: T): T | undefined;
|
|
|
402
416
|
* only if unclaimed and returns whether the assignment applied - `true` means
|
|
403
417
|
* this call freshly claimed it, `false` means it was already parented.
|
|
404
418
|
*/
|
|
405
|
-
declare function parent(child: object):
|
|
406
|
-
declare function parent(child: object, value:
|
|
419
|
+
declare function parent(child: object): Model | null | undefined;
|
|
420
|
+
declare function parent(child: object, value: Model | null): boolean;
|
|
407
421
|
//#endregion
|
|
408
|
-
export { GETTERS, type Handler, LATEST, METHODS, PENDING, SETUP, STORE,
|
|
422
|
+
export { GETTERS, type Handler, LATEST, METHODS, Model, PENDING, SETUP, STORE, UNBIND, access, adopt, apply, children, classify, compute, event, owned, parent, trailing, uid, unbind, update };
|
|
409
423
|
//# sourceMappingURL=state.d.ts.map
|