@expressive/mvc 0.8.2 → 0.9.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 +44 -36
- package/lib/index.esm.js +200 -177
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +201 -178
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -8,18 +8,21 @@ declare type Listener = {
|
|
|
8
8
|
commit(): void;
|
|
9
9
|
release(): void;
|
|
10
10
|
};
|
|
11
|
+
declare namespace Subscriber {
|
|
12
|
+
type OnEvent<T = any> = (key: Model.Event<T> | null, source: Control) => Callback | void;
|
|
13
|
+
}
|
|
11
14
|
declare class Subscriber<T extends {} = any> {
|
|
12
15
|
parent: Control<T>;
|
|
13
|
-
onUpdate:
|
|
14
|
-
static get<T extends {}>(from: T):
|
|
16
|
+
onUpdate: Subscriber.OnEvent;
|
|
17
|
+
static get<T extends {}>(from: T): Subscriber<T> | undefined;
|
|
15
18
|
proxy: T;
|
|
16
19
|
release: Callback;
|
|
17
20
|
latest?: Model.Event<T>[];
|
|
18
21
|
active: boolean;
|
|
19
22
|
dependant: Set<Listener>;
|
|
20
23
|
watch: Map<any, boolean | (() => true | void)>;
|
|
21
|
-
constructor(parent: Control<T>, onUpdate:
|
|
22
|
-
get using(): Model.Values<T
|
|
24
|
+
constructor(parent: Control<T>, onUpdate: Subscriber.OnEvent);
|
|
25
|
+
get using(): Model.Values<T>[];
|
|
23
26
|
assign(apply: Model.Compat<T>, keys?: any): void;
|
|
24
27
|
add(key: any, value?: boolean | Callback): void;
|
|
25
28
|
commit: () => () => void;
|
|
@@ -84,33 +87,28 @@ declare class Model {
|
|
|
84
87
|
*/
|
|
85
88
|
is: this;
|
|
86
89
|
constructor();
|
|
87
|
-
on<P
|
|
88
|
-
on<P extends Model.Event<this>>(key: P): Promise<Model.ValueOf<this, P>>;
|
|
89
|
-
on<P extends Model.Event<this>>(key: P, timeout: number): Promise<Model.ValueOf<this, P>>;
|
|
90
|
+
on<P extends Model.Event<this>>(key: P, timeout?: number): Promise<Model.ValueOf<this, P>>;
|
|
90
91
|
on<P extends Model.Event<this>>(key: P, listener: Model.OnUpdate<this, P>, once?: boolean): Callback;
|
|
91
|
-
on<P extends Model.Event<this>>(
|
|
92
|
-
on<P extends Model.Event<this>>(
|
|
93
|
-
on
|
|
94
|
-
on
|
|
95
|
-
on<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
on<P extends Model.Event<this>>(keys: P[], timeout?: number): Promise<P[]>;
|
|
93
|
+
on<P extends Model.Event<this>>(keys: P[], listener: (keys: P[]) => void, once?: boolean): Callback;
|
|
94
|
+
on(effect: Model.Effect<this>): Callback;
|
|
95
|
+
on(effect: Model.Effect<this>, watch?: []): Callback;
|
|
96
|
+
on(effect: Model.Effect<this>, watch?: Model.Event<this>[]): Callback;
|
|
97
|
+
on(key?: undefined, timeout?: number): Promise<Model.Event<this>[]>;
|
|
98
|
+
on(current?: boolean): Promise<Model.Event<this>[] | null>;
|
|
99
|
+
on(current: true): Promise<Model.Event<this>[]>;
|
|
100
|
+
on(current: null): Promise<null>;
|
|
99
101
|
export(): Model.Values<this>;
|
|
100
|
-
export<P extends Model.Field<this>>(select: P
|
|
101
|
-
update(): PromiseLike<readonly Model.Event<this>[] | false>;
|
|
102
|
-
update(strict: true): Promise<readonly Model.Event<this>[]>;
|
|
103
|
-
update(strict: false): Promise<false>;
|
|
104
|
-
update(strict: boolean): Promise<readonly Model.Event<this>[] | false>;
|
|
102
|
+
export<P extends Model.Field<this>>(select: Iterable<P>): Model.Values<this, P>;
|
|
105
103
|
update(key: Model.Event<this>): PromiseLike<readonly Model.Event<this>[]>;
|
|
106
104
|
update(key: Model.Event<this>, callMethod: boolean): PromiseLike<readonly Model.Event<this>[]>;
|
|
107
105
|
update<T>(key: Model.Event<this>, argument: T): PromiseLike<readonly Model.Event<this>[]>;
|
|
108
106
|
update<T extends Model.Compat<this>>(source: T, select: (keyof T)[]): PromiseLike<(keyof T)[]>;
|
|
109
107
|
update<T extends Model.Compat<this>>(source: T, force?: boolean): PromiseLike<(keyof T)[]>;
|
|
110
108
|
/**
|
|
111
|
-
*
|
|
109
|
+
* Clean up side effects and mark this instance for garbage-collection.
|
|
112
110
|
*/
|
|
113
|
-
|
|
111
|
+
destroy(): void;
|
|
114
112
|
/**
|
|
115
113
|
* Creates a new instance of this controller.
|
|
116
114
|
*
|
|
@@ -128,22 +126,32 @@ declare class Model {
|
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
declare namespace Control {
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Callback for Controller.for() static method.
|
|
131
|
+
* Returned callback is forwarded.
|
|
132
|
+
*/
|
|
133
133
|
type OnReady<T extends {}> = (control: Control<T>) => Callback | void;
|
|
134
|
+
/**
|
|
135
|
+
* Called immediately when any key is changed or emitted.
|
|
136
|
+
* Returned callback is notified when update is complete.
|
|
137
|
+
*/
|
|
138
|
+
type OnSync<T = any> = (key: Model.Event<T> | null, source: Control) => OnAsync<T> | void;
|
|
139
|
+
/** Called at the end of an event frame with all keys affected. */
|
|
140
|
+
type OnAsync<T = any> = (keys: Model.Event<T>[]) => void;
|
|
141
|
+
type OnValue<T = any> = (this: T, value: any) => boolean | void;
|
|
134
142
|
}
|
|
135
143
|
declare class Control<T extends {} = any> {
|
|
136
144
|
subject: T;
|
|
137
145
|
state: Map<any, any>;
|
|
138
146
|
frame: Set<string>;
|
|
139
|
-
waiting: Set<
|
|
140
|
-
followers: Set<Model.Control.
|
|
147
|
+
waiting: Set<Model.Control.OnAsync<T>>;
|
|
148
|
+
followers: Set<Model.Control.OnSync<any>>;
|
|
141
149
|
latest?: Model.Event<T>[];
|
|
142
150
|
constructor(subject: T);
|
|
143
|
-
subscribe(callback:
|
|
151
|
+
subscribe(callback: Subscriber.OnEvent<T>): Model.Subscriber<T>;
|
|
144
152
|
watch(key: keyof T & string): void;
|
|
145
|
-
addListener(listener: Control.
|
|
146
|
-
ref
|
|
153
|
+
addListener(listener: Control.OnSync<T>): () => void;
|
|
154
|
+
ref<K extends Model.Field<T>>(key: K, handler?: (this: T, value: T[K]) => boolean | void): (value: any) => void;
|
|
147
155
|
update(key: Model.Field<T>): void;
|
|
148
156
|
clear(): void;
|
|
149
157
|
static get<T extends {}>(from: T): Control<T> | undefined;
|
|
@@ -191,17 +199,17 @@ declare type Async<T = any> = (...args: any[]) => Promise<T>;
|
|
|
191
199
|
/**
|
|
192
200
|
* Sets an exotic method with managed ready-state. Property accepts an async function.
|
|
193
201
|
*
|
|
194
|
-
* When
|
|
202
|
+
* When a run-method is invoked, its `active` property to true for duration of call.
|
|
195
203
|
* This is emitted as an update to property, both when called and after returns (or throws).
|
|
196
204
|
*
|
|
197
205
|
* **Note:** Subsequent calls will immediately throw if one is still pending.
|
|
198
206
|
*
|
|
199
207
|
* @param action - Action to fire when resulting property is invoked.
|
|
200
208
|
*/
|
|
201
|
-
declare function
|
|
209
|
+
declare function run(action: Async): typeof action & {
|
|
202
210
|
active: boolean;
|
|
203
211
|
};
|
|
204
|
-
declare function
|
|
212
|
+
declare function run<S>(action: Async<S>): typeof action & {
|
|
205
213
|
active: boolean;
|
|
206
214
|
};
|
|
207
215
|
|
|
@@ -522,7 +530,7 @@ declare function Provider<T extends Provider.Item>(props: Provider.Props<T>): Re
|
|
|
522
530
|
|
|
523
531
|
declare class Global extends MVC {
|
|
524
532
|
constructor();
|
|
525
|
-
|
|
533
|
+
destroy(force?: boolean): boolean;
|
|
526
534
|
static keepAlive: boolean;
|
|
527
535
|
static new<T extends Class>(this: T, ...args: ConstructorParameters<T>): InstanceOf<T>;
|
|
528
536
|
/**
|
|
@@ -576,8 +584,8 @@ declare function tap<T extends Model>(Type: Model.Type<T>, callback?: (instance?
|
|
|
576
584
|
declare function tap<T extends Model>(Type: Model.Type<T>, required: true): T;
|
|
577
585
|
declare function tap<T extends Model>(Type: Model.Type<T>, required?: boolean): T | undefined;
|
|
578
586
|
|
|
579
|
-
declare function
|
|
580
|
-
declare function
|
|
587
|
+
declare function useValue<T extends {}, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
588
|
+
declare function useValue<T extends {}, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
581
589
|
|
|
582
590
|
declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), callback?: (instance: T) => void): T;
|
|
583
591
|
declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), watch: Model.Field<T>[], callback?: (instance: T) => void): T;
|
|
@@ -592,4 +600,4 @@ declare function useTap<T extends Model, K extends Model.Field<T>>(source: useTa
|
|
|
592
600
|
declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
593
601
|
declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
594
602
|
|
|
595
|
-
export { Consumer, Debug, Global, MVC, MVC as Model, Provider,
|
|
603
|
+
export { Consumer, Debug, Global, MVC, MVC as Model, Provider, add, MVC as default, get, has, ref, run, set, tap, use, useContext, useModel, useTap, useValue };
|