@expressive/mvc 0.4.7 → 0.5.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 +36 -40
- package/lib/index.esm.js +385 -448
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +385 -450
- 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,6 +210,24 @@ 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>;
|
|
@@ -357,12 +346,19 @@ declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T;
|
|
|
357
346
|
declare function set<T>(value: T, onUpdate: set.Callback<T>): T;
|
|
358
347
|
declare function set<T, S>(value: T, onUpdate: set.Callback<T, S>): T;
|
|
359
348
|
|
|
360
|
-
declare
|
|
361
|
-
declare
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
declare function use(
|
|
349
|
+
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;
|
|
350
|
+
declare type Managed<T> = T & {
|
|
351
|
+
from?: T;
|
|
352
|
+
forEach<R>(mapFunction: MapFunction<T, R>, thisArg?: any): Exclude<R, undefined>[] | void;
|
|
353
|
+
};
|
|
354
|
+
declare function use<K = any>(initial: SetConstructor): Managed<Set<K>>;
|
|
355
|
+
declare function use<K = any, V = any>(initial: MapConstructor): Managed<Map<K, V>>;
|
|
356
|
+
declare function use(initial: Set<unknown>): Managed<Set<any>>;
|
|
357
|
+
declare function use(initial: Map<unknown, unknown>): Managed<Map<any, any>>;
|
|
358
|
+
declare function use(from: () => Set<unknown>): Managed<Set<any>>;
|
|
359
|
+
declare function use(from: () => Map<unknown, unknown>): Managed<Map<any, any>>;
|
|
360
|
+
declare function use<T extends Set<any> | Map<any, any>>(initial: T): Managed<T>;
|
|
361
|
+
declare function use<T extends Set<any> | Map<any, any>>(from: () => T): Managed<T>;
|
|
366
362
|
/**
|
|
367
363
|
* Create a placeholder for specified Model type.
|
|
368
364
|
*/
|
|
@@ -393,8 +389,8 @@ declare function use<T extends {}>(peer: T, callback?: (i: T) => void): T;
|
|
|
393
389
|
* @param Expects - Type of controller compatible with this class.
|
|
394
390
|
* @param required - Throw if controller is created independantly.
|
|
395
391
|
*/
|
|
396
|
-
declare function
|
|
397
|
-
declare function
|
|
392
|
+
declare function has<T extends typeof Model>(Expects: T, required: false): InstanceOf<T> | undefined;
|
|
393
|
+
declare function has<T extends typeof Model>(Expects: T, required?: true): InstanceOf<T>;
|
|
398
394
|
|
|
399
395
|
declare class MVC extends Model {
|
|
400
396
|
static [CONTROL]: Controller;
|
|
@@ -629,4 +625,4 @@ declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T
|
|
|
629
625
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
630
626
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
631
627
|
|
|
632
|
-
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply,
|
|
628
|
+
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, MVC as default, get, has, put, ref, set, tap, use, useFrom, useLocal, useModel, useTap };
|