@expressive/mvc 0.19.2 → 0.21.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/lib/index.d.ts CHANGED
@@ -14,35 +14,127 @@ declare class Issue extends Error {
14
14
  }
15
15
  declare function issues<M extends Issue.Messages>(register: M): Issue.Output<M>;
16
16
 
17
- declare const LOCAL = "__local";
17
+ type Async<T = any> = (...args: any[]) => Promise<T>;
18
+ /**
19
+ * Sets an exotic method with managed ready-state. Property accepts an async function.
20
+ *
21
+ * When a run-method is invoked, its `active` property to true for duration of call.
22
+ * This is emitted as an update to property, both when called and after returns (or throws).
23
+ *
24
+ * **Note:** Subsequent calls will immediately throw if one is still pending.
25
+ *
26
+ * @param action - Action to fire when resulting property is invoked.
27
+ */
28
+ declare function run(action: Async): typeof action & {
29
+ active: boolean;
30
+ };
31
+ declare function run<S>(action: Async<S>): typeof action & {
32
+ active: boolean;
33
+ };
34
+
35
+ type Callback = () => void;
36
+
37
+ declare global {
38
+ namespace jest {
39
+ interface Matchers<R> {
40
+ /** Assert model does have one or more updates pending. */
41
+ toUpdate(): Promise<R>;
42
+
43
+ /** Assert model did update with keys specified. */
44
+ toHaveUpdated<R>(keys: string[]): Promise<R>;
45
+ }
46
+ }
47
+ }
48
+
49
+ type Observer<T extends Model = any> = (key: Model.Event<T> | null | undefined, source: Control) => Callback | null | void;
50
+ declare namespace Control {
51
+ /**
52
+ * Property initializer, will run upon instance creation.
53
+ * Optional returned callback will run when once upon first access.
54
+ */
55
+ type Instruction<T> = (this: Control, key: string, thisArg: Control) => PropertyDescriptor<T> | Getter<T> | void;
56
+ type Getter<T> = (source: Model) => T;
57
+ type Setter<T> = (value: T) => boolean | void;
58
+ type PropertyDescriptor<T = any> = {
59
+ enumerable?: boolean;
60
+ value?: T;
61
+ get?: Getter<T>;
62
+ set?: Setter<T> | false;
63
+ };
64
+ /**
65
+ * Callback for Controller.for() static method.
66
+ * Returned callback is forwarded.
67
+ */
68
+ type OnReady<T extends Model> = (control: Control<T>) => Callback | void;
69
+ type GetAdapter<T> = (update: () => void, source: (request: (got: Model | undefined) => void) => void) => {
70
+ mount: () => (() => void) | void;
71
+ render: () => T;
72
+ } | void;
73
+ type GetHook = <T extends Model, R>(type: Model.Type<T>, adapter: GetAdapter<R>) => R | null;
74
+ type UseAdapter<T extends Model> = (update: () => void) => {
75
+ instance: T;
76
+ mount: () => (() => void) | void;
77
+ render: (props: Model.Compat<T>) => T;
78
+ };
79
+ type UseHook = <T extends Model>(adapter: UseAdapter<T>) => (props: Model.Compat<T>) => T;
80
+ type HasHook = (type: typeof Model, relativeTo: Model, callback: (got: Model | undefined) => void) => void;
81
+ }
82
+ declare class Control<T extends Model = any> {
83
+ subject: T;
84
+ id: string | number;
85
+ static after: Set<Callback>;
86
+ static before: Set<Callback>;
87
+ static pending: Set<Callback>;
88
+ static get: Control.GetHook;
89
+ static use: Control.UseHook;
90
+ static has: Control.HasHook;
91
+ static for: typeof control;
92
+ static apply: typeof apply;
93
+ static watch: typeof watch;
94
+ state: {
95
+ [key: string]: any;
96
+ };
97
+ latest?: Model.Event<T>[];
98
+ frame: Set<string>;
99
+ followers: Set<Observer<any>>;
100
+ observers: Map<string, Set<Observer<any>>>;
101
+ constructor(subject: T, id?: string | number);
102
+ add(key: Extract<keyof T, string>): void;
103
+ watch(key: keyof T & string, output: Control.PropertyDescriptor<any>): void;
104
+ ref<K extends Model.Key<T>>(key: K, callback?: (this: T, value: T[K]) => boolean | void): (value: any) => void;
105
+ update(key: string): void;
106
+ addListener(fn: Observer): () => boolean;
107
+ clear(): void;
108
+ }
109
+ declare function control<T extends Model>(subject: T, ready: Control.OnReady<T>): Callback;
110
+ declare function control<T extends Model>(subject: T, ready?: boolean): Control<T>;
111
+ declare function watch<T extends Model>(on: T, cb: Observer): T;
112
+ declare function apply<T = any>(instruction: Control.Instruction<any>): T;
113
+
18
114
  declare const STATE = "__state";
19
115
  declare const UPDATE = "__update";
20
116
  declare const CONTROL = "__control";
117
+ declare const PARENT = "__parent";
21
118
  declare const Debug: {
22
- /** Use to access Model's local Subscriber (if exists). */
23
- LOCAL: "__local";
24
119
  /** Use to access snapshot of Model's current state. */
25
120
  STATE: "__state";
26
121
  /**
27
122
  * Use to access snapshot of Model's latest update.
28
- *
29
- * Note: If used within a Subscriber, update will be narrowed to the specific keys
30
- * which triggered a refresh (if one did).
31
123
  */
32
124
  UPDATE: "__update";
33
125
  /** Use to access a Model's controller. */
34
126
  CONTROL: "__control";
127
+ /** Use to access a Model's parent, if exists. */
128
+ PARENT: "__parent";
35
129
  };
36
130
  /**
37
131
  * Generic will declare debug properties on a given Model.
38
132
  *
39
133
  * These properties always exist at runtime, however are hidden unless you cast your Model as `Debug<T>`.
40
134
  */
41
- type Debug<T extends Model> = T & {
135
+ type Debug<T extends Model = Model> = T & {
42
136
  /** Controller for this instance. */
43
137
  [CONTROL]?: Control<T>;
44
- /** Current subscriber (if present) while used in a live context (e.g. hook or effect). */
45
- [LOCAL]?: Subscriber<T>;
46
138
  /** Current state of this instance. */
47
139
  [STATE]?: Model.Export<T>;
48
140
  /**
@@ -52,75 +144,78 @@ type Debug<T extends Model> = T & {
52
144
  * If within a subscribed function, will contain only keys which explicitly caused a refresh.
53
145
  */
54
146
  [UPDATE]?: readonly Model.Event<T>[];
147
+ /**
148
+ * Parent currently assigned to parent. Usually the model which this one is a property of.
149
+ */
150
+ [PARENT]?: Model;
55
151
  };
56
152
 
57
- type Callback = () => void;
58
- type Class = new (...args: any[]) => any;
59
- type InstanceOf<T> = T extends { prototype: infer U } ? U : never;
60
-
61
- type MaybePromise<T> = T | Promise<T>;
62
-
63
153
  /** Type may not be undefined - instead will be null. */
64
154
  type NoVoid<T> = T extends undefined ? null : T;
155
+ declare function get$1<T extends Model>(this: Model.Type<T>): T;
156
+ /** Fetch instance of this class in passive mode. Will not subscribe to events. */
157
+ declare function get$1<T extends Model>(this: Model.Type<T>, ignoreUpdates?: true): T;
158
+ /** Fetch instance of this class optionally. May be undefined, but will never subscribe. */
159
+ declare function get$1<T extends Model>(this: Model.Type<T>, required: boolean): T | undefined;
160
+ declare function get$1<T extends Model, R extends []>(this: Model.Type<T>, factory: Model.GetCallback<T, R | (() => R)>, expect?: boolean): R;
161
+ declare function get$1<T extends Model, R extends []>(this: Model.Type<T>, factory: Model.GetCallback<T, Promise<R> | (() => R) | null>, expect?: boolean): R | null;
162
+ declare function get$1<T extends Model, R extends []>(this: Model.Type<T>, factory: Model.GetCallback<T, Promise<R> | R>, expect: true): Exclude<R, undefined>;
163
+ declare function get$1<T extends Model, R>(this: Model.Type<T>, init: Model.GetCallback<T, () => R>): NoVoid<R>;
164
+ declare function get$1<T extends Model, R>(this: Model.Type<T>, init: Model.GetCallback<T, (() => R) | null>): NoVoid<R> | null;
165
+ declare function get$1<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, Promise<R> | R>, expect: true): Exclude<R, undefined>;
166
+ declare function get$1<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, Promise<R>>, expect?: boolean): NoVoid<R> | null;
167
+ declare function get$1<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, R>, expect?: boolean): NoVoid<R>;
65
168
 
169
+ declare function use$1<T extends Model>(this: Model.New<T>, callback?: (instance: T) => void): T;
170
+ declare function use$1<T extends Model>(this: Model.New<T>, apply?: Model.Compat<T>, repeat?: boolean): T;
171
+
172
+ type InstanceOf<T> = T extends {
173
+ prototype: infer U;
174
+ } ? U : never;
66
175
  declare namespace Model {
67
- export { Control };
68
- export { Subscriber };
69
- /** Including but not limited to T. */
70
- type Extends<T> = T | (string & Record<never, never>);
71
176
  /** Any typeof Model, using class constructor as the reference. */
72
- export type Type<T extends Model = Model> = abstract new () => T;
73
- export type Class<T extends Model> = (abstract new () => T) & typeof Model;
74
- /** A typeof Model, specifically one which may be created without arguments. */
75
- export type New<T extends Model = Model> = (new () => T) & typeof Model;
76
- export type Effect<T> = (this: T, argument: T) => Callback | Promise<any> | void;
177
+ type Type<T extends Model = Model> = abstract new (...args: any[]) => T;
178
+ /** A typeof Model, specifically one which can be created without any arguments. */
179
+ type New<T extends Model = Model> = (new () => T) & typeof Model;
180
+ type Effect<T> = (this: T, argument: T) => Callback | Promise<any> | void;
77
181
  /** Exotic value, actual value is contained. */
78
- export type Ref<T = any> = {
182
+ type Ref<T = any> = {
79
183
  (next: T): void;
80
184
  current: T | null;
81
185
  };
82
- /** Properties of T which are methods. */
83
- export type Methods<T> = {
84
- [K in keyof T]: T[K] extends Ref ? never : T[K] extends Function ? K : never;
85
- }[keyof T];
86
- type BuiltIn = keyof Model | keyof Debug<Model>;
87
186
  /**
88
187
  * Subset of `keyof T` which are not methods or defined by base Model U.
89
- *
90
- * **Note**: This excludes all keys which are not of type `string` (only those are managed).
91
- *
92
- * TODO: Should exclude methods
93
- **/
94
- export type Key<T> = Exclude<keyof T, BuiltIn> & string;
95
- /**
96
- * Including but not limited to `keyof T` which are not methods or defined by base Model.
97
188
  **/
98
- export type Event<T> = Extends<Key<T>>;
189
+ type Key<T, U = Model> = Extract<Exclude<keyof T, keyof U | keyof Debug>, string>;
190
+ /** Including but not limited to `keyof T` which are not methods or defined by base Model. */
191
+ type Event<T> = Key<T> | (string & {});
192
+ /** Actual value stored in state. */
193
+ type Value<R> = R extends Ref<infer T> ? T : R;
194
+ /** Actual value belonging to a managed property. */
195
+ type ValueOf<T extends {}, K> = K extends keyof T ? Value<T[K]> : undefined;
196
+ type Export<T> = {
197
+ [P in Key<T>]: Value<T[P]>;
198
+ };
99
199
  /** Object containing managed entries found in T. */
100
- export type Entries<T> = {
200
+ type Entries<T> = {
101
201
  [K in Key<T>]: T[K];
102
202
  };
103
203
  /** Object comperable to data found in T. */
104
- export type Compat<T> = {
204
+ type Compat<T> = {
105
205
  [K in Key<T>]?: T[K];
106
206
  };
107
- /** Actual value stored in state. */
108
- export type Value<R> = R extends Ref<infer T> ? T : R;
109
- /** Actual value belonging to a managed property. */
110
- export type ValueOf<T extends {}, K> = K extends keyof T ? Value<T[K]> : undefined;
111
207
  /**
112
208
  * Values from current state of given controller.
113
209
  *
114
210
  * Differs from `Entries` as values here will drill into "real" values held by exotics like ref.
115
211
  */
116
- export type Get<T, K extends Key<T> = Key<T>> = {
212
+ type Get<T, K extends Key<T> = Key<T>> = {
117
213
  [P in K]: Value<T[P]>;
118
214
  };
119
- export type Export<T> = {
120
- [P in Key<T>]: Value<T[P]>;
121
- };
122
- export type FindFunction = <T extends Model>(type: Model.Type<T>, relativeTo: Model, required: boolean) => (_refresh: (x: T) => void) => T | undefined;
123
- export type GetCallback<T extends Model, R> = (this: T, model: T, update: ForceUpdate) => R;
215
+ /** Promise thrown by something which is not yet ready. */
216
+ type Suspense = Promise<void> & Error;
217
+ type OnCallback<T extends Model> = (this: T, keys: Model.Event<T>[] | null) => void;
218
+ type GetCallback<T extends Model, R> = (this: T, model: T, update: ForceUpdate) => R;
124
219
  type ForceUpdate = {
125
220
  /** Force an update in current component. */
126
221
  (): void;
@@ -128,51 +223,38 @@ declare namespace Model {
128
223
  * Force an update and again after promise either resolves or rejects.
129
224
  * Will return a duplicate of given Promise, which resolves after refresh.
130
225
  */
131
- <T = void>(passthru?: Promise<T>): Promise<T>;
226
+ <T = void>(passthru: Promise<T>): Promise<T>;
132
227
  /**
133
228
  * Force a update while calling async function.
134
229
  * A refresh will occur both before and after given function.
135
230
  * Any actions performed before first `await` will occur before refresh!
136
231
  */
137
- <T = void>(invoke?: () => Promise<T>): Promise<T>;
232
+ <T = void>(invoke: () => Promise<T>): Promise<T>;
138
233
  };
139
- export type Suspense = Promise<void> & Error;
140
234
  }
141
235
  declare class Model {
236
+ constructor(id?: string | number);
142
237
  /**
143
238
  * Reference to `this` without a subscription.
144
239
  * Use to obtain full reference from a destructure.
145
240
  */
146
- is: this;
147
- /** Unique identifier for Model instance. */
148
- id: string;
149
- constructor(id?: string);
150
- on<P extends Model.Event<this>>(keys?: P | Iterable<P>, timeout?: number): Promise<P[]>;
151
- on<P extends Model.Event<this>>(keys: P | Iterable<P>, listener: (this: this, keys: Model.Event<this>[]) => void, once?: boolean): Callback;
241
+ get is(): this;
242
+ on(): Promise<Model.Event<this>[]>;
243
+ on(timeout?: number): Promise<Model.Event<this>[] | false>;
244
+ on<P extends Model.Event<this>>(keys?: P | P[], timeout?: number): Promise<P[] | false>;
245
+ on<P extends Model.Event<this>>(keys: P | P[], listener: Model.OnCallback<this>, once?: boolean): Callback;
152
246
  on(effect: Model.Effect<this>): Callback;
153
- on(effect: Model.Effect<this>, watch?: []): Callback;
154
- on(effect: Model.Effect<this>, watch?: Model.Event<this>[]): Callback;
155
- on(key?: undefined, timeout?: number): Promise<Model.Event<this>[]>;
156
- on(current?: boolean): Promise<Model.Event<this>[] | null>;
157
- on(current: true): Promise<Model.Event<this>[]>;
158
- on(current: null): Promise<null>;
159
247
  get(): Model.Export<this>;
160
248
  get<P extends Model.Key<this>>(select: P): this[P];
161
249
  get<P extends Model.Key<this>>(select: Iterable<P>): Model.Get<this, P>;
162
- get<P extends Model.Key<this>>(select: P, timeout: number): Promise<this[P]>;
163
- get<P extends Model.Key<this>>(select: Iterable<P>, timeout: number): Promise<Model.Get<this, P>>;
164
- get<P extends Model.Key<this>>(select: P, onChange: true): Promise<this[P]>;
165
- get<P extends Model.Key<this>>(select: Iterable<P>, onChange: true): Promise<Model.Get<this, P>>;
166
- get<P extends Model.Key<this>>(select: P, onChange: boolean): MaybePromise<this[P]>;
167
- get<P extends Model.Key<this>>(select: Iterable<P>, onChange: boolean): MaybePromise<Model.Get<this, P>>;
168
- get<P extends Model.Key<this>>(select: P, listener: (this: this, value: this[P], key: P[]) => void): Callback;
169
- get<P extends Model.Key<this>>(select: Iterable<P>, listener: (this: this, value: Model.Get<this, P>, key: P[]) => void): Callback;
170
- set(key: Model.Event<this>): PromiseLike<readonly Model.Event<this>[]>;
171
- set<K extends Model.Event<this>>(key: Model.Event<this>, value: Model.ValueOf<this, K>): PromiseLike<readonly Model.Event<this>[]>;
172
- set<T extends Model.Compat<this>>(source: T, select: (keyof T)[]): PromiseLike<(keyof T)[]>;
173
- set<T extends Model.Compat<this>>(source: T, force?: boolean): PromiseLike<(keyof T)[]>;
250
+ get<P extends Model.Key<this>>(select: P, listener: (this: this, value: this[P]) => void): Callback;
251
+ get<P extends Model.Key<this>>(select: Iterable<P>, listener: (this: this, value: Model.Get<this, P>) => void): Callback;
252
+ set<T extends Model.Compat<this>>(source: T, select?: (keyof T)[]): Promise<Model.Key<T>[]>;
253
+ set<K extends Model.Event<this>>(key: K, value?: Model.ValueOf<this, K>): Promise<Model.Event<this>[] | false>;
174
254
  /** Mark this instance for garbage collection. */
175
- gc(): void;
255
+ null(): void;
256
+ static get: typeof get$1;
257
+ static use: typeof use$1;
176
258
  /**
177
259
  * Creates a new instance of this controller.
178
260
  *
@@ -180,23 +262,7 @@ declare class Model {
180
262
  *
181
263
  * @param args - arguments sent to constructor
182
264
  */
183
- static new<T extends Class>(this: T, ...args: ConstructorParameters<T>): InstanceOf<T>;
184
- static find<T extends Model>(this: Model.Type<T>, required?: boolean): T;
185
- static find<T extends Model>(this: Model.Type<T>, required: false): T | undefined;
186
- static get<T extends Model>(this: Model.Type<T>): T;
187
- static get<T extends Model>(this: Model.Type<T>, passive: true): T;
188
- static get<T extends Model>(this: Model.Type<T>, required: false): T | undefined;
189
- static get<T extends Model, R extends []>(this: Model.Type<T>, compute: Model.GetCallback<T, R | (() => R)>, expect?: boolean): R;
190
- static get<T extends Model, R extends []>(this: Model.Type<T>, compute: Model.GetCallback<T, Promise<R> | (() => R) | null>, expect?: boolean): R | null;
191
- static get<T extends Model, R extends []>(this: Model.Type<T>, compute: Model.GetCallback<T, Promise<R> | R>, expect: true): Exclude<R, undefined>;
192
- static get<T extends Model, R>(this: Model.Type<T>, init: Model.GetCallback<T, () => R>): NoVoid<R>;
193
- static get<T extends Model, R>(this: Model.Type<T>, init: Model.GetCallback<T, (() => R) | null>): NoVoid<R> | null;
194
- static get<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, Promise<R> | R>, expect: true): Exclude<R, undefined>;
195
- static get<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, Promise<R>>, expect?: boolean): NoVoid<R> | null;
196
- static get<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, R>, expect?: boolean): NoVoid<R>;
197
- static use<I extends Model>(this: Model.Type<I>, watch: Model.Key<I>[], callback?: (instance: I) => void): I;
198
- static use<I extends Model>(this: Model.Type<I>, callback?: (instance: I) => void): I;
199
- static use<I extends Model>(this: Model.Type<I>, apply: Model.Compat<I>, keys?: Model.Event<I>[]): I;
265
+ static new<T extends new (...args: any[]) => any>(this: T, ...args: ConstructorParameters<T>): InstanceOf<T>;
200
266
  /**
201
267
  * Static equivalent of `x instanceof this`.
202
268
  *
@@ -205,120 +271,10 @@ declare class Model {
205
271
  static isTypeof<T extends Model.Type>(this: T, maybe: any): maybe is T;
206
272
  }
207
273
 
208
- type Listener = {
209
- commit(): void;
210
- release(): void;
211
- };
212
- declare namespace Subscriber {
213
- type OnEvent<T = any> = (key: Model.Event<T> | null, source: Control) => Callback | void;
214
- type Getter<T extends Model> = (within?: Subscriber<T> | undefined) => any;
215
- }
216
- declare class Subscriber<T extends Model = any> {
217
- onUpdate: Subscriber.OnEvent;
218
- proxy: T;
219
- clear: () => void;
220
- latest?: Model.Event<T>[];
221
- active: boolean;
222
- dependant: Set<Listener>;
223
- watch: Map<any, boolean | (() => boolean | void)>;
224
- parent: Control<T>;
225
- constructor(parent: Control<T> | T, onUpdate: Subscriber.OnEvent);
226
- get using(): Model.Key<T>[];
227
- get(key: string, using?: Subscriber.Getter<T>): any;
228
- follow(key: any, value?: boolean | (() => boolean | void)): void;
229
- commit(): void;
230
- release(): void;
231
- private notify;
232
- }
233
-
234
- /**
235
- * Property initializer, will run upon instance creation.
236
- * Optional returned callback will run when once upon first access.
237
- */
238
- type Instruction<T> = (this: Control, key: string, thisArg: Control) => Instruction.Getter<T> | Instruction.Descriptor<T> | void;
239
- declare namespace Instruction {
240
- type Getter<T> = (within?: Subscriber) => T;
241
- type Setter<T> = (value: T) => boolean | void;
242
- type Runner = (on: Control, key: string) => Instruction.Descriptor<any> | undefined;
243
- interface Descriptor<T> {
244
- enumerable?: boolean;
245
- value?: T;
246
- get?: Getter<T>;
247
- set?: Setter<T> | false;
248
- }
249
- }
250
- /**
251
- * Run instruction as controller sets itself up.
252
- * This will specialize the behavior of a given property.
253
- */
254
- declare function add<T = any>(instruction: Instruction<any>, label?: string): T;
255
-
256
- declare namespace Control {
257
- /**
258
- * Called immediately when any key is changed or emitted.
259
- * Returned callback is notified when update is complete.
260
- */
261
- type OnSync<T = any> = (key: Model.Event<T> | null, source: Control) => OnAsync<T> | void;
262
- /** Called at the end of an event frame with all keys affected. */
263
- type OnAsync<T = any> = (keys: Model.Event<T>[]) => void;
264
- type OnValue<T = any> = (this: T, value: any) => boolean | void;
265
- }
266
- declare class Control<T extends {} = any> {
267
- subject: T;
268
- state: Map<any, any>;
269
- frame: Set<string>;
270
- waiting: Set<Model.Control.OnAsync<T>>;
271
- followers: Set<Model.Control.OnSync<any>>;
272
- latest?: Model.Event<T>[];
273
- constructor(subject: T);
274
- watch(key: keyof T & string): void;
275
- /** Throw suspense which resolves when key is set. */
276
- waitFor(key: string): never;
277
- addListener(listener: Control.OnSync<T>): () => void;
278
- ref<K extends Model.Key<T>>(key: K, handler?: (this: T, value: T[K]) => boolean | void): (value: any) => void;
279
- update(key: Model.Key<T>): void;
280
- clear(): void;
281
- static get: typeof controller;
282
- static for: typeof control;
283
- }
284
- declare function controller<T extends Model>(from: T): Control<T> | undefined;
285
- declare namespace control {
286
- /**
287
- * Callback for Controller.for() static method.
288
- * Returned callback is forwarded.
289
- */
290
- type OnReady<T extends Model> = (control: Control<T>) => Callback | void;
291
- }
292
- declare function control<T extends Model>(subject: T): Control<T>;
293
- declare function control<T extends Model>(subject: T, cb: control.OnReady<T>): Callback;
294
-
295
- declare function getParent<T extends Model>(from: Model, type?: Model.Class<T>): T;
296
-
297
- type Async<T = any> = (...args: any[]) => Promise<T>;
298
- /**
299
- * Sets an exotic method with managed ready-state. Property accepts an async function.
300
- *
301
- * When a run-method is invoked, its `active` property to true for duration of call.
302
- * This is emitted as an update to property, both when called and after returns (or throws).
303
- *
304
- * **Note:** Subsequent calls will immediately throw if one is still pending.
305
- *
306
- * @param action - Action to fire when resulting property is invoked.
307
- */
308
- declare function run(action: Async): typeof action & {
309
- active: boolean;
310
- };
311
- declare function run<S>(action: Async<S>): typeof action & {
312
- active: boolean;
313
- };
314
-
315
274
  declare namespace get {
316
275
  type Function<T, S = any> = (this: S, on: S) => T;
317
276
  type Factory<R, T> = (this: T, property: string, on: T) => Function<R, T>;
318
- type FindFunction<T extends Model = Model> = (type: Model.Class<T>, relativeTo: Model, required: boolean) => Source<T>;
319
277
  type Source<T extends Model = Model> = (callback: (x: T) => void) => void;
320
- /** Assign fetch algorithm for get instruction. */
321
- let using: (fn: FindFunction) => typeof get;
322
278
  }
323
279
  /**
324
280
  * Fetches and assigns the controller which spawned this host.
@@ -338,8 +294,8 @@ declare function get<R, T extends Model>(Type: Model.Type<T>, compute: (this: T,
338
294
  * @param source - Source model from which computed value will be a subscriber.
339
295
  * @param compute - Compute function. Bound to a subscriber-proxy of source, returns output value. Will update automatically as input values change.
340
296
  */
341
- declare function get<R, T>(source: T, compute: (this: T, on: T) => R): Exclude<R, undefined>;
342
- declare function get<R, T>(source: T, compute: (this: T, on: T) => R): R;
297
+ declare function get<R, T extends Model>(source: T, compute: (this: T, on: T) => R): Exclude<R, undefined>;
298
+ declare function get<R, T extends Model>(source: T, compute: (this: T, on: T) => R): R;
343
299
  /**
344
300
  * Implement a computed value; output is returned by function from provided factory.
345
301
  *
@@ -349,7 +305,7 @@ declare function get<R, T>(compute: (property: string, on: T) => (this: T, state
349
305
  declare function get<R, T>(compute: (property: string, on: T) => (this: T, state: T) => R): R;
350
306
 
351
307
  declare namespace ref {
352
- type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<void> | void | boolean;
308
+ type Callback<T> = (argument: T) => ((next: T) => void) | Promise<void> | void | boolean;
353
309
  interface Object<T = any> {
354
310
  (next: T): void;
355
311
  current: T | null;
@@ -389,11 +345,10 @@ declare function ref<O extends Model, R>(target: O, mapper: (key: Model.Key<O>)
389
345
  * @param callback - Optional callback to synchronously fire when reference is first set or does update.
390
346
  */
391
347
  declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>;
392
- declare function ref<T, S>(callback?: ref.Callback<T, S>): ref.Object<T>;
393
348
 
394
349
  declare namespace set {
395
350
  type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
396
- type Factory<T, S = unknown> = (this: S, key: string, thisArg: S) => T;
351
+ type Factory<T, S = any> = (this: S, key: string, thisArg: S) => Promise<T> | T;
397
352
  }
398
353
  /**
399
354
  * Set property with a placeholder.
@@ -402,28 +357,12 @@ declare namespace set {
402
357
  * `Promise`/`Error` (ala: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.
403
358
  */
404
359
  declare function set<T = any>(): T;
405
- /**
406
- * Set property with an async function.
407
- *
408
- * Property cannot be accessed until factory resolves, yeilding a result.
409
- * If accessed while processing, React Suspense will be thrown.
410
- *
411
- * - `required: true` (default) -
412
- * Run factory immediately upon creation of model instance.
413
- * - `required: false` -
414
- * Run factory only if/when accessed.
415
- * Value will always throw suspense at least once - use with caution.
416
- *
417
- * @param factory - Callback run to derrive property value.
418
- * @param required - (default: true) Run factory immediately on creation, otherwise on access.
419
- */
420
- declare function set<T>(factory: set.Factory<Promise<T>>, required: false): T | undefined;
421
- declare function set<T, S>(factory: set.Factory<Promise<T>, S>, required: false): T | undefined;
422
- declare function set<T>(factory: set.Factory<Promise<T>>, required?: boolean): T;
423
- declare function set<T, S>(factory: set.Factory<Promise<T>, S>, required?: boolean): T;
424
360
  /**
425
361
  * Set property with a factory function.
426
362
  *
363
+ * If async, poperty cannot be accessed until resolves, yeilding a result.
364
+ * If accessed while still processing, React Suspense will be thrown.
365
+ *
427
366
  * - `required: true` (default) -
428
367
  * Run factory immediately upon creation of model instance.
429
368
  * - `required: false` -
@@ -433,70 +372,45 @@ declare function set<T, S>(factory: set.Factory<Promise<T>, S>, required?: boole
433
372
  * @param factory - Callback run to derrive property value.
434
373
  * @param required - (default: true) Run factory immediately on creation, otherwise on access.
435
374
  */
436
- declare function set<T>(factory: set.Factory<T>, required: false): T | undefined;
437
- declare function set<T, S>(factory: set.Factory<T, S>, required: false): T | undefined;
438
- declare function set<T>(factory: set.Factory<T>, required?: boolean): T;
439
- declare function set<T, S>(factory: set.Factory<T, S>, required?: boolean): T;
440
- declare function set<T>(factory: Promise<T>, required: false): T | undefined;
441
- declare function set<T>(factory: Promise<T>, required?: boolean): T;
375
+ declare function set<T>(factory: set.Factory<T> | Promise<T>, required: false): T | undefined;
376
+ declare function set<T>(factory: set.Factory<T> | Promise<T>, required?: boolean): T;
442
377
  declare function set<T>(value: undefined, onUpdate: set.Callback<T>): T;
443
- declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T;
444
378
  declare function set<T>(value: T, onUpdate: set.Callback<T>): T;
445
- declare function set<T, S>(value: T, onUpdate: set.Callback<T, S>): T;
446
379
 
447
- type MapFunction<T, R> = T extends Map<infer K, infer V> ? (value: V, key: K, map: T) => R | void : T extends Set<infer K> ? (value: K, key: K, set: T) => R | void : never;
448
- type Managed<T> = Exclude<T, "forEach"> & {
449
- from?: T;
450
- forEach<R>(mapFunction: MapFunction<T, R>, thisArg?: any): Exclude<R, undefined>[] | void;
451
- };
452
-
453
- declare function use<K = any>(initial: SetConstructor): Managed<Set<K>>;
454
- declare function use<K = any, V = any>(initial: MapConstructor): Managed<Map<K, V>>;
455
- declare function use(initial: Set<unknown>): Managed<Set<any>>;
456
- declare function use(initial: Map<unknown, unknown>): Managed<Map<any, any>>;
457
- declare function use(from: () => Set<unknown>): Managed<Set<any>>;
458
- declare function use(from: () => Map<unknown, unknown>): Managed<Map<any, any>>;
459
- declare function use<T extends Set<any> | Map<any, any>>(initial: T): Managed<T>;
460
- declare function use<T extends Set<any> | Map<any, any>>(from: () => T): Managed<T>;
461
- /**
462
- * Create a placeholder for specified Model type.
463
- */
380
+ /** Create a placeholder for specified Model type. */
464
381
  declare function use<T extends Model>(): T | undefined;
465
- declare function use<T extends Model>(from: () => T, required: false): T | undefined;
466
- declare function use<T extends Model>(from: () => T, required: boolean): T;
467
- /**
468
- * Create a new child instance of model.
469
- */
382
+ /** Create a new child instance of model. */
470
383
  declare function use<T extends Model>(Type: Model.New<T>, callback?: (i: T) => void): T;
384
+ /** Assign the result of a factory as a child model. */
385
+ declare function use<T extends Model>(from: () => Promise<T> | T, required?: true): T;
386
+ /** Assign the result of a factory as a child model. */
387
+ declare function use<T extends Model>(from: () => Promise<T> | T, required: boolean): T | undefined;
388
+ /** Create a managed child from factory function. */
389
+ declare function use<T extends Model>(from: () => Promise<T> | T, callback?: (i: T) => void): T;
471
390
  /**
472
- * Create a managed child from factory function.
473
- */
474
- declare function use<T extends {}>(from: () => Promise<T>, required: false): T | undefined;
475
- declare function use<T extends {}>(from: () => Promise<T>, required: boolean): T;
476
- declare function use<T extends {}>(from: () => Promise<T>, callback?: (i: T) => void): T;
477
- declare function use<T extends {}>(from: () => T, callback?: (i: T) => void): T;
478
- /**
479
- * Create child-instance relationship with provided model.
480
- *
481
- * Note: If `peer` is not already initialized before parent is
482
- * (created with `new` as opposed to create method), that model will
483
- * attach this via `parent()` instruction. It will not, however, if
484
- * already active.
485
- */
486
- declare function use<T extends {}>(peer: T, callback?: (i: T) => void): T;
391
+ * Create child-instance relationship with provided model.
392
+ *
393
+ * Note: If `peer` is not already initialized before parent is
394
+ * (created with `new` as opposed to create method), that model will
395
+ * attach this via `parent()` instruction. It will not, however, if
396
+ * already active.
397
+ */
398
+ declare function use<T extends Model>(peer: T, callback?: (i: T) => void): T;
487
399
 
488
- declare class Register {
400
+ declare namespace Context {
401
+ type Inputs = {
402
+ [key: string | number]: Model | Model.New;
403
+ };
404
+ }
405
+ declare class Context {
489
406
  private table;
490
- register: Map<string | number, Model | Model.Type>;
407
+ private input;
491
408
  private has;
492
409
  get<T extends Model>(Type: Model.Type<T>): T | undefined;
493
- add(input: Model.New | Model, key?: number | string): Model;
410
+ include(inputs: Context.Inputs): Map<Model, boolean>;
411
+ add<T extends Model>(input: T | Model.New<T>, implicit?: boolean): T;
494
412
  push(): this;
495
413
  pop(): void;
496
414
  }
497
415
 
498
- declare const Internal: {
499
- getParent: typeof getParent;
500
- };
501
-
502
- export { Control, Debug, Internal, Model, Register, Subscriber, add, Model as default, get, issues, ref, run, set, use };
416
+ export { Context, Control, Debug, Model, Model as default, get, issues, ref, run, set, use };