@expressive/mvc 0.7.1 → 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 +136 -170
- package/lib/index.esm.js +468 -489
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +470 -493
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
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
|
|
12
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
33
|
+
export type Ref<T = any> = {
|
|
49
34
|
(next: T): void;
|
|
50
35
|
current: T | null;
|
|
51
|
-
}
|
|
52
|
-
/** Properties of T
|
|
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> =
|
|
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> =
|
|
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
|
|
70
|
+
export type Values<T, K extends Field<T> = Field<T>> = {
|
|
80
71
|
[P in K]: Value<T[P]>;
|
|
81
72
|
};
|
|
82
73
|
}
|
|
83
|
-
|
|
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
|
|
98
|
-
on<P
|
|
99
|
-
on(
|
|
100
|
-
on<P extends Model.Event<this>>(key: P
|
|
101
|
-
on<P extends Model.Event<this>>(key: P
|
|
102
|
-
on<P extends Model.Event<this>>(key: P
|
|
103
|
-
|
|
104
|
-
|
|
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(
|
|
122
|
-
update(
|
|
123
|
-
update<T>(
|
|
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
|
-
|
|
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
|
|
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
|
|
122
|
+
static isTypeof<T extends Model.Type>(this: T, maybe: any): maybe is T;
|
|
143
123
|
}
|
|
144
124
|
|
|
145
|
-
declare
|
|
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:
|
|
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
|
|
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.
|
|
135
|
+
followers: Set<Model.Control.OnEvent<any>>;
|
|
156
136
|
constructor(subject: T);
|
|
157
|
-
subscribe(callback:
|
|
158
|
-
|
|
159
|
-
addListener(listener:
|
|
160
|
-
ref(key: Model.Field<T>, handler?:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
391
|
-
declare function has<T extends
|
|
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
|
|
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
|
|
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<
|
|
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<
|
|
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
|
|
437
|
-
static tap<
|
|
438
|
-
static tap<
|
|
439
|
-
static tap<T,
|
|
440
|
-
static tap<T,
|
|
441
|
-
static tap<T,
|
|
442
|
-
static tap<T,
|
|
443
|
-
|
|
444
|
-
|
|
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 */
|
|
@@ -506,35 +482,32 @@ declare namespace Consumer {
|
|
|
506
482
|
}
|
|
507
483
|
declare function Consumer<T extends Class>(props: Consumer.Props<T>): any;
|
|
508
484
|
|
|
509
|
-
declare type Collection = Array<Model | typeof Model> | {
|
|
510
|
-
[anything: string]: Model | typeof Model;
|
|
511
|
-
};
|
|
512
485
|
declare class Lookup {
|
|
513
486
|
private table;
|
|
514
487
|
get local(): Model[];
|
|
515
488
|
private key;
|
|
516
|
-
get(T:
|
|
517
|
-
push(
|
|
518
|
-
|
|
489
|
+
get(T: Model.Type): any;
|
|
490
|
+
push(): this;
|
|
491
|
+
inject(T: Model.Type, I: Model, writable?: boolean): void;
|
|
519
492
|
pop(): void;
|
|
520
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];
|
|
521
498
|
|
|
522
499
|
declare namespace Provider {
|
|
523
|
-
type Item = Model |
|
|
524
|
-
type
|
|
500
|
+
type Item = Model | Model.Type;
|
|
501
|
+
type Multiple<T extends Item = Item> = T[] | {
|
|
525
502
|
[key: string]: T;
|
|
526
503
|
};
|
|
527
504
|
type Existent<E> = E extends Class ? InstanceType<E> : E extends Model ? E : never;
|
|
528
505
|
type NormalProps<E, I = Existent<E>> = {
|
|
529
|
-
/** @deprecated use for instead. */
|
|
530
|
-
of?: never;
|
|
531
506
|
for: E;
|
|
532
|
-
children
|
|
507
|
+
children?: React.ReactNode | ((instance: I) => React.ReactNode);
|
|
533
508
|
} & Model.Compat<I>;
|
|
534
509
|
type MultipleProps<T extends Item> = {
|
|
535
|
-
|
|
536
|
-
of?: never;
|
|
537
|
-
for: Collection<T>;
|
|
510
|
+
for: Multiple<T>;
|
|
538
511
|
children?: React.ReactNode | (() => React.ReactNode);
|
|
539
512
|
} & Model.Compat<Existent<T>>;
|
|
540
513
|
type Props<T extends Item> = MultipleProps<T> | NormalProps<T>;
|
|
@@ -542,32 +515,34 @@ declare namespace Provider {
|
|
|
542
515
|
declare function Provider<T extends Provider.Item>(props: Provider.Props<T>): React.FunctionComponentElement<React.ProviderProps<Lookup>>;
|
|
543
516
|
|
|
544
517
|
declare class Global extends MVC {
|
|
545
|
-
|
|
518
|
+
constructor();
|
|
519
|
+
kill(force?: boolean): boolean;
|
|
520
|
+
static keepAlive: boolean;
|
|
521
|
+
static new<T extends Class>(this: T, ...args: ConstructorParameters<T>): InstanceOf<T>;
|
|
546
522
|
/**
|
|
547
523
|
* Update the active instance of this class.
|
|
548
524
|
* Returns a thenable; resolves after successful update.
|
|
549
525
|
* If instance does not already exist, one will be created.
|
|
550
526
|
*/
|
|
551
|
-
static set<T extends typeof Global>(this: T,
|
|
527
|
+
static set<T extends typeof Global>(this: T, values: Model.Compat<InstanceOf<T>, Global>): PromiseLike<Exclude<keyof InstanceOf<T> & string, keyof Global>[]>;
|
|
552
528
|
/**
|
|
553
529
|
* **React Hook** - Fetch most instance of this controller from context, if it exists.
|
|
554
530
|
*
|
|
555
531
|
* @param required - If false, may return undefined.
|
|
556
532
|
*/
|
|
557
|
-
static get<T extends
|
|
533
|
+
static get<T extends Global>(this: Model.Type<T>, required: false): T | undefined;
|
|
558
534
|
/**
|
|
559
535
|
* **React Hook** - Fetch most instance of this controller from context.
|
|
560
536
|
*
|
|
561
537
|
* @param required - Unless false, will throw where instance cannot be found.
|
|
562
538
|
*/
|
|
563
|
-
static get<T extends
|
|
539
|
+
static get<T extends Global>(this: Model.Type<T>, required?: boolean): T;
|
|
564
540
|
/**
|
|
565
541
|
* **React Hook** - Fetch specific value from instance of this controller in context.
|
|
566
542
|
*/
|
|
567
|
-
static get<T extends
|
|
543
|
+
static get<T extends Global, K extends Model.Field<T, Global>>(this: Model.Type<T>, key: K): T[K];
|
|
568
544
|
/** Destroy current instance of Global, if it exists. */
|
|
569
545
|
static reset(): void;
|
|
570
|
-
destroy(): void;
|
|
571
546
|
}
|
|
572
547
|
|
|
573
548
|
/**
|
|
@@ -581,8 +556,8 @@ declare class Global extends MVC {
|
|
|
581
556
|
* - If argument is inadequate, but required, your implemention should simply throw.
|
|
582
557
|
* - If inadequate and not required, conditionally return false.
|
|
583
558
|
*/
|
|
584
|
-
declare function tap<T extends
|
|
585
|
-
declare function tap<T extends
|
|
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;
|
|
586
561
|
/**
|
|
587
562
|
* Find and attach most applicable instance of Model via context.
|
|
588
563
|
*
|
|
@@ -592,35 +567,26 @@ declare function tap<T extends Class>(Type: T, callback?: (instance?: InstanceOf
|
|
|
592
567
|
* @param Type - Type of controller to attach to property.
|
|
593
568
|
* @param required - Throw if instance of Type cannot be found.
|
|
594
569
|
*/
|
|
595
|
-
declare function tap<T extends
|
|
596
|
-
declare function tap<T extends
|
|
597
|
-
|
|
598
|
-
declare function useFrom<T extends Stateful, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
599
|
-
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;
|
|
600
572
|
|
|
601
|
-
declare function
|
|
602
|
-
declare function
|
|
603
|
-
declare function useLocal<T extends typeof Model, I extends InstanceOf<T>>(Type: T, effect: (found: I) => Callback | void): I;
|
|
604
|
-
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;
|
|
605
575
|
|
|
606
|
-
declare function useModel<T extends
|
|
607
|
-
declare function useModel<T extends
|
|
608
|
-
declare function useModel<T extends
|
|
609
|
-
declare function useModel<T extends
|
|
610
|
-
declare function useModel<T extends
|
|
611
|
-
declare function useModel<T extends
|
|
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;
|
|
612
582
|
|
|
613
583
|
declare namespace useTap {
|
|
614
|
-
|
|
615
|
-
new (): Stateful;
|
|
616
|
-
new (...args: any[]): Stateful;
|
|
617
|
-
get?: () => Stateful;
|
|
618
|
-
}
|
|
584
|
+
type Source<T extends Model> = T | Model.Type<T> | (() => T | Model.Type<T>);
|
|
619
585
|
}
|
|
620
|
-
declare function useTap<T extends
|
|
621
|
-
declare function useTap<T extends
|
|
622
|
-
declare function useTap<T extends
|
|
623
|
-
declare function useTap<T extends
|
|
624
|
-
declare function useTap<T extends
|
|
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;
|
|
625
591
|
|
|
626
|
-
export {
|
|
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 };
|