@expressive/mvc 0.4.5 → 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 +41 -43
- package/lib/index.esm.js +410 -561
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +411 -563
- 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,7 +210,25 @@ declare namespace Instruction {
|
|
|
239
210
|
*/
|
|
240
211
|
declare function apply<T = any>(instruction: Instruction<T>, name?: string): T;
|
|
241
212
|
|
|
242
|
-
declare
|
|
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
|
+
|
|
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;
|
|
@@ -251,16 +240,16 @@ declare namespace from {
|
|
|
251
240
|
* @param compute - Compute function. Bound to a subscriber-proxy of source, returns output value. Will update automatically as input values change.
|
|
252
241
|
* @param suspend - Value will throw suspense when evaulating to undefined.
|
|
253
242
|
*/
|
|
254
|
-
declare function
|
|
255
|
-
declare function
|
|
243
|
+
declare function get<R, T>(source: T, compute: (this: T, on: T) => R, suspend: true): Exclude<R, undefined>;
|
|
244
|
+
declare function get<R, T>(source: T, compute: (this: T, on: T) => R, suspend?: boolean): R;
|
|
256
245
|
/**
|
|
257
246
|
* Implement a computed value; output is returned by function from provided factory.
|
|
258
247
|
*
|
|
259
248
|
* @param compute - Factory function to generate a getter to subscribe dependancies.
|
|
260
249
|
* @param suspend - Value will throw suspense when evaulating to undefined.
|
|
261
250
|
*/
|
|
262
|
-
declare function
|
|
263
|
-
declare function
|
|
251
|
+
declare function get<R, T>(compute: (property: string) => (this: T, state: T) => R, suspend: true): Exclude<R, undefined>;
|
|
252
|
+
declare function get<R, T>(compute: (property: string) => (this: T, state: T) => R, suspend?: boolean): R;
|
|
264
253
|
|
|
265
254
|
declare namespace ref {
|
|
266
255
|
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<void> | void | boolean;
|
|
@@ -357,10 +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
|
-
|
|
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>;
|
|
364
362
|
/**
|
|
365
363
|
* Create a placeholder for specified Model type.
|
|
366
364
|
*/
|
|
@@ -391,8 +389,8 @@ declare function use<T extends {}>(peer: T, callback?: (i: T) => void): T;
|
|
|
391
389
|
* @param Expects - Type of controller compatible with this class.
|
|
392
390
|
* @param required - Throw if controller is created independantly.
|
|
393
391
|
*/
|
|
394
|
-
declare function
|
|
395
|
-
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>;
|
|
396
394
|
|
|
397
395
|
declare class MVC extends Model {
|
|
398
396
|
static [CONTROL]: Controller;
|
|
@@ -627,4 +625,4 @@ declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T
|
|
|
627
625
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
628
626
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
629
627
|
|
|
630
|
-
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 };
|