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