@expressive/mvc 0.7.2 → 0.8.1

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
@@ -8,48 +8,38 @@ declare type Listener = {
8
8
  commit(): void;
9
9
  release(): void;
10
10
  };
11
- declare class Subscriber<T extends Stateful = any> {
12
- onUpdate: Controller.OnEvent;
11
+ declare class Subscriber<T extends {} = any> {
12
+ parent: Control<T>;
13
+ onUpdate: Control.OnEvent;
14
+ static get<T extends {}>(from: T): Model.Subscriber<T> | undefined;
13
15
  proxy: T;
14
- commit: () => Callback;
15
16
  release: Callback;
17
+ latest?: Model.Event<T>[];
16
18
  active: boolean;
17
19
  dependant: Set<Listener>;
18
- add: (key: any, value?: boolean | Callback) => void;
19
- constructor(parent: Controller<T>, onUpdate: Controller.OnEvent);
20
+ watch: Map<any, boolean | (() => true | void)>;
21
+ constructor(parent: Control<T>, onUpdate: Control.OnEvent);
22
+ get using(): Model.Values<T>;
23
+ assign(apply: Model.Compat<T>, keys?: any): void;
24
+ add(key: any, value?: boolean | Callback): void;
25
+ commit: () => () => void;
26
+ private event;
20
27
  }
21
28
 
22
- declare const WHY: unique symbol;
23
- declare const LOCAL: unique symbol;
24
- declare const STATE: unique symbol;
25
- interface Stateful {
26
- /** Controller for this instance. */
27
- [CONTROL]?: Controller;
28
- /** Current subscriber (if present) while used in a live context (e.g. hook or effect). */
29
- [LOCAL]?: Subscriber;
30
- /** Current state of this instance. */
31
- [STATE]?: Model.Values<this>;
32
- /**
33
- * Last update causing a refresh to subscribers.
34
- *
35
- * If accessed directly, will contain all keys from last push.
36
- * If within a subscribed function, will contain only keys which explicitly caused a refresh.
37
- */
38
- [WHY]?: readonly Model.Event<this>[];
39
- }
40
29
  declare namespace Model {
30
+ export { Control };
31
+ export { Subscriber };
41
32
  /** Including but not limited to T. */
42
33
  type Extends<T> = T | (string & Record<never, never>);
43
- export { Controller };
44
- export { Subscriber };
34
+ export type Type<T extends Model = Model> = typeof Model & (new () => T);
45
35
  export type OnUpdate<T, P> = (this: T, value: ValueOf<keyof T, P>, changed: P) => void;
46
36
  export type Effect<T> = (this: T, argument: T) => Callback | Promise<any> | void;
47
37
  /** Exotic value, actual value is contained. */
48
- export interface Ref<T = any> {
38
+ export type Ref<T = any> = {
49
39
  (next: T): void;
50
40
  current: T | null;
51
- }
52
- /** Properties of T, of which are methods. */
41
+ };
42
+ /** Properties of T which are methods. */
53
43
  export type Methods<T> = {
54
44
  [K in keyof T]: T[K] extends Ref ? never : T[K] extends Function ? K : never;
55
45
  }[keyof T];
@@ -57,6 +47,8 @@ declare namespace Model {
57
47
  * Subset of `keyof T` which are not methods or defined by base Model U.
58
48
  *
59
49
  * **Note**: This excludes all keys which are not of type `string` (only those are managed).
50
+ *
51
+ * TODO: Should exclude methods
60
52
  **/
61
53
  export type Field<T, U extends Model = Model> = Exclude<keyof T & string, keyof U>;
62
54
  /**
@@ -64,9 +56,13 @@ declare namespace Model {
64
56
  **/
65
57
  export type Event<T, U extends Model = Model> = Extends<Field<T, U>>;
66
58
  /** Object containing managed entries found in T. */
67
- export type Entries<T, U extends Model = Model> = Pick<T, Field<T, U>>;
59
+ export type Entries<T, U extends Model = Model> = {
60
+ [K in Field<T, U>]: T[K];
61
+ };
68
62
  /** Object comperable to data found in T. */
69
- export type Compat<T, U extends Model = Model> = Partial<Entries<T, U>>;
63
+ export type Compat<T, U extends Model = Model> = {
64
+ [K in Field<T, U>]?: T[K];
65
+ };
70
66
  /** Actual value stored in state. */
71
67
  export type Value<R> = R extends Ref<infer T> ? T : R;
72
68
  /** Actual value belonging to a managed property. */
@@ -76,56 +72,45 @@ declare namespace Model {
76
72
  *
77
73
  * Differs from `Entries` as values here will drill into "real" values held by exotics like ref.
78
74
  */
79
- export type Values<T, K extends Field<T, Model> = Field<T, Model>> = {
75
+ export type Values<T, K extends Field<T> = Field<T>> = {
80
76
  [P in K]: Value<T[P]>;
81
77
  };
82
78
  }
83
- interface Model extends Stateful {
79
+ declare class Model {
84
80
  /**
85
81
  * Circular reference to `this` controller.
86
82
  *
87
83
  * Useful to obtain full reference where one has already destructured.
88
84
  */
89
85
  is: this;
90
- }
91
- declare class Model {
92
- static [WHY]: readonly string[];
93
86
  constructor();
94
- get [STATE](): Model.Values<this, Exclude<keyof this & string, keyof Model>>;
95
- get [WHY](): readonly string[] | undefined;
96
87
  on<P = Model.Event<this>>(event: (key: P) => Callback | void): Callback;
97
- on<P = Model.Event<this>>(keys: [], listener: Model.OnUpdate<this, P>, squash?: boolean, once?: boolean): Callback;
98
- on<P = Model.Event<this>>(keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
99
- on(keys: [], listener: unknown, squash: boolean, once?: boolean): Callback;
100
- on<P extends Model.Event<this>>(key: P | P[], listener: Model.OnUpdate<this, P>, squash?: boolean, once?: boolean): Callback;
101
- on<P extends Model.Event<this>>(key: P | P[], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
102
- on<P extends Model.Event<this>>(key: P | P[], listener: unknown, squash: boolean, once?: boolean): Callback;
103
- once<P = Model.Event<this>>(keys: [], listener: Model.OnUpdate<this, P>, squash?: false, once?: boolean): Callback;
104
- once<P = Model.Event<this>>(keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
105
- once<P = Model.Event<this>>(keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
106
- once(keys: [], listener: unknown, squash: boolean, once?: boolean): Callback;
107
- once<P extends Model.Event<this>>(key: P | P[], listener: Model.OnUpdate<this, P>, squash?: false): Callback;
108
- once<P extends Model.Event<this>>(key: P | P[], listener: (keys: P[]) => void, squash: true): Callback;
109
- once<P extends Model.Event<this>>(key: P | P[], listener: unknown, squash: boolean): Callback;
110
- once<P extends Model.Event<this>>(key: P | P[], timeout?: number): Promise<void>;
88
+ on<P extends Model.Event<this>>(key: P): Promise<Model.ValueOf<this, P>>;
89
+ on<P extends Model.Event<this>>(key: P, timeout: number): Promise<Model.ValueOf<this, P>>;
90
+ on<P extends Model.Event<this>>(key: P, listener: Model.OnUpdate<this, P>, once?: boolean): Callback;
91
+ on<P extends Model.Event<this>>(key: P[]): Promise<P[]>;
92
+ on<P extends Model.Event<this>>(key: P[], timeout: number): Promise<P[]>;
93
+ on<P extends Model.Event<this>>(key: P[], listener: (keys: P[]) => void, once?: boolean): Callback;
94
+ on<P = Model.Event<this>>(keys: [], listener: Model.OnUpdate<this, P>, once?: boolean): Callback;
95
+ on<P = Model.Event<this>>(keys: [], listener: (keys: P[]) => void, once?: boolean): Callback;
111
96
  effect(callback: Model.Effect<this>): Callback;
112
97
  effect(callback: Model.Effect<this>, select: []): Callback;
113
98
  effect(callback: Model.Effect<this>, select: Model.Event<this>[]): Callback;
114
- import<O extends Model.Compat<this>>(source: O, select?: (keyof O)[]): void;
115
99
  export(): Model.Values<this>;
116
100
  export<P extends Model.Field<this>>(select: P[]): Model.Values<this, P>;
117
101
  update(): PromiseLike<readonly Model.Event<this>[] | false>;
118
102
  update(strict: true): Promise<readonly Model.Event<this>[]>;
119
103
  update(strict: false): Promise<false>;
120
104
  update(strict: boolean): Promise<readonly Model.Event<this>[] | false>;
121
- update(keys: Model.Event<this>): PromiseLike<readonly Model.Event<this>[]>;
122
- update(keys: Model.Event<this>, callMethod: boolean): PromiseLike<readonly Model.Event<this>[]>;
123
- update<T>(keys: Model.Event<this>, argument: T): PromiseLike<readonly Model.Event<this>[]>;
105
+ update(key: Model.Event<this>): PromiseLike<readonly Model.Event<this>[]>;
106
+ update(key: Model.Event<this>, callMethod: boolean): PromiseLike<readonly Model.Event<this>[]>;
107
+ update<T>(key: Model.Event<this>, argument: T): PromiseLike<readonly Model.Event<this>[]>;
108
+ update<T extends Model.Compat<this>>(source: T, select: (keyof T)[]): PromiseLike<(keyof T)[]>;
109
+ update<T extends Model.Compat<this>>(source: T, force?: boolean): PromiseLike<(keyof T)[]>;
124
110
  /**
125
111
  * Mark this instance for garbage-collection and send `willDestroy` event to all listeners.
126
112
  */
127
- destroy(): void;
128
- toString(): string;
113
+ kill(): void;
129
114
  /**
130
115
  * Creates a new instance of this controller.
131
116
  *
@@ -133,44 +118,48 @@ declare class Model {
133
118
  *
134
119
  * @param args - arguments sent to constructor
135
120
  */
136
- static create<T extends Class>(this: T, ...args: ConstructorParameters<T>): InstanceOf<T>;
121
+ static new<T extends Class>(this: T, ...args: ConstructorParameters<T>): InstanceOf<T>;
137
122
  /**
138
123
  * Static equivalent of `x instanceof this`.
139
124
  *
140
125
  * Will determine if provided class is a subtype of this one.
141
126
  */
142
- static isTypeof<T extends new () => Model>(this: T, maybe: any): maybe is T;
127
+ static isTypeof<T extends Model.Type>(this: T, maybe: any): maybe is T;
143
128
  }
144
129
 
145
- declare const CONTROL: unique symbol;
146
- declare namespace Controller {
130
+ declare namespace Control {
147
131
  type OnValue<T = any> = (this: T, value: any) => boolean | void;
148
- type OnEvent<T = any> = (key: Model.Event<T> | null, source: Controller) => Callback | void;
132
+ type OnEvent<T = any> = (key: Model.Event<T> | null, source: Control) => Callback | void;
133
+ type OnReady<T extends {}> = (control: Control<T>) => Callback | void;
149
134
  }
150
- declare class Controller<T extends Stateful = any> {
135
+ declare class Control<T extends {} = any> {
151
136
  subject: T;
152
137
  state: Map<any, any>;
153
138
  frame: Set<string>;
154
139
  waiting: Set<Callback>;
155
- followers: Set<Model.Controller.OnEvent<any>>;
140
+ followers: Set<Model.Control.OnEvent<any>>;
141
+ latest?: Model.Event<T>[];
156
142
  constructor(subject: T);
157
- subscribe(callback: Controller.OnEvent<T>): Model.Subscriber<T>;
158
- add(key: keyof T & string): void;
159
- addListener(listener: Controller.OnEvent<T>): () => void;
160
- ref(key: Model.Field<T>, handler?: Controller.OnValue<T>): (value: any) => void;
143
+ subscribe(callback: Control.OnEvent<T>): Model.Subscriber<T>;
144
+ watch(key: keyof T & string): void;
145
+ addListener(listener: Control.OnEvent<T>): () => void;
146
+ ref(key: Model.Field<T>, handler?: Control.OnValue<T>): (value: any) => void;
161
147
  update(key: Model.Field<T>): void;
162
148
  clear(): void;
149
+ static get<T extends {}>(from: T): Control<T> | undefined;
150
+ static for<T extends {}>(subject: T): Control<T>;
151
+ static for<T extends {}>(subject: T, cb: Control.OnReady<T>): Callback;
163
152
  }
164
153
 
165
154
  /**
166
155
  * Property initializer, will run upon instance creation.
167
156
  * Optional returned callback will run when once upon first access.
168
157
  */
169
- declare type Instruction<T> = (this: Controller, key: string, thisArg: Controller) => Instruction.Getter<T> | Instruction.ExplicitDescriptor | Instruction.Descriptor<T> | Instruction.RecursiveDescriptor<T> | boolean | void;
158
+ declare type Instruction<T> = (this: Control, key: string, thisArg: Control) => Instruction.Getter<T> | Instruction.ExplicitDescriptor | Instruction.Descriptor<T> | Instruction.RecursiveDescriptor<T> | boolean | void;
170
159
  declare namespace Instruction {
171
160
  type Getter<T> = (within?: Subscriber) => T;
172
161
  type Setter<T> = (value: T) => boolean | void;
173
- type Runner<T> = (this: Controller, key: string, on: Controller) => Instruction.Descriptor<T> | boolean | undefined;
162
+ type Runner<T> = (this: Control, key: string, on: Control) => Instruction.Descriptor<T> | boolean | undefined;
174
163
  interface Descriptor<T> {
175
164
  configurable?: boolean;
176
165
  enumerable?: boolean;
@@ -178,7 +167,7 @@ declare namespace Instruction {
178
167
  writable?: boolean;
179
168
  get?: Getter<T>;
180
169
  set?: Setter<T> | false;
181
- suspense?: boolean;
170
+ suspend?: boolean;
182
171
  destroy?: () => void;
183
172
  }
184
173
  interface ExplicitDescriptor extends PropertyDescriptor {
@@ -189,14 +178,14 @@ declare namespace Instruction {
189
178
  enumerable?: boolean;
190
179
  value?: T;
191
180
  set?: Setter<T> | false;
192
- suspense?: boolean;
181
+ suspend?: boolean;
193
182
  }
194
183
  }
195
184
  /**
196
185
  * Run instruction as controller sets itself up.
197
186
  * This will specialize the behavior of a given property.
198
187
  */
199
- declare function apply<T = any>(instruction: Instruction<T>, name?: string): T;
188
+ declare function add<T = any>(instruction: Instruction<any>, label?: string): T;
200
189
 
201
190
  declare type Async<T = any> = (...args: any[]) => Promise<T>;
202
191
  /**
@@ -361,7 +350,7 @@ declare function use<T extends Model>(from: () => T, required: boolean): T;
361
350
  /**
362
351
  * Create a new child instance of model.
363
352
  */
364
- declare function use<T extends Class>(Type: T, callback?: (i: InstanceOf<T>) => void): InstanceOf<T>;
353
+ declare function use<T extends Model>(Type: Model.Type<T>, callback?: (i: T) => void): T;
365
354
  /**
366
355
  * Create a managed child from factory function.
367
356
  */
@@ -384,82 +373,49 @@ declare function use<T extends {}>(peer: T, callback?: (i: T) => void): T;
384
373
  * When parent assigns an instance via `use()` directive, it
385
374
  * will be made available to child upon this request.
386
375
  *
387
- * @param Expects - Type of controller compatible with this class.
376
+ * @param Type - Type of controller compatible with this class.
388
377
  * @param required - Throw if controller is created independantly.
389
378
  */
390
- declare function has<T extends typeof Model>(Expects: T, required: false): InstanceOf<T> | undefined;
391
- declare function has<T extends typeof Model>(Expects: T, required?: true): InstanceOf<T>;
379
+ declare function has<T extends Model>(Type: Model.Type<T>, required: false): T | undefined;
380
+ declare function has<T extends Model>(Type: Model.Type<T>, required?: true): T;
392
381
 
393
382
  declare class MVC extends Model {
394
- static [CONTROL]: Controller;
395
- /** Attaches this controller to a component. */
396
- tap(): this;
397
- tap<K extends Model.Field<this>>(key: K, expect: true): Exclude<this[K], undefined>;
398
- tap<K extends Model.Field<this>>(key: K, expect?: boolean): this[K];
399
- tap<T>(from: (this: this, state: this) => Promise<T>, expect: true): Exclude<T, undefined>;
400
- tap<T>(from: (this: this, state: this) => Promise<T>, expect?: boolean): T | undefined;
401
- tap<T>(from: (this: this, state: this) => T, expect: true): Exclude<T, undefined>;
402
- tap<T>(from: (this: this, state: this) => T, expect?: boolean): T;
403
- /**
404
- * **React Hook** - Subscribe to instance of controller within a component.
405
- *
406
- * @param callback - Run once before subscription begins.
407
- */
408
- use(watch: Model.Field<this>[], callback?: (instance: this) => void): this;
409
- use(callback?: (instance: this) => void): this;
410
383
  /**
411
384
  * **React Hook** - Fetch most instance of this controller from context, if it exists.
412
385
  *
413
386
  * @param required - Unless false, will throw where instance cannot be found.
414
387
  */
415
- static get<T extends Class>(this: T, required?: boolean): InstanceOf<T>;
388
+ static get<T extends MVC>(this: Model.Type<T>, required?: boolean): T;
416
389
  /**
417
390
  * **React Hook** - Fetch most instance of this controller from context.
418
391
  *
419
392
  * @param required - If false, may return undefined.
420
393
  */
421
- static get<T extends Class>(this: T, required: false): InstanceOf<T> | undefined;
394
+ static get<T extends MVC>(this: Model.Type<T>, required: false): T | undefined;
422
395
  /**
423
396
  * **React Hook** - Fetch specific value from instance of this controller in context.
424
397
  */
425
- static get<T extends Class, I extends InstanceOf<T>, K extends Model.Field<I>>(this: T, key: K): I[K];
398
+ static get<I extends MVC, K extends Model.Field<I>>(this: Model.Type<I>, key: K): I[K];
426
399
  /**
427
400
  * **React Hook** - Fetch instance.
428
401
  *
429
402
  * Effect callback will run once if found, throw if not found.
430
403
  * Returned function is called on unmount.
431
404
  */
432
- static get<T extends Class, I extends InstanceOf<T>>(this: T, effect: (found: I) => Callback | void): I;
405
+ static get<I extends MVC>(this: Model.Type<I>, effect: (found: I) => Callback | void): I;
433
406
  /**
434
407
  * **React Hook** - Fetch and subscribe to instance of this controller within ambient component.
435
408
  */
436
- static tap<T extends Class>(this: T): InstanceOf<T>;
437
- static tap<T extends Class, I extends InstanceOf<T>, K extends Model.Field<I>>(this: T, key: K, expect: true): Exclude<I[K], undefined>;
438
- static tap<T extends Class, I extends InstanceOf<T>, K extends Model.Field<I>>(this: T, key: K, expect?: boolean): I[K];
439
- static tap<T, M extends Class, I extends InstanceOf<M>>(this: M, from: (this: I, state: I) => Promise<T>, expect: true): Exclude<T, undefined>;
440
- static tap<T, M extends Class, I extends InstanceOf<M>>(this: M, from: (this: I, state: I) => Promise<T>, expect?: boolean): T;
441
- static tap<T, M extends Class, I extends InstanceOf<M>>(this: M, from: (this: I, state: I) => T, expect: true): Exclude<T, undefined>;
442
- static tap<T, M extends Class, I extends InstanceOf<M>>(this: M, from: (this: I, state: I) => T, expect?: boolean): T;
443
- /**
444
- * **React Hook** - Spawn and maintain a controller from within a component.
445
- *
446
- * More efficient than `use()` if you don't need hook-based features.
447
- *
448
- * @param callback - Run after creation of instance.
449
- */
450
- static new<T extends Class, I extends InstanceOf<T>>(this: T, callback?: (instance: I) => void): I;
451
- static new<T extends Class, I extends InstanceOf<T>>(this: T, apply: Model.Compat<I>): I;
452
- static use<T extends Class, I extends InstanceOf<T>>(this: T, watch: Model.Field<I>[], callback?: (instance: I) => void): I;
453
- static use<T extends Class, I extends InstanceOf<T>>(this: T, callback?: (instance: I) => void): I;
454
- static use<T extends Class, I extends InstanceOf<T>>(this: T, apply: Model.Compat<I>, keys?: Model.Event<I>[]): I;
455
- /**
456
- * @deprecated consider doing this manually - not worth minor efficiency gain over using.
457
- */
458
- static uses<T extends typeof MVC, I extends InstanceOf<T>, D extends Model.Compat<I>>(this: T, apply: D, keys?: (keyof D)[]): InstanceOf<T>;
459
- /**
460
- * @deprecated is now replaced by overload of `use` method.
461
- */
462
- static using<T extends typeof MVC, I extends InstanceOf<T>>(this: T, apply: Model.Compat<I>, keys?: Model.Event<I>[]): I;
409
+ static tap<T extends MVC>(this: Model.Type<T>): T;
410
+ static tap<I extends MVC, K extends Model.Field<I>>(this: Model.Type<I>, key: K, expect: true): Exclude<I[K], undefined>;
411
+ static tap<I extends MVC, K extends Model.Field<I>>(this: Model.Type<I>, key: K, expect?: boolean): I[K];
412
+ static tap<T, I extends MVC>(this: Model.Type<I>, from: (this: I, state: I) => Promise<T>, expect: true): Exclude<T, undefined>;
413
+ static tap<T, I extends MVC>(this: Model.Type<I>, from: (this: I, state: I) => Promise<T>, expect?: boolean): T;
414
+ static tap<T, I extends MVC>(this: Model.Type<I>, from: (this: I, state: I) => T, expect: true): Exclude<T, undefined>;
415
+ static tap<T, I extends MVC>(this: Model.Type<I>, from: (this: I, state: I) => T, expect?: boolean): T;
416
+ static use<I extends MVC>(this: Model.Type<I>, watch: Model.Field<I>[], callback?: (instance: I) => void): I;
417
+ static use<I extends MVC>(this: Model.Type<I>, callback?: (instance: I) => void): I;
418
+ static use<I extends MVC>(this: Model.Type<I>, apply: Model.Compat<I>, keys?: Model.Event<I>[]): I;
463
419
  static meta<T extends Class>(this: T): T;
464
420
  static meta<T extends Class, K extends keyof T>(this: T, key: K, expect: true): Exclude<T[K], undefined>;
465
421
  static meta<T extends Class, K extends keyof T>(this: T, key: K, expect?: boolean): T[K];
@@ -469,6 +425,32 @@ declare class MVC extends Model {
469
425
  static meta<T, M extends Class>(this: M, from: (this: M, state: M) => T, expect?: boolean): T;
470
426
  }
471
427
 
428
+ declare const LOCAL = "$debug local";
429
+ declare const STATE = "$debug state";
430
+ declare const UPDATE = "$debug update";
431
+ declare const CONTROL = "$debug controller";
432
+ declare const Debug: {
433
+ readonly CONTROL: "$debug controller";
434
+ readonly LOCAL: "$debug local";
435
+ readonly STATE: "$debug state";
436
+ readonly UPDATE: "$debug update";
437
+ };
438
+ declare type Debug<T extends {}> = T & {
439
+ /** Controller for this instance. */
440
+ [CONTROL]?: Control<T>;
441
+ /** Current subscriber (if present) while used in a live context (e.g. hook or effect). */
442
+ [LOCAL]?: Subscriber<T>;
443
+ /** Current state of this instance. */
444
+ [STATE]?: Model.Values<T>;
445
+ /**
446
+ * Last update causing a refresh to subscribers.
447
+ *
448
+ * If accessed directly, will contain all keys from last push.
449
+ * If within a subscribed function, will contain only keys which explicitly caused a refresh.
450
+ */
451
+ [UPDATE]?: readonly Model.Event<T>[];
452
+ };
453
+
472
454
  declare namespace Consumer {
473
455
  type HasProps<E extends Class> = {
474
456
  /** @deprecated - use for instead */
@@ -510,28 +492,28 @@ declare class Lookup {
510
492
  private table;
511
493
  get local(): Model[];
512
494
  private key;
513
- get(T: typeof Model): any;
495
+ get(T: Model.Type): any;
514
496
  push(): this;
515
- inject(T: typeof Model, I: Model, writable?: boolean): void;
497
+ inject(T: Model.Type, I: Model, writable?: boolean): void;
516
498
  pop(): void;
517
499
  }
500
+ declare function useContext<T extends Model>(Type: Model.Type<T>, required: false): T | undefined;
501
+ declare function useContext<T extends Model>(Type: Model.Type<T>, arg?: boolean): T;
502
+ declare function useContext<T extends Model>(Type: Model.Type<T>, effect: (found: T) => Callback | void): T;
503
+ declare function useContext<T extends Model, K extends Model.Field<T>>(Type: Model.Type<T>, key: K): T[K];
518
504
 
519
505
  declare namespace Provider {
520
- type Item = Model | typeof Model;
521
- type Collection<T extends Item> = T[] | {
506
+ type Item = Model | Model.Type;
507
+ type Multiple<T extends Item = Item> = T[] | {
522
508
  [key: string]: T;
523
509
  };
524
510
  type Existent<E> = E extends Class ? InstanceType<E> : E extends Model ? E : never;
525
511
  type NormalProps<E, I = Existent<E>> = {
526
- /** @deprecated use for instead. */
527
- of?: never;
528
512
  for: E;
529
- children: React.ReactNode | ((instance: I) => React.ReactNode);
513
+ children?: React.ReactNode | ((instance: I) => React.ReactNode);
530
514
  } & Model.Compat<I>;
531
515
  type MultipleProps<T extends Item> = {
532
- /** @deprecated use for instead. */
533
- of?: never;
534
- for: Collection<T>;
516
+ for: Multiple<T>;
535
517
  children?: React.ReactNode | (() => React.ReactNode);
536
518
  } & Model.Compat<Existent<T>>;
537
519
  type Props<T extends Item> = MultipleProps<T> | NormalProps<T>;
@@ -539,32 +521,34 @@ declare namespace Provider {
539
521
  declare function Provider<T extends Provider.Item>(props: Provider.Props<T>): React.FunctionComponentElement<React.ProviderProps<Lookup>>;
540
522
 
541
523
  declare class Global extends MVC {
542
- static create<T extends Class>(this: T, ...args: ConstructorParameters<T>): InstanceOf<T>;
524
+ constructor();
525
+ kill(force?: boolean): boolean;
526
+ static keepAlive: boolean;
527
+ static new<T extends Class>(this: T, ...args: ConstructorParameters<T>): InstanceOf<T>;
543
528
  /**
544
529
  * Update the active instance of this class.
545
530
  * Returns a thenable; resolves after successful update.
546
531
  * If instance does not already exist, one will be created.
547
532
  */
548
- static set<T extends typeof Global>(this: T, updates: Partial<InstanceOf<T>>): any;
533
+ static set<T extends typeof Global>(this: T, values: Model.Compat<InstanceOf<T>, Global>): PromiseLike<Exclude<keyof InstanceOf<T> & string, keyof Global>[]>;
549
534
  /**
550
535
  * **React Hook** - Fetch most instance of this controller from context, if it exists.
551
536
  *
552
537
  * @param required - If false, may return undefined.
553
538
  */
554
- static get<T extends Class>(this: T, required: false): InstanceOf<T> | undefined;
539
+ static get<T extends Global>(this: Model.Type<T>, required: false): T | undefined;
555
540
  /**
556
541
  * **React Hook** - Fetch most instance of this controller from context.
557
542
  *
558
543
  * @param required - Unless false, will throw where instance cannot be found.
559
544
  */
560
- static get<T extends Class>(this: T, required?: boolean): InstanceOf<T>;
545
+ static get<T extends Global>(this: Model.Type<T>, required?: boolean): T;
561
546
  /**
562
547
  * **React Hook** - Fetch specific value from instance of this controller in context.
563
548
  */
564
- static get<T extends Class, K extends Model.Field<InstanceOf<T>>>(this: T, key: K): InstanceOf<T>[K];
549
+ static get<T extends Global, K extends Model.Field<T, Global>>(this: Model.Type<T>, key: K): T[K];
565
550
  /** Destroy current instance of Global, if it exists. */
566
551
  static reset(): void;
567
- destroy(): void;
568
552
  }
569
553
 
570
554
  /**
@@ -578,8 +562,8 @@ declare class Global extends MVC {
578
562
  * - If argument is inadequate, but required, your implemention should simply throw.
579
563
  * - If inadequate and not required, conditionally return false.
580
564
  */
581
- declare function tap<T extends Class>(Type: T, callback?: (instance?: InstanceOf<T>) => void | true): InstanceOf<T>;
582
- declare function tap<T extends Class>(Type: T, callback?: (instance?: InstanceOf<T>) => void | boolean): InstanceOf<T> | undefined;
565
+ declare function tap<T extends Model>(Type: Model.Type<T>, callback?: (instance?: T) => void | true): T;
566
+ declare function tap<T extends Model>(Type: Model.Type<T>, callback?: (instance?: T) => void | boolean): T | undefined;
583
567
  /**
584
568
  * Find and attach most applicable instance of Model via context.
585
569
  *
@@ -589,35 +573,23 @@ declare function tap<T extends Class>(Type: T, callback?: (instance?: InstanceOf
589
573
  * @param Type - Type of controller to attach to property.
590
574
  * @param required - Throw if instance of Type cannot be found.
591
575
  */
592
- declare function tap<T extends Class>(Type: T, required: true): InstanceOf<T>;
593
- declare function tap<T extends Class>(Type: T, required?: boolean): InstanceOf<T> | undefined;
576
+ declare function tap<T extends Model>(Type: Model.Type<T>, required: true): T;
577
+ declare function tap<T extends Model>(Type: Model.Type<T>, required?: boolean): T | undefined;
594
578
 
595
- declare function useFrom<T extends Stateful, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
596
- declare function useFrom<T extends Stateful, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect?: boolean): R;
579
+ declare function useFrom<T extends {}, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
580
+ declare function useFrom<T extends {}, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect?: boolean): R;
597
581
 
598
- declare function useLocal<T extends typeof Model>(Type: T, required: false): InstanceOf<T> | undefined;
599
- declare function useLocal<T extends typeof Model>(Type: T, arg?: boolean): InstanceOf<T>;
600
- declare function useLocal<T extends typeof Model, I extends InstanceOf<T>>(Type: T, effect: (found: I) => Callback | void): I;
601
- declare function useLocal<T extends typeof Model, I extends InstanceOf<T>, K extends Model.Field<I>>(Type: T, key: K): I[K];
602
-
603
- declare function useModel<T extends Class, I extends InstanceOf<T>>(source: T, watch: Model.Field<I>[], callback?: (instance: I) => void): I;
604
- declare function useModel<T extends Class, I extends InstanceOf<T>>(source: T, callback?: (instance: I) => void): I;
605
- declare function useModel<T extends Class, I extends InstanceOf<T>>(source: T, apply: Model.Compat<I>, keys?: Model.Event<I>[]): I;
606
- declare function useModel<T extends Stateful>(source: (() => T) | T, watch?: Model.Field<T>[], callback?: (instance: T) => void): T;
607
- declare function useModel<T extends Stateful>(source: (() => T) | T, callback?: (instance: T) => void): T;
608
- declare function useModel<T extends Stateful>(source: (() => T) | T, apply: Model.Compat<T>, keys?: Model.Event<T>[]): T;
582
+ declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), callback?: (instance: T) => void): T;
583
+ declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), watch: Model.Field<T>[], callback?: (instance: T) => void): T;
584
+ declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), apply: Model.Compat<T>, keys?: Model.Event<T>[]): T;
609
585
 
610
586
  declare namespace useTap {
611
- interface Tappable {
612
- new (): Stateful;
613
- new (...args: any[]): Stateful;
614
- get?: () => Stateful;
615
- }
587
+ type Source<T extends Model> = T | Model.Type<T> | (() => T | Model.Type<T>);
616
588
  }
617
- declare function useTap<T extends Stateful>(source: T | (() => T)): T;
618
- declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T | (() => T) | useTap.Tappable, path: K, expect: true): Exclude<T[K], undefined>;
619
- declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T | (() => T) | useTap.Tappable, path: K, expect?: boolean): T[K];
620
- declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
621
- declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect?: boolean): R;
589
+ declare function useTap<T extends Model>(source: useTap.Source<T>): T;
590
+ declare function useTap<T extends Model, K extends Model.Field<T>>(source: useTap.Source<T>, path: K, expect: true): Exclude<T[K], undefined>;
591
+ declare function useTap<T extends Model, K extends Model.Field<T>>(source: useTap.Source<T>, path: K, expect?: boolean): T[K];
592
+ declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
593
+ declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, from: T) => R, expect?: boolean): R;
622
594
 
623
- export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, MVC as default, get, has, ref, set, tap, use, useFrom, useLocal, useModel, useTap };
595
+ export { Consumer, Debug, Global, MVC, MVC as Model, Provider, act, add, MVC as default, get, has, ref, set, tap, use, useContext, useFrom, useModel, useTap };