@expressive/mvc 1.0.0-beta.3 → 1.0.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -17
- package/lib/index.esm.js +1238 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +1038 -848
- package/lib/index.js.map +1 -0
- package/package.json +12 -13
- package/types/context.d.ts +57 -0
- package/types/index.d.ts +3 -21
- package/types/instructions.d.ts +252 -107
- package/types/model.d.ts +229 -37
- package/types/selector.ts +18 -0
- package/types/types.d.ts +7 -3
- package/types/controller.d.ts +0 -56
- package/types/react.d.ts +0 -46
package/types/model.d.ts
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Key } from 'react';
|
|
2
2
|
|
|
3
|
-
import Controller from './controller';
|
|
4
3
|
import Lifecycle from './lifecycle';
|
|
5
|
-
import { Selector } from './selector';
|
|
6
|
-
import { Class, InstanceOf,
|
|
4
|
+
import { Select, Selector } from './selector';
|
|
5
|
+
import { BunchOf, Callback, Class, InstanceOf, Query, RequestCallback, UpdateCallback } from './types';
|
|
6
|
+
|
|
7
|
+
interface PropertyDescriptor<T> {
|
|
8
|
+
configurable?: boolean;
|
|
9
|
+
enumerable?: boolean;
|
|
10
|
+
value?: T;
|
|
11
|
+
writable?: boolean;
|
|
12
|
+
get?(): T;
|
|
13
|
+
set?(v: T): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type Argument<T> = T extends (arg: infer U) => any ? U : never;
|
|
17
|
+
|
|
18
|
+
type Thenable<T> = {
|
|
19
|
+
then(onFulfilled: (arg: T) => void): void;
|
|
20
|
+
}
|
|
7
21
|
|
|
8
22
|
export namespace Model {
|
|
23
|
+
/** Exotic value, actual value is contained. */
|
|
24
|
+
interface Ref<T = any> {
|
|
25
|
+
(next: T): void;
|
|
26
|
+
current: T | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type GetFunction<T> = (within?: Subscriber) => T;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Property initializer, will run upon instance creation.
|
|
33
|
+
* Optional returned callback will run when once upon first access.
|
|
34
|
+
*/
|
|
35
|
+
type Instruction<T> = (this: Controller, key: string, thisArg: Controller) =>
|
|
36
|
+
void | GetFunction<T> | PropertyDescriptor<T>;
|
|
37
|
+
|
|
9
38
|
/** Shallow replacement given all entries of Model */
|
|
10
39
|
type Overlay<T, R> = { [K in keyof Entries<T>]: R };
|
|
11
40
|
|
|
@@ -15,6 +44,14 @@ export namespace Model {
|
|
|
15
44
|
/** Object containing data found in T. */
|
|
16
45
|
type Entries<T, E = Model> = Pick<T, Fields<T, E>>;
|
|
17
46
|
|
|
47
|
+
/** Actual value stored in state. */
|
|
48
|
+
type Value<R> = R extends Ref<infer T> ? T : R;
|
|
49
|
+
|
|
50
|
+
/** Values from current state of given controller. */
|
|
51
|
+
type State<T, K extends keyof T = Fields<T, Model>> = {
|
|
52
|
+
[P in K]: Value<T[P]>;
|
|
53
|
+
}
|
|
54
|
+
|
|
18
55
|
/** Object comperable to data which may be found in T. */
|
|
19
56
|
type Data<T, E = Model> = Partial<Entries<T, E>>;
|
|
20
57
|
|
|
@@ -65,11 +102,81 @@ export namespace Model {
|
|
|
65
102
|
type SelectFields<T> = Selector.Function<Omit<T, keyof Model>>;
|
|
66
103
|
|
|
67
104
|
type SelectField<T> = (arg: Omit<T, keyof Model>) => any;
|
|
105
|
+
|
|
106
|
+
type SelectFieldKey<T> = Select.Key<Fields<T>>;
|
|
107
|
+
|
|
108
|
+
type Typeof<T, ST, X extends keyof T = Exclude<keyof T, keyof Model>> = {
|
|
109
|
+
[Key in X]: T[Key] extends ST ? Key : never;
|
|
110
|
+
}[X];
|
|
111
|
+
|
|
112
|
+
type SelectTypeof<T, ST> = Select.Key<Typeof<T, ST>>;
|
|
113
|
+
|
|
114
|
+
type HandleValue = (value: any) => boolean | void;
|
|
115
|
+
|
|
116
|
+
export namespace Controller {
|
|
117
|
+
export type Listen = (key: string, source: Controller) =>
|
|
118
|
+
RequestCallback | undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export class Controller {
|
|
122
|
+
state: BunchOf<any>;
|
|
123
|
+
subject: {};
|
|
124
|
+
waiting: Set<RequestCallback>;
|
|
125
|
+
|
|
126
|
+
/** Add property to managed state. */
|
|
127
|
+
manage(key: string, initial: any, effect?: HandleValue): void;
|
|
128
|
+
|
|
129
|
+
select(using?: Query): string[];
|
|
130
|
+
|
|
131
|
+
setter(key: string, effect?: HandleValue): (value: any) => boolean | void;
|
|
132
|
+
|
|
133
|
+
addListener(listener: Controller.Listen): Callback;
|
|
134
|
+
|
|
135
|
+
update(key: string, value?: any): void;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export class Subscriber {
|
|
139
|
+
proxy: any;
|
|
140
|
+
source: any;
|
|
141
|
+
parent: Controller;
|
|
142
|
+
active: boolean;
|
|
143
|
+
listen: Controller.Listen;
|
|
144
|
+
dependant: Set<{
|
|
145
|
+
commit(): void;
|
|
146
|
+
release(): void;
|
|
147
|
+
}>;
|
|
148
|
+
|
|
149
|
+
follow(key: string, cb?: RequestCallback | undefined): void;
|
|
150
|
+
commit(): Callback;
|
|
151
|
+
release(): Callback;
|
|
152
|
+
onUpdate(): void;
|
|
153
|
+
}
|
|
68
154
|
}
|
|
69
155
|
|
|
70
|
-
|
|
156
|
+
declare const CONTROL: unique symbol;
|
|
157
|
+
declare const UPDATE: unique symbol;
|
|
158
|
+
declare const LOCAL: unique symbol;
|
|
159
|
+
declare const STATE: unique symbol;
|
|
71
160
|
|
|
161
|
+
export interface Model extends Lifecycle {}
|
|
72
162
|
export abstract class Model {
|
|
163
|
+
/** Controller for this instance. */
|
|
164
|
+
[CONTROL]: Model.Controller;
|
|
165
|
+
|
|
166
|
+
/** Current state of this instance. */
|
|
167
|
+
[STATE]?: Model.State<this>;
|
|
168
|
+
|
|
169
|
+
/** Current subscriber (if present) while used in a live context (e.g. hook or effect). */
|
|
170
|
+
[LOCAL]?: Model.Subscriber;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Last update causing a refresh to subscribers.
|
|
174
|
+
*
|
|
175
|
+
* If accessed directly, will contain all keys from last push.
|
|
176
|
+
* If within a subscribed function, will contain only keys which explicitly caused a refresh.
|
|
177
|
+
**/
|
|
178
|
+
[UPDATE]?: readonly string[];
|
|
179
|
+
|
|
73
180
|
/**
|
|
74
181
|
* Circular reference to `this` controller.
|
|
75
182
|
*
|
|
@@ -129,15 +236,35 @@ export abstract class Model {
|
|
|
129
236
|
*/
|
|
130
237
|
set: this;
|
|
131
238
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
239
|
+
import <O extends Model.Data<this>> (via: O, select?: string[] | Model.SelectFields<this>): void;
|
|
240
|
+
|
|
241
|
+
export(): Model.State<this>;
|
|
242
|
+
export <P extends Model.Fields<this>> (select: P[]): Model.State<this, P>;
|
|
243
|
+
export <S extends Model.SelectFields<this>> (select: S): Model.State<this, Selector.From<S>>;
|
|
244
|
+
|
|
245
|
+
update(): PromiseLike<readonly string[] | false>;
|
|
246
|
+
update(strict: true): Promise<readonly string[]>;
|
|
247
|
+
update(strict: false): Promise<false>;
|
|
248
|
+
update(strict: boolean): Promise<readonly string[] | false>;
|
|
249
|
+
|
|
250
|
+
update(keys: Model.Fields<this>): Thenable<readonly string[]>;
|
|
251
|
+
update(keys: Model.SelectFieldKey<this>): Thenable<readonly string[]>;
|
|
252
|
+
|
|
253
|
+
update(keys: Model.Fields<this>, callMethod: boolean): PromiseLike<readonly string[]>;
|
|
254
|
+
update(keys: Model.SelectFields<this>, callMethod: boolean): PromiseLike<readonly string[]>;
|
|
255
|
+
|
|
256
|
+
update<T>(keys: Model.Fields<this>, argument: T): PromiseLike<readonly string[]>;
|
|
257
|
+
update<T>(keys: Model.SelectFields<this>, argument: T): PromiseLike<readonly string[]>;
|
|
258
|
+
|
|
259
|
+
/*
|
|
260
|
+
Issue with self-reference, using fallback.
|
|
261
|
+
|
|
262
|
+
update(keys: Model.Typeof<this, () => void>, callMethod: boolean): Thenable<string[]>;
|
|
263
|
+
update(keys: Model.SelectTypeof<this, () => void>, callMethod: boolean): Thenable<string[]>;
|
|
264
|
+
|
|
265
|
+
update<T>(keys: Model.Typeof<this, (arg: T) => void>, argument: T): Thenable<string[]>;
|
|
266
|
+
update<T>(keys: Model.SelectTypeof<this, (arg: T) => void>, argument: T): Thenable<string[]>;
|
|
267
|
+
*/
|
|
141
268
|
|
|
142
269
|
/**
|
|
143
270
|
* Mark this instance for garbage-collection and send `willDestroy` event to all listeners.
|
|
@@ -167,24 +294,79 @@ export abstract class Model {
|
|
|
167
294
|
|
|
168
295
|
tap <K extends Model.SelectField<this>> (key: K, expect?: boolean): ReturnType<K>;
|
|
169
296
|
tap <K extends Model.SelectField<this>> (key: K, expect: true): Exclude<ReturnType<K>, undefined>;
|
|
297
|
+
|
|
298
|
+
// Keyed
|
|
299
|
+
on <S extends Model.SelectEvents<this>> (via: S, cb: Selector.Callback<S, this>, squash?: false, once?: boolean): Callback;
|
|
300
|
+
on <P = Model.EventsCompat<this>> (keys: [], listener: UpdateCallback<this, P>, squash?: false, once?: boolean): Callback;
|
|
301
|
+
on <P extends Model.EventsCompat<this>> (key: P | P[], listener: UpdateCallback<this, P>, squash?: false, once?: boolean): Callback;
|
|
302
|
+
// Squash
|
|
303
|
+
on <S extends Model.SelectEvents<this>> (via: S, cb: (keys: Selector.From<S>[]) => void, squash: true, once?: boolean): Callback;
|
|
304
|
+
on <P = Model.EventsCompat<this>> (keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
|
|
305
|
+
on <P extends Model.EventsCompat<this>> (key: P | P[], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
|
|
306
|
+
// Unknown
|
|
307
|
+
on <S extends Model.SelectEvents<this>> (via: S, cb: unknown, squash: boolean, once?: boolean): Callback;
|
|
308
|
+
on (keys: [], listener: unknown, squash: boolean, once?: boolean): Callback;
|
|
309
|
+
on <P extends Model.EventsCompat<this>> (key: P | P[], listener: unknown, squash: boolean, once?: boolean): Callback;
|
|
310
|
+
|
|
311
|
+
// Keyed
|
|
312
|
+
once <S extends Model.SelectEvents<this>> (via: S, cb: Selector.Callback<S, this>, squash?: false): Callback;
|
|
313
|
+
once <P = Model.EventsCompat<this>> (keys: [], listener: UpdateCallback<this, P>, squash?: false, once?: boolean): Callback;
|
|
314
|
+
once <P extends Model.EventsCompat<this>> (key: P | P[], listener: UpdateCallback<this, P>, squash?: false): Callback;
|
|
315
|
+
// Squash
|
|
316
|
+
once <S extends Model.SelectEvents<this>> (via: S, cb: (keys: Selector.From<S>[]) => void, squash: true): Callback;
|
|
317
|
+
once <P = Model.EventsCompat<this>> (keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
|
|
318
|
+
once <P extends Model.EventsCompat<this>> (key: P | P[], listener: (keys: P[]) => void, squash: true): Callback;
|
|
319
|
+
// Promise
|
|
320
|
+
once <S extends Model.SelectEvents<this>> (via: S): Promise<Selector.From<S>[]>;
|
|
321
|
+
once <P = Model.EventsCompat<this>> (keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
|
|
322
|
+
once <P extends Model.EventsCompat<this>> (key: P | P[]): Promise<P[]>;
|
|
323
|
+
// Unknown
|
|
324
|
+
once <S extends Model.SelectEvents<this>> (via: S, cb: unknown, squash: boolean): Callback;
|
|
325
|
+
once (keys: [], listener: unknown, squash: boolean, once?: boolean): Callback;
|
|
326
|
+
once <P extends Model.EventsCompat<this>> (key: P | P[], listener: unknown, squash: boolean): Callback;
|
|
327
|
+
|
|
328
|
+
effect(callback: (this: this, state: this) => void, select?: Model.SelectFields<this>): Callback;
|
|
329
|
+
effect(callback: (this: this, state: this) => void, select?: []): Callback;
|
|
330
|
+
effect(callback: (this: this, state: this) => void, select?: (keyof this)[]): Callback;
|
|
170
331
|
|
|
171
332
|
/**
|
|
172
|
-
* **React Hook** - Attach to instance of this controller within
|
|
333
|
+
* **React Hook** - Attach to instance of this controller within a component.
|
|
173
334
|
*
|
|
174
335
|
* This method will fire lifecycle events on given controller.
|
|
175
336
|
*
|
|
176
337
|
* @param id - Argument passed to controller-lifecycle methods. Use to identify the consumer.
|
|
177
338
|
*/
|
|
178
|
-
|
|
339
|
+
tag(id?: any): this;
|
|
179
340
|
|
|
180
341
|
/**
|
|
181
|
-
* **React Hook** -
|
|
342
|
+
* **React Hook** - Subscribe to instance of controller within a component.
|
|
182
343
|
*
|
|
183
|
-
* This method will fire lifecycle events on given controller
|
|
344
|
+
* This method will fire lifecycle events on given controller (as element)..
|
|
184
345
|
*
|
|
185
346
|
* @param idFactory - Will be invoked with fetched instance. Use this to register a tag as-needed.
|
|
186
347
|
*/
|
|
187
|
-
|
|
348
|
+
tag(idFactory: (idFactory: this) => any): this;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* **React Hook** - Subscribe to instance of controller within a component.
|
|
352
|
+
*
|
|
353
|
+
* This method will fire lifecycle events on given controller (as component).
|
|
354
|
+
*
|
|
355
|
+
* @param callback - Run once before subscription begins.
|
|
356
|
+
*/
|
|
357
|
+
use(callback?: (instance: this) => void): this;
|
|
358
|
+
|
|
359
|
+
/** Use symbol to access controller of a model. */
|
|
360
|
+
static CONTROL: typeof CONTROL;
|
|
361
|
+
|
|
362
|
+
/** Use symbol to access current state of a model. */
|
|
363
|
+
static STATE: typeof STATE;
|
|
364
|
+
|
|
365
|
+
/** Use symbol to access current subscriber of a model in a live context (e.g. hook or effect). */
|
|
366
|
+
static LOCAL: typeof LOCAL;
|
|
367
|
+
|
|
368
|
+
/** Use symbol to access keys affected by last update. */
|
|
369
|
+
static WHY: typeof UPDATE;
|
|
188
370
|
|
|
189
371
|
/**
|
|
190
372
|
* Creates a new instance of this controller.
|
|
@@ -200,17 +382,19 @@ export abstract class Model {
|
|
|
200
382
|
*
|
|
201
383
|
* Differs from `use()` in lacking subscription and lifecycle events.
|
|
202
384
|
* Much more efficient if you don't need hook-based features.
|
|
385
|
+
*
|
|
386
|
+
* @param callback - Run after creation of instance.
|
|
203
387
|
*/
|
|
204
|
-
static new <T extends Class> (this: T,
|
|
388
|
+
static new <T extends Class> (this: T, callback?: (instance: InstanceOf<T>) => void): InstanceOf<T>;
|
|
205
389
|
|
|
206
390
|
/**
|
|
207
391
|
* **React Hook** - Create and attach an instance of this controller a react component.
|
|
208
392
|
*
|
|
209
393
|
* Note: Model will be destroyed when ambient component unmounts!
|
|
210
394
|
*
|
|
211
|
-
* @param
|
|
395
|
+
* @param callback - Run after creation of instance.
|
|
212
396
|
*/
|
|
213
|
-
static use <T extends Class> (this: T,
|
|
397
|
+
static use <T extends Class> (this: T, callback?: (instance: InstanceOf<T>) => void): InstanceOf<T>;
|
|
214
398
|
|
|
215
399
|
/**
|
|
216
400
|
* **React Hook** - Similar to `use`, will instanciate a controller bound to ambient component.
|
|
@@ -218,7 +402,7 @@ export abstract class Model {
|
|
|
218
402
|
*
|
|
219
403
|
* @param data - Data to be applied to controller upon creation.
|
|
220
404
|
*/
|
|
221
|
-
static uses <T extends Class, I extends InstanceOf<T>, D extends Partial<I>> (this: T, data: D): I;
|
|
405
|
+
static uses <T extends Class, I extends InstanceOf<T>, D extends Partial<I>> (this: T, data: D, only?: (keyof D)[]): I;
|
|
222
406
|
|
|
223
407
|
/**
|
|
224
408
|
* **React Hook** - Similar to `uses`, will instanciate a controller includive of given data.
|
|
@@ -227,7 +411,13 @@ export abstract class Model {
|
|
|
227
411
|
*
|
|
228
412
|
* @param data - Data to be observed by controller.
|
|
229
413
|
*/
|
|
230
|
-
static using <T extends Class, I extends InstanceOf<T>, D extends Partial<I>> (this: T, data: D): I;
|
|
414
|
+
static using <T extends Class, I extends InstanceOf<T>, D extends Partial<I>> (this: T, data: D, only?: (keyof D)[]): I;
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* **React Hook** - Locate most relevant instance of this type in context.
|
|
418
|
+
*/
|
|
419
|
+
static find <T extends Class>(this: T, strict: true): InstanceOf<T>;
|
|
420
|
+
static find <T extends Class>(this: T, strict?: boolean): InstanceOf<T> | undefined;
|
|
231
421
|
|
|
232
422
|
/**
|
|
233
423
|
* **React Hook** - Fetch most instance of this controller from context, if it exists.
|
|
@@ -298,7 +488,7 @@ export abstract class Model {
|
|
|
298
488
|
*
|
|
299
489
|
* Documentation TBD.
|
|
300
490
|
*/
|
|
301
|
-
static meta <T extends Class>(this: T): T
|
|
491
|
+
static meta <T extends Class>(this: T): T;
|
|
302
492
|
|
|
303
493
|
/**
|
|
304
494
|
* **React Hook** - Fetch and subscribe to value defined on class itself using selectors.
|
|
@@ -307,25 +497,27 @@ export abstract class Model {
|
|
|
307
497
|
*/
|
|
308
498
|
static meta <T extends Class, K extends Model.SelectField<T>> (this: T, key?: K): ReturnType<K>;
|
|
309
499
|
|
|
310
|
-
/**
|
|
311
|
-
* **React Hook** - Locate most relevant instance of this type in context.
|
|
312
|
-
*/
|
|
313
|
-
static find <T extends Class>(this: T): InstanceOf<T>;
|
|
314
|
-
|
|
315
500
|
/**
|
|
316
501
|
* Static equivalent of `x instanceof this`.
|
|
317
502
|
*
|
|
318
503
|
* Will determine if provided class is a subtype of this one.
|
|
319
504
|
*/
|
|
320
505
|
static isTypeof <T extends Class>(this: T, subject: any): subject is T;
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Retreives parent inherited by this class, unless it is base `Model`.
|
|
324
|
-
*/
|
|
325
|
-
static inherits: typeof Model | undefined;
|
|
326
506
|
}
|
|
327
507
|
|
|
328
508
|
export class Singleton extends Model {
|
|
329
|
-
/**
|
|
330
|
-
static
|
|
509
|
+
/** Get current instance of this singleton. Will throw if one does not exist. */
|
|
510
|
+
static is<T extends Class>(this: T): InstanceOf<T>;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Update the active instance of this class.
|
|
514
|
+
* Returns a thenable; resolves after successful update.
|
|
515
|
+
* If instance does not already exist, one will be created.
|
|
516
|
+
**/
|
|
517
|
+
static update<T extends Class>(
|
|
518
|
+
this: T, updates: Model.Data<InstanceOf<T>>
|
|
519
|
+
): PromiseLike<string[] | false>;
|
|
520
|
+
|
|
521
|
+
/** Destroy current instance of Singleton, if it exists. */
|
|
522
|
+
static reset(): void;
|
|
331
523
|
}
|
package/types/selector.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export type KeysOfType<T, ST> = {
|
|
2
|
+
[Key in keyof T]: T[Key] extends ST ? Key : never
|
|
3
|
+
}[keyof T];
|
|
4
|
+
|
|
1
5
|
export namespace Selector {
|
|
2
6
|
/**
|
|
3
7
|
* Shallow-recursive clone of source object.
|
|
@@ -26,4 +30,18 @@ export namespace Selector {
|
|
|
26
30
|
|
|
27
31
|
export type Gets<F extends Function<any>> =
|
|
28
32
|
F extends (spy: any) => infer R ? Values<R> : never;
|
|
33
|
+
|
|
34
|
+
export type Callback<S extends Function<any>, T> =
|
|
35
|
+
(this: T, value: Gets<S>, key: From<S>) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export namespace Select {
|
|
39
|
+
export type One<T> =
|
|
40
|
+
(arg: { [K in keyof T]: K }) => string & keyof T;
|
|
41
|
+
|
|
42
|
+
export type Key<T extends string | number | symbol> =
|
|
43
|
+
(arg: { [K in T]: K }) => string & T;
|
|
44
|
+
|
|
45
|
+
export type From<T extends One<any>> =
|
|
46
|
+
T extends (from: any) => infer R ? R : never;
|
|
29
47
|
}
|
package/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type Key = string | symbol | number;
|
|
2
|
-
export type Async = (...args: any[]) => Promise<any>;
|
|
2
|
+
export type Async<T = any> = (this: T, ...args: any[]) => Promise<any>;
|
|
3
3
|
export type BunchOf<T> = { [key: string]: T };
|
|
4
4
|
|
|
5
5
|
export type Class = new (...args: any[]) => any;
|
|
@@ -7,8 +7,12 @@ export type InstanceOf<T> = T extends { prototype: infer U } ? U : never;
|
|
|
7
7
|
export type IfApplicable<T extends {}, K> = K extends keyof T ? T[K] : undefined;
|
|
8
8
|
|
|
9
9
|
export type Callback = () => void;
|
|
10
|
-
export type RequestCallback = (keys
|
|
10
|
+
export type RequestCallback = (keys: readonly string[]) => void;
|
|
11
11
|
export type EffectCallback<T, A = T> = (this: T, argument: A) => Callback | Promise<any> | void;
|
|
12
12
|
export type UpdateCallback<T, P> = (this: T, value: IfApplicable<T, P>, changed: P) => void;
|
|
13
|
+
export type InterceptCallback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
13
14
|
|
|
14
|
-
export type RefFunction = (e: HTMLElement | null) => void;
|
|
15
|
+
export type RefFunction = (e: HTMLElement | null) => void;
|
|
16
|
+
|
|
17
|
+
export type Recursive<T> = { [K in keyof T]: Recursive<Omit<T, K>> };
|
|
18
|
+
export type Query = (select: Recursive<{}>) => void;
|
package/types/controller.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Model } from './model';
|
|
2
|
-
import { Selector } from './selector';
|
|
3
|
-
import { Callback, EffectCallback, UpdateCallback } from './types';
|
|
4
|
-
|
|
5
|
-
type CallbackFor<S extends Selector.Function<any>, T> =
|
|
6
|
-
(this: T, value: Selector.Gets<S>, key: Selector.From<S>) => void;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Observable Instance
|
|
10
|
-
*
|
|
11
|
-
* Implements internal value tracking.
|
|
12
|
-
* Able to be subscribed to, per-value to know when updated.
|
|
13
|
-
*/
|
|
14
|
-
interface Dispatch {
|
|
15
|
-
// Explicit all
|
|
16
|
-
on <S extends Model.SelectEvents<this>> (via: S, cb: CallbackFor<S, this>, squash?: false, once?: boolean): Callback;
|
|
17
|
-
on <P extends Model.EventsCompat<this>> (key: P | P[], listener: UpdateCallback<this, P>, squash?: false, once?: boolean): Callback;
|
|
18
|
-
|
|
19
|
-
once <S extends Model.SelectEvents<this>> (via: S, cb: CallbackFor<S, this>, squash?: false): Callback;
|
|
20
|
-
once <P extends Model.EventsCompat<this>> (key: P | P[], listener: UpdateCallback<this, P>, squash?: false): Callback;
|
|
21
|
-
|
|
22
|
-
// Explicit squash
|
|
23
|
-
on <S extends Model.SelectEvents<this>> (via: S, cb: (keys: Selector.From<S>[]) => void, squash: true, once?: boolean): Callback;
|
|
24
|
-
on <P extends Model.EventsCompat<this>> (key: P | P[], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
|
|
25
|
-
|
|
26
|
-
once <S extends Model.SelectEvents<this>> (via: S, cb: (keys: Selector.From<S>[]) => void, squash: true): Callback;
|
|
27
|
-
once <P extends Model.EventsCompat<this>> (key: P | P[], listener: (keys: P[]) => void, squash: true): Callback;
|
|
28
|
-
|
|
29
|
-
// Implicit squash
|
|
30
|
-
once <S extends Model.SelectEvents<this>> (via: S): Promise<Selector.From<S>[]>;
|
|
31
|
-
once <P extends Model.EventsCompat<this>> (key: P | P[]): Promise<P[]>;
|
|
32
|
-
|
|
33
|
-
// Unknown squash
|
|
34
|
-
on <S extends Model.SelectEvents<this>> (via: S, cb: unknown, squash: boolean, once?: boolean): Callback;
|
|
35
|
-
on <P extends Model.EventsCompat<this>> (key: P | P[], listener: unknown, squash: boolean, once?: boolean): Callback;
|
|
36
|
-
|
|
37
|
-
once <S extends Model.SelectEvents<this>> (via: S, cb: unknown, squash: boolean): Callback;
|
|
38
|
-
once <P extends Model.EventsCompat<this>> (key: P | P[], listener: unknown, squash: boolean): Callback;
|
|
39
|
-
|
|
40
|
-
effect(callback: EffectCallback<this>, select?: Model.SelectFields<this>): Callback;
|
|
41
|
-
effect(callback: EffectCallback<this>, select?: (keyof this)[]): Callback;
|
|
42
|
-
|
|
43
|
-
import <O extends Model.Data<this>> (via: O, select?: string[] | Model.SelectFields<this>): void;
|
|
44
|
-
|
|
45
|
-
export(): Model.Entries<this>;
|
|
46
|
-
export <P extends Model.Fields<this>> (select: P[]): Pick<this, P>;
|
|
47
|
-
export <S extends Model.SelectFields<this>> (select: S): Pick<this, Selector.From<S>>;
|
|
48
|
-
|
|
49
|
-
update(keys: Model.SelectFields<this>): void;
|
|
50
|
-
update(keys: Model.Fields<this>[]): void;
|
|
51
|
-
|
|
52
|
-
requestUpdate(strict?: boolean): Promise<string[] | false>;
|
|
53
|
-
requestUpdate(cb: (keys: string[]) => void): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export = Dispatch;
|
package/types/react.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ReactElement } from "react";
|
|
2
|
-
import { Model } from "./model"
|
|
3
|
-
import { Class } from "./types";
|
|
4
|
-
|
|
5
|
-
type ComponentOutput = ReactElement<any, any> | null;
|
|
6
|
-
|
|
7
|
-
type ProviderForProps<E> = E extends Class
|
|
8
|
-
? ({ of: E, children?: React.ReactNode } & Model.Data<InstanceType<E>>)
|
|
9
|
-
| ({ of: E, children?: (instance: InstanceType<E>) => React.ReactNode } & Model.Data<InstanceType<E>>)
|
|
10
|
-
: ({ of: E, children?: React.ReactNode } & Model.Data<E>);
|
|
11
|
-
|
|
12
|
-
type ConsumerProps<E extends Class> =
|
|
13
|
-
| {
|
|
14
|
-
/** Type of controller to fetch from context. */
|
|
15
|
-
of: E;
|
|
16
|
-
/**
|
|
17
|
-
* Getter function. Is called on every natural render of this component.
|
|
18
|
-
* Will throw if usable instance cannot be found in context.
|
|
19
|
-
*/
|
|
20
|
-
has: (value: InstanceType<E>) => void;
|
|
21
|
-
}
|
|
22
|
-
| {
|
|
23
|
-
/** Type of controller to fetch from context. */
|
|
24
|
-
of: E;
|
|
25
|
-
/** Getter function. Is called on every natural render of this component. */
|
|
26
|
-
get: (value: InstanceType<E> | undefined) => void;
|
|
27
|
-
}
|
|
28
|
-
| {
|
|
29
|
-
/** Type of controller to fetch from context. */
|
|
30
|
-
of: E;
|
|
31
|
-
/**
|
|
32
|
-
* Render function, will receive instance of desired controller.
|
|
33
|
-
*
|
|
34
|
-
* Similar to `tap()`, updates to properties accessed in
|
|
35
|
-
* this function will cause a refresh when they change.
|
|
36
|
-
*/
|
|
37
|
-
children: (value: InstanceType<E>) => ComponentOutput;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// type ProvideCollection = Array<Model | typeof Model> | BunchOf<Model | typeof Model>;
|
|
41
|
-
// declare function Provider(props: ProviderOfProps): ComponentOutput;
|
|
42
|
-
|
|
43
|
-
declare function Provider<T>(props: ProviderForProps<T>): ComponentOutput;
|
|
44
|
-
declare function Consumer<T extends Class>(props: ConsumerProps<T>): ComponentOutput;
|
|
45
|
-
|
|
46
|
-
export { Consumer, Provider };
|