@expressive/mvc 0.4.6 → 0.6.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 +83 -94
- package/lib/index.esm.js +636 -654
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +636 -657
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
declare type Async<T = any> = (...args: any[]) => Promise<T>;
|
|
4
|
-
/**
|
|
5
|
-
* Sets an exotic method with managed ready-state. Property accepts an async function.
|
|
6
|
-
*
|
|
7
|
-
* When an act-method is invoked, its `active` property to true for duration of call.
|
|
8
|
-
* This is emitted as an update to property, both when called and after returns (or throws).
|
|
9
|
-
*
|
|
10
|
-
* **Note:** Subsequent calls will immediately throw if one is still pending.
|
|
11
|
-
*
|
|
12
|
-
* @param action - Action to fire when resulting property is invoked.
|
|
13
|
-
*/
|
|
14
|
-
declare function act(action: Async): typeof action & {
|
|
15
|
-
active: boolean;
|
|
16
|
-
};
|
|
17
|
-
declare function act<S>(action: Async<S>): typeof action & {
|
|
18
|
-
active: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
declare function array<T = any>(): T[];
|
|
22
|
-
|
|
23
3
|
type Callback = () => void;
|
|
24
4
|
type Class = new (...args: any[]) => any;
|
|
25
5
|
type InstanceOf<T> = T extends { prototype: infer U } ? U : never;
|
|
@@ -39,13 +19,12 @@ declare class Subscriber<T extends Stateful = any> {
|
|
|
39
19
|
constructor(parent: Controller<T>, onUpdate: Controller.OnEvent);
|
|
40
20
|
}
|
|
41
21
|
|
|
42
|
-
declare const CONTROL: unique symbol;
|
|
43
22
|
declare const WHY: unique symbol;
|
|
44
23
|
declare const LOCAL: unique symbol;
|
|
45
24
|
declare const STATE: unique symbol;
|
|
46
25
|
interface Stateful {
|
|
47
26
|
/** Controller for this instance. */
|
|
48
|
-
[CONTROL]
|
|
27
|
+
[CONTROL]?: Controller;
|
|
49
28
|
/** Current subscriber (if present) while used in a live context (e.g. hook or effect). */
|
|
50
29
|
[LOCAL]?: Subscriber;
|
|
51
30
|
/** Current state of this instance. */
|
|
@@ -107,14 +86,6 @@ declare namespace Model {
|
|
|
107
86
|
};
|
|
108
87
|
}
|
|
109
88
|
interface Model extends Stateful {
|
|
110
|
-
/**
|
|
111
|
-
* Circular reference to `this` controller.
|
|
112
|
-
*
|
|
113
|
-
* Useful to obtain full reference where one has already destructured.
|
|
114
|
-
*
|
|
115
|
-
* @deprecated will be removed in favor of `is`
|
|
116
|
-
*/
|
|
117
|
-
get: this;
|
|
118
89
|
/**
|
|
119
90
|
* Circular reference to `this` controller.
|
|
120
91
|
*
|
|
@@ -130,7 +101,6 @@ interface Model extends Stateful {
|
|
|
130
101
|
set: Model.Refs<this>;
|
|
131
102
|
}
|
|
132
103
|
declare class Model {
|
|
133
|
-
static [CONTROL]: Controller;
|
|
134
104
|
static [WHY]: readonly string[];
|
|
135
105
|
constructor();
|
|
136
106
|
get [STATE](): Model.Values<this, Exclude<keyof this & string, keyof Model>>;
|
|
@@ -184,6 +154,7 @@ declare class Model {
|
|
|
184
154
|
static isTypeof<T extends new () => Model>(this: T, maybe: any): maybe is T;
|
|
185
155
|
}
|
|
186
156
|
|
|
157
|
+
declare const CONTROL: unique symbol;
|
|
187
158
|
declare namespace Controller {
|
|
188
159
|
type OnValue<T = any> = (this: T, value: any) => boolean | void;
|
|
189
160
|
type OnEvent<T = any> = (key: Model.Event<T> | null, source: Controller) => Callback | void;
|
|
@@ -239,10 +210,29 @@ declare namespace Instruction {
|
|
|
239
210
|
*/
|
|
240
211
|
declare function apply<T = any>(instruction: Instruction<T>, name?: string): T;
|
|
241
212
|
|
|
213
|
+
declare type Async<T = any> = (...args: any[]) => Promise<T>;
|
|
214
|
+
/**
|
|
215
|
+
* Sets an exotic method with managed ready-state. Property accepts an async function.
|
|
216
|
+
*
|
|
217
|
+
* When an act-method is invoked, its `active` property to true for duration of call.
|
|
218
|
+
* This is emitted as an update to property, both when called and after returns (or throws).
|
|
219
|
+
*
|
|
220
|
+
* **Note:** Subsequent calls will immediately throw if one is still pending.
|
|
221
|
+
*
|
|
222
|
+
* @param action - Action to fire when resulting property is invoked.
|
|
223
|
+
*/
|
|
224
|
+
declare function act(action: Async): typeof action & {
|
|
225
|
+
active: boolean;
|
|
226
|
+
};
|
|
227
|
+
declare function act<S>(action: Async<S>): typeof action & {
|
|
228
|
+
active: boolean;
|
|
229
|
+
};
|
|
230
|
+
|
|
242
231
|
declare namespace get {
|
|
243
232
|
type Function<T, O = any> = (this: O, on: O) => T;
|
|
244
233
|
type Factory<T, O = any> = (key: string) => Function<T, O>;
|
|
245
234
|
type Getter = (controller: Controller, key: string) => any;
|
|
235
|
+
type Factory2<T, S = unknown> = (this: S, key: string, thisArg: S) => T;
|
|
246
236
|
}
|
|
247
237
|
/**
|
|
248
238
|
* Implement a computed value; output will be generated by provided function.
|
|
@@ -261,6 +251,46 @@ declare function get<R, T>(source: T, compute: (this: T, on: T) => R, suspend?:
|
|
|
261
251
|
*/
|
|
262
252
|
declare function get<R, T>(compute: (property: string) => (this: T, state: T) => R, suspend: true): Exclude<R, undefined>;
|
|
263
253
|
declare function get<R, T>(compute: (property: string) => (this: T, state: T) => R, suspend?: boolean): R;
|
|
254
|
+
/**
|
|
255
|
+
* Set property with an async function.
|
|
256
|
+
*
|
|
257
|
+
* Property cannot be accessed until factory resolves, yeilding a result.
|
|
258
|
+
* If accessed while processing, React Suspense will be thrown.
|
|
259
|
+
*
|
|
260
|
+
* - `required: true` (default) -
|
|
261
|
+
* Run factory immediately upon creation of model instance.
|
|
262
|
+
* - `required: false` -
|
|
263
|
+
* Run factory only if/when accessed.
|
|
264
|
+
* Value will always throw suspense at least once - use with caution.
|
|
265
|
+
*
|
|
266
|
+
* @param factory - Callback run to derrive property value.
|
|
267
|
+
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
268
|
+
*/
|
|
269
|
+
declare function get<T>(factory: get.Factory2<Promise<T>>, required: false): T | undefined;
|
|
270
|
+
declare function get<T, S>(factory: get.Factory2<Promise<T>, S>, required: false): T | undefined;
|
|
271
|
+
declare function get<T>(factory: get.Factory2<Promise<T>>, required?: boolean): T;
|
|
272
|
+
declare function get<T, S>(factory: get.Factory2<Promise<T>, S>, required?: boolean): T;
|
|
273
|
+
/**
|
|
274
|
+
* Set property with a factory function.
|
|
275
|
+
*
|
|
276
|
+
* - `required: true` (default) -
|
|
277
|
+
* Run factory immediately upon creation of model instance.
|
|
278
|
+
* - `required: false` -
|
|
279
|
+
* Run factory only if/when accessed.
|
|
280
|
+
* Value will always throw suspense at least once - use with caution.
|
|
281
|
+
*
|
|
282
|
+
* @param factory - Callback run to derrive property value.
|
|
283
|
+
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
284
|
+
*/
|
|
285
|
+
declare function get<T>(factory: get.Factory2<T>, required: false): T | undefined;
|
|
286
|
+
declare function get<T, S>(factory: get.Factory2<T, S>, required: false): T | undefined;
|
|
287
|
+
declare function get<T>(factory: get.Factory2<T>, required?: boolean): T;
|
|
288
|
+
declare function get<T, S>(factory: get.Factory2<T, S>, required?: boolean): T;
|
|
289
|
+
/**
|
|
290
|
+
* Assign a property with result of a promise.
|
|
291
|
+
*/
|
|
292
|
+
declare function get<T>(factory: Promise<T>, required: false): T | undefined;
|
|
293
|
+
declare function get<T>(factory: Promise<T>, required?: boolean): T;
|
|
264
294
|
|
|
265
295
|
declare namespace ref {
|
|
266
296
|
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<void> | void | boolean;
|
|
@@ -284,62 +314,6 @@ declare namespace ref {
|
|
|
284
314
|
declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>;
|
|
285
315
|
declare function ref<T, S>(callback?: ref.Callback<T, S>): ref.Object<T>;
|
|
286
316
|
|
|
287
|
-
declare namespace set$1 {
|
|
288
|
-
type Factory<T, S = unknown> = (this: S, key: string, subject: S) => T;
|
|
289
|
-
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Set property with an async function.
|
|
293
|
-
*
|
|
294
|
-
* Property cannot be accessed until factory resolves, yeilding a result.
|
|
295
|
-
* If accessed while processing, React Suspense will be thrown.
|
|
296
|
-
*
|
|
297
|
-
* - `required: true` (default) -
|
|
298
|
-
* Run factory immediately upon creation of model instance.
|
|
299
|
-
* - `required: false` -
|
|
300
|
-
* Run factory only if/when accessed.
|
|
301
|
-
* Value will always throw suspense at least once - use with caution.
|
|
302
|
-
*
|
|
303
|
-
* @param factory - Callback run to derrive property value.
|
|
304
|
-
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
305
|
-
*/
|
|
306
|
-
declare function put<T>(factory: set$1.Factory<Promise<T>>, required: false): T | undefined;
|
|
307
|
-
declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required: false): T | undefined;
|
|
308
|
-
declare function put<T>(factory: set$1.Factory<Promise<T>>, required?: boolean): T;
|
|
309
|
-
declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required?: boolean): T;
|
|
310
|
-
declare function put<T>(value: set$1.Factory<Promise<T>>, onUpdate: set$1.Callback<T>): T;
|
|
311
|
-
declare function put<T, S>(value: set$1.Factory<Promise<T>, S>, onUpdate: set$1.Callback<T, S>): T;
|
|
312
|
-
/**
|
|
313
|
-
* Set property with a factory function.
|
|
314
|
-
*
|
|
315
|
-
* - `required: true` (default) -
|
|
316
|
-
* Run factory immediately upon creation of model instance.
|
|
317
|
-
* - `required: false` -
|
|
318
|
-
* Run factory only if/when accessed.
|
|
319
|
-
* Value will always throw suspense at least once - use with caution.
|
|
320
|
-
*
|
|
321
|
-
* @param factory - Callback run to derrive property value.
|
|
322
|
-
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
323
|
-
*/
|
|
324
|
-
declare function put<T>(factory: set$1.Factory<T>, required: false): T | undefined;
|
|
325
|
-
declare function put<T, S>(factory: set$1.Factory<T, S>, required: false): T | undefined;
|
|
326
|
-
declare function put<T>(factory: set$1.Factory<T>, required?: boolean): T;
|
|
327
|
-
declare function put<T, S>(factory: set$1.Factory<T, S>, required?: boolean): T;
|
|
328
|
-
declare function put<T>(value: set$1.Factory<T>, onUpdate: set$1.Callback<T>): T;
|
|
329
|
-
declare function put<T, S>(value: set$1.Factory<T, S>, onUpdate: set$1.Callback<T, S>): T;
|
|
330
|
-
/**
|
|
331
|
-
* Assign a property with result of a promise.
|
|
332
|
-
*/
|
|
333
|
-
declare function put<T>(factory: Promise<T>, required: false): T | undefined;
|
|
334
|
-
declare function put<T>(factory: Promise<T>, required?: boolean): T;
|
|
335
|
-
declare function put<T>(value: Promise<T>, onUpdate: set$1.Callback<T>): T;
|
|
336
|
-
/**
|
|
337
|
-
* Assign a property.
|
|
338
|
-
*/
|
|
339
|
-
declare function put<T>(factory: T, required: false): T | undefined;
|
|
340
|
-
declare function put<T>(factory: T, required?: boolean): T;
|
|
341
|
-
declare function put<T>(value: T, onUpdate: set$1.Callback<T>): T;
|
|
342
|
-
|
|
343
317
|
declare namespace set {
|
|
344
318
|
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
345
319
|
}
|
|
@@ -357,14 +331,26 @@ declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T;
|
|
|
357
331
|
declare function set<T>(value: T, onUpdate: set.Callback<T>): T;
|
|
358
332
|
declare function set<T, S>(value: T, onUpdate: set.Callback<T, S>): T;
|
|
359
333
|
|
|
360
|
-
declare
|
|
361
|
-
declare
|
|
362
|
-
|
|
363
|
-
|
|
334
|
+
declare type MapFunction<T, R> = T extends Map<infer K, infer V> ? (value: V, key: K, map: T) => R | void : T extends Set<infer K> ? (value: K, key: K, set: T) => R | void : never;
|
|
335
|
+
declare type Managed<T> = Exclude<T, "forEach"> & {
|
|
336
|
+
from?: T;
|
|
337
|
+
forEach<R>(mapFunction: MapFunction<T, R>, thisArg?: any): Exclude<R, undefined>[] | void;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
declare function use<K = any>(initial: SetConstructor): Managed<Set<K>>;
|
|
341
|
+
declare function use<K = any, V = any>(initial: MapConstructor): Managed<Map<K, V>>;
|
|
342
|
+
declare function use(initial: Set<unknown>): Managed<Set<any>>;
|
|
343
|
+
declare function use(initial: Map<unknown, unknown>): Managed<Map<any, any>>;
|
|
344
|
+
declare function use(from: () => Set<unknown>): Managed<Set<any>>;
|
|
345
|
+
declare function use(from: () => Map<unknown, unknown>): Managed<Map<any, any>>;
|
|
346
|
+
declare function use<T extends Set<any> | Map<any, any>>(initial: T): Managed<T>;
|
|
347
|
+
declare function use<T extends Set<any> | Map<any, any>>(from: () => T): Managed<T>;
|
|
364
348
|
/**
|
|
365
349
|
* Create a placeholder for specified Model type.
|
|
366
350
|
*/
|
|
367
351
|
declare function use<T extends Model>(): T | undefined;
|
|
352
|
+
declare function use<T extends Model>(from: () => T, required: false): T | undefined;
|
|
353
|
+
declare function use<T extends Model>(from: () => T, required: boolean): T;
|
|
368
354
|
/**
|
|
369
355
|
* Create a new child instance of model.
|
|
370
356
|
*/
|
|
@@ -372,6 +358,9 @@ declare function use<T extends Class>(Type: T, callback?: (i: InstanceOf<T>) =>
|
|
|
372
358
|
/**
|
|
373
359
|
* Create a managed child from factory function.
|
|
374
360
|
*/
|
|
361
|
+
declare function use<T extends {}>(from: () => Promise<T>, required: false): T | undefined;
|
|
362
|
+
declare function use<T extends {}>(from: () => Promise<T>, required: boolean): T;
|
|
363
|
+
declare function use<T extends {}>(from: () => Promise<T>, callback?: (i: T) => void): T;
|
|
375
364
|
declare function use<T extends {}>(from: () => T, callback?: (i: T) => void): T;
|
|
376
365
|
/**
|
|
377
366
|
* Create child-instance relationship with provided model.
|
|
@@ -391,8 +380,8 @@ declare function use<T extends {}>(peer: T, callback?: (i: T) => void): T;
|
|
|
391
380
|
* @param Expects - Type of controller compatible with this class.
|
|
392
381
|
* @param required - Throw if controller is created independantly.
|
|
393
382
|
*/
|
|
394
|
-
declare function
|
|
395
|
-
declare function
|
|
383
|
+
declare function has<T extends typeof Model>(Expects: T, required: false): InstanceOf<T> | undefined;
|
|
384
|
+
declare function has<T extends typeof Model>(Expects: T, required?: true): InstanceOf<T>;
|
|
396
385
|
|
|
397
386
|
declare class MVC extends Model {
|
|
398
387
|
static [CONTROL]: Controller;
|
|
@@ -627,4 +616,4 @@ declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T
|
|
|
627
616
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
628
617
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
629
618
|
|
|
630
|
-
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply,
|
|
619
|
+
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 };
|