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