@expressive/mvc 0.2.6 → 0.4.1
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 +54 -74
- package/lib/index.esm.js +730 -556
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +730 -555
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -31,12 +31,12 @@ declare type Listener = {
|
|
|
31
31
|
declare class Subscriber<T extends Stateful = any> {
|
|
32
32
|
onUpdate: Controller.OnEvent;
|
|
33
33
|
proxy: T;
|
|
34
|
+
commit: () => Callback;
|
|
34
35
|
release: Callback;
|
|
35
|
-
commit: () => () => void;
|
|
36
36
|
active: boolean;
|
|
37
37
|
dependant: Set<Listener>;
|
|
38
|
-
|
|
39
|
-
constructor(
|
|
38
|
+
add: (key: any, value?: Callback) => void;
|
|
39
|
+
constructor(parent: Controller<T>, onUpdate: Controller.OnEvent);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
declare const CONTROL: unique symbol;
|
|
@@ -49,7 +49,7 @@ interface Stateful {
|
|
|
49
49
|
/** Current subscriber (if present) while used in a live context (e.g. hook or effect). */
|
|
50
50
|
[LOCAL]?: Subscriber;
|
|
51
51
|
/** Current state of this instance. */
|
|
52
|
-
[STATE]?: this
|
|
52
|
+
[STATE]?: Model.Values<this>;
|
|
53
53
|
/**
|
|
54
54
|
* Last update causing a refresh to subscribers.
|
|
55
55
|
*
|
|
@@ -133,7 +133,7 @@ declare class Model {
|
|
|
133
133
|
static [CONTROL]: Controller;
|
|
134
134
|
static [WHY]: readonly string[];
|
|
135
135
|
constructor();
|
|
136
|
-
get [STATE](): this
|
|
136
|
+
get [STATE](): Model.Values<this, Exclude<keyof this & string, keyof Model>>;
|
|
137
137
|
get [WHY](): readonly string[] | undefined;
|
|
138
138
|
on<P = Model.Event<this>>(event: (key: P) => Callback | void): Callback;
|
|
139
139
|
on<P = Model.Event<this>>(keys: [], listener: Model.OnUpdate<this, P>, squash?: boolean, once?: boolean): Callback;
|
|
@@ -149,7 +149,7 @@ declare class Model {
|
|
|
149
149
|
once<P extends Model.Event<this>>(key: P | P[], listener: Model.OnUpdate<this, P>, squash?: false): Callback;
|
|
150
150
|
once<P extends Model.Event<this>>(key: P | P[], listener: (keys: P[]) => void, squash: true): Callback;
|
|
151
151
|
once<P extends Model.Event<this>>(key: P | P[], listener: unknown, squash: boolean): Callback;
|
|
152
|
-
once<P extends Model.Event<this>>(key: P | P[]): Promise<
|
|
152
|
+
once<P extends Model.Event<this>>(key: P | P[], timeout?: number): Promise<void>;
|
|
153
153
|
effect(callback: Model.Effect<this>): Callback;
|
|
154
154
|
effect(callback: Model.Effect<this>, select: []): Callback;
|
|
155
155
|
effect(callback: Model.Effect<this>, select: Model.Event<this>[]): Callback;
|
|
@@ -185,30 +185,22 @@ declare class Model {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
declare namespace Controller {
|
|
188
|
-
type OnValue<T = any
|
|
189
|
-
type OnEvent<T = any> = (key: Model.Event<T
|
|
188
|
+
type OnValue<T = any> = (this: T, value: any) => boolean | void;
|
|
189
|
+
type OnEvent<T = any> = (key: Model.Event<T> | null, source: Controller) => Callback | void;
|
|
190
190
|
}
|
|
191
191
|
declare class Controller<T extends Stateful = any> {
|
|
192
192
|
subject: T;
|
|
193
|
-
|
|
194
|
-
state: Model.Values<T, Exclude<keyof T & string, keyof Model>>;
|
|
193
|
+
state: Map<any, any>;
|
|
195
194
|
frame: Set<string>;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
protected followers: Set<Model.Controller.OnEvent<any>>;
|
|
195
|
+
waiting: Set<Callback>;
|
|
196
|
+
followers: Set<Model.Controller.OnEvent<any>>;
|
|
199
197
|
constructor(subject: T);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
manage(key: Model.Field<T>, value: any): void;
|
|
203
|
-
ref(key: Model.Field<T>, handler?: Controller.OnValue<T>): (value: any) => void;
|
|
198
|
+
subscribe(callback: Controller.OnEvent<T>): Model.Subscriber<T>;
|
|
199
|
+
add(key: keyof T & string): void;
|
|
204
200
|
addListener(listener: Controller.OnEvent<T>): () => void;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
requestUpdate(strict: true): Promise<readonly Model.Event<T>[]>;
|
|
209
|
-
requestUpdate(strict: false): Promise<false>;
|
|
210
|
-
requestUpdate(strict: boolean): Promise<readonly Model.Event<T>[] | false>;
|
|
211
|
-
requestUpdate(callback: Callback): void;
|
|
201
|
+
ref(key: Model.Field<T>, handler?: Controller.OnValue<T>): (value: any) => void;
|
|
202
|
+
update(key: Model.Field<T>): void;
|
|
203
|
+
clear(): void;
|
|
212
204
|
}
|
|
213
205
|
|
|
214
206
|
/**
|
|
@@ -217,8 +209,8 @@ declare class Controller<T extends Stateful = any> {
|
|
|
217
209
|
*/
|
|
218
210
|
declare type Instruction<T> = (this: Controller, key: string, thisArg: Controller) => Instruction.Getter<T> | Instruction.ExplicitDescriptor | Instruction.Descriptor<T> | Instruction.RecursiveDescriptor<T> | boolean | void;
|
|
219
211
|
declare namespace Instruction {
|
|
220
|
-
type Getter<T> = (
|
|
221
|
-
type Setter<T> = (value: T
|
|
212
|
+
type Getter<T> = (within?: Subscriber) => T;
|
|
213
|
+
type Setter<T> = (value: T) => boolean | void;
|
|
222
214
|
type Runner<T> = (this: Controller, key: string, on: Controller) => Instruction.Descriptor<T> | boolean | undefined;
|
|
223
215
|
interface Descriptor<T> {
|
|
224
216
|
configurable?: boolean;
|
|
@@ -280,15 +272,6 @@ declare namespace ref {
|
|
|
280
272
|
[P in Model.Field<T>]: Model.Ref<T[P]>;
|
|
281
273
|
};
|
|
282
274
|
}
|
|
283
|
-
/**
|
|
284
|
-
* Creates an object with references to all managed values.
|
|
285
|
-
* Each property will set value in state when invoked.
|
|
286
|
-
*
|
|
287
|
-
* *Properties are simultaneously a ref-function and ref-object, use as needed.*
|
|
288
|
-
*
|
|
289
|
-
* @param target - Source model from which to reference values.
|
|
290
|
-
*/
|
|
291
|
-
declare function ref<T extends Model>(target: T): ref.Proxy<T>;
|
|
292
275
|
/**
|
|
293
276
|
* Creates a ref-compatible property.
|
|
294
277
|
* Will persist value, and updates to this are made part of controller event-stream.
|
|
@@ -300,30 +283,10 @@ declare function ref<T extends Model>(target: T): ref.Proxy<T>;
|
|
|
300
283
|
declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>;
|
|
301
284
|
declare function ref<T, S>(callback?: ref.Callback<T, S>): ref.Object<T>;
|
|
302
285
|
|
|
303
|
-
declare namespace set {
|
|
286
|
+
declare namespace set$1 {
|
|
304
287
|
type Factory<T, S = unknown> = (this: S, key: string, subject: S) => T;
|
|
305
288
|
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
306
289
|
}
|
|
307
|
-
/**
|
|
308
|
-
* Set property with a placeholder.
|
|
309
|
-
*
|
|
310
|
-
* Property cannot be accessed until it is defined. If accessed while undefined, a hybrid
|
|
311
|
-
* `Promise`/`Error` (ala: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.
|
|
312
|
-
*/
|
|
313
|
-
declare function set<T = any>(): T;
|
|
314
|
-
/**
|
|
315
|
-
* Set property with starting value `undefined`.
|
|
316
|
-
*
|
|
317
|
-
* If required and accessed while still empty, React Suspense will be thrown.
|
|
318
|
-
* Property will reject any assignment of undefined.
|
|
319
|
-
*
|
|
320
|
-
* @param value - Starting value of host property (undefined).
|
|
321
|
-
* @param required - Property will suspend callee if undefined at time of access.
|
|
322
|
-
*/
|
|
323
|
-
declare function set<T>(value: undefined, required: false): T | undefined;
|
|
324
|
-
declare function set<T>(value: undefined, required?: boolean): T;
|
|
325
|
-
declare function set<T>(value: undefined, onUpdate: set.Callback<T>): T | undefined;
|
|
326
|
-
declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T | undefined;
|
|
327
290
|
/**
|
|
328
291
|
* Set property with an async function.
|
|
329
292
|
*
|
|
@@ -339,12 +302,12 @@ declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T |
|
|
|
339
302
|
* @param factory - Callback run to derrive property value.
|
|
340
303
|
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
341
304
|
*/
|
|
342
|
-
declare function
|
|
343
|
-
declare function
|
|
344
|
-
declare function
|
|
345
|
-
declare function
|
|
346
|
-
declare function
|
|
347
|
-
declare function
|
|
305
|
+
declare function put<T>(factory: set$1.Factory<Promise<T>>, required: false): T | undefined;
|
|
306
|
+
declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required: false): T | undefined;
|
|
307
|
+
declare function put<T>(factory: set$1.Factory<Promise<T>>, required?: boolean): T;
|
|
308
|
+
declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required?: boolean): T;
|
|
309
|
+
declare function put<T>(value: set$1.Factory<Promise<T>>, onUpdate: set$1.Callback<T>): T;
|
|
310
|
+
declare function put<T, S>(value: set$1.Factory<Promise<T>, S>, onUpdate: set$1.Callback<T, S>): T;
|
|
348
311
|
/**
|
|
349
312
|
* Set property with a factory function.
|
|
350
313
|
*
|
|
@@ -357,24 +320,41 @@ declare function set<T, S>(value: set.Factory<Promise<T>, S>, onUpdate: set.Call
|
|
|
357
320
|
* @param factory - Callback run to derrive property value.
|
|
358
321
|
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
359
322
|
*/
|
|
360
|
-
declare function
|
|
361
|
-
declare function
|
|
362
|
-
declare function
|
|
363
|
-
declare function
|
|
364
|
-
declare function
|
|
365
|
-
declare function
|
|
323
|
+
declare function put<T>(factory: set$1.Factory<T>, required: false): T | undefined;
|
|
324
|
+
declare function put<T, S>(factory: set$1.Factory<T, S>, required: false): T | undefined;
|
|
325
|
+
declare function put<T>(factory: set$1.Factory<T>, required?: boolean): T;
|
|
326
|
+
declare function put<T, S>(factory: set$1.Factory<T, S>, required?: boolean): T;
|
|
327
|
+
declare function put<T>(value: set$1.Factory<T>, onUpdate: set$1.Callback<T>): T;
|
|
328
|
+
declare function put<T, S>(value: set$1.Factory<T, S>, onUpdate: set$1.Callback<T, S>): T;
|
|
366
329
|
/**
|
|
367
330
|
* Assign a property with result of a promise.
|
|
368
331
|
*/
|
|
369
|
-
declare function
|
|
370
|
-
declare function
|
|
371
|
-
declare function
|
|
332
|
+
declare function put<T>(factory: Promise<T>, required: false): T | undefined;
|
|
333
|
+
declare function put<T>(factory: Promise<T>, required?: boolean): T;
|
|
334
|
+
declare function put<T>(value: Promise<T>, onUpdate: set$1.Callback<T>): T;
|
|
372
335
|
/**
|
|
373
336
|
* Assign a property.
|
|
374
337
|
*/
|
|
375
|
-
declare function
|
|
376
|
-
declare function
|
|
338
|
+
declare function put<T>(factory: T, required: false): T | undefined;
|
|
339
|
+
declare function put<T>(factory: T, required?: boolean): T;
|
|
340
|
+
declare function put<T>(value: T, onUpdate: set$1.Callback<T>): T;
|
|
341
|
+
|
|
342
|
+
declare namespace set {
|
|
343
|
+
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Set property with a placeholder.
|
|
347
|
+
*
|
|
348
|
+
* Property cannot be accessed until it is defined. If accessed while undefined, a hybrid
|
|
349
|
+
* `Promise`/`Error` (ala: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.
|
|
350
|
+
*/
|
|
351
|
+
declare function set<T = any>(): T;
|
|
352
|
+
declare function set<T>(onUpdate: set.Callback<T>): T;
|
|
353
|
+
declare function set<T, S>(onUpdate: set.Callback<T, S>): T;
|
|
354
|
+
declare function set<T>(value: undefined, onUpdate: set.Callback<T>): T;
|
|
355
|
+
declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T;
|
|
377
356
|
declare function set<T>(value: T, onUpdate: set.Callback<T>): T;
|
|
357
|
+
declare function set<T, S>(value: T, onUpdate: set.Callback<T, S>): T;
|
|
378
358
|
|
|
379
359
|
/**
|
|
380
360
|
* Create a placeholder for specified Model type.
|
|
@@ -642,4 +622,4 @@ declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T
|
|
|
642
622
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
643
623
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
644
624
|
|
|
645
|
-
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, array, MVC as default, from, parent, ref, set, tap, use, useFrom, useLocal, useModel, useTap };
|
|
625
|
+
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, array, MVC as default, from, parent, put, ref, set, tap, use, useFrom, useLocal, useModel, useTap };
|