@expressive/mvc 0.72.0 → 0.73.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/dist/esm/context.d.ts +62 -0
- package/dist/esm/context.js +151 -163
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +9 -23
- package/dist/esm/instruction/get.d.ts +36 -0
- package/dist/esm/instruction/get.js +75 -79
- package/dist/esm/instruction/ref.d.ts +71 -0
- package/dist/esm/instruction/ref.js +65 -66
- package/dist/esm/instruction/set.d.ts +69 -0
- package/dist/esm/instruction/set.js +113 -131
- package/dist/esm/instruction/use.d.ts +23 -0
- package/dist/esm/instruction/use.js +48 -55
- package/dist/esm/observable.d.ts +42 -0
- package/dist/esm/observable.js +121 -0
- package/dist/esm/state.d.ts +234 -0
- package/dist/esm/state.js +267 -298
- package/dist/index.d.ts +322 -332
- package/dist/index.js +820 -931
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/dist/esm/control.js +0 -136
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/observable.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Update callback function.
|
|
3
4
|
*
|
|
@@ -12,15 +13,16 @@ type Notify<T extends Observable = any> = (this: T, key: Event, source: T) => ((
|
|
|
12
13
|
type Effect<T extends Observable> = (proxy: T) => ((update: boolean | null) => void) | Promise<void> | null | void;
|
|
13
14
|
type Event = number | string | null | boolean | symbol;
|
|
14
15
|
type PromiseLite<T = void> = {
|
|
15
|
-
|
|
16
|
+
then: (callback: () => T) => T;
|
|
16
17
|
};
|
|
17
18
|
declare namespace Observable {
|
|
18
|
-
|
|
19
|
+
type Callback = () => void | PromiseLite;
|
|
19
20
|
}
|
|
20
21
|
interface Observable {
|
|
21
|
-
|
|
22
|
+
[Observable](callback: Observable.Callback, required?: boolean): this | void;
|
|
22
23
|
}
|
|
23
24
|
declare const Observable: unique symbol;
|
|
25
|
+
/** Update register. */
|
|
24
26
|
declare function addListener<T extends Observable>(subject: T, callback: Notify<T>, select?: Event | Set<Event>): () => boolean;
|
|
25
27
|
declare function event(subject: Observable, key?: string | number | symbol | null, silent?: boolean): void;
|
|
26
28
|
/**
|
|
@@ -31,264 +33,252 @@ declare function event(subject: Observable, key?: string | number | symbol | nul
|
|
|
31
33
|
* @param callback - Function to invoke when values change.
|
|
32
34
|
* @param requireValues - If `true` will throw if accessing a value which is `undefined`.
|
|
33
35
|
*/
|
|
34
|
-
declare function watch<T extends
|
|
35
|
-
declare function watch<T extends
|
|
36
|
-
|
|
36
|
+
declare function watch<T extends Observable>(target: T, callback: Effect<Required<T>>, requireValues: true): () => void;
|
|
37
|
+
declare function watch<T extends Observable>(target: T, callback: Effect<T>, recursive?: boolean): () => void;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/state.d.ts
|
|
37
40
|
/** Reference bound instance methods to real ones. */
|
|
38
41
|
declare const METHOD: WeakMap<any, any>;
|
|
39
42
|
declare namespace State {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
(next: T): void;
|
|
97
|
-
current: T | null;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* A callback function which is subscribed to parent and updates when accessed properties change.
|
|
101
|
-
*
|
|
102
|
-
* @param current - Current state of this state. This is a proxy which detects properties which
|
|
103
|
-
* where accessed, and thus depended upon to stay current.
|
|
104
|
-
*
|
|
105
|
-
* @param update - Set of properties which have changed, and events fired, since last update.
|
|
106
|
-
*
|
|
107
|
-
* @returns A callback function which will be called when this effect is stale.
|
|
108
|
-
*/
|
|
109
|
-
type Effect<T> = (this: T, current: T, update: Set<Event<T>>) => EffectCallback | Promise<void> | null | void;
|
|
110
|
-
/**
|
|
111
|
-
* A callback function returned by effect. Will be called when effect is stale.
|
|
112
|
-
*
|
|
113
|
-
* @param update - `true` if update is pending, `false` effect has been cancelled, `null` if state is destroyed.
|
|
114
|
-
*/
|
|
115
|
-
type EffectCallback = (update: boolean | null) => void;
|
|
43
|
+
/** Any type of State, using own class constructor as its identifier. */
|
|
44
|
+
type Extends<T extends State = State> = (abstract new (...args: any[]) => T) & typeof State;
|
|
45
|
+
/** A State constructor which may be instanciated. */
|
|
46
|
+
type Type<T extends State = State> = (new (...args: State.Args<T>) => T) & Omit<typeof State, never>;
|
|
47
|
+
/** State constructor arguments */
|
|
48
|
+
type Args<T extends State = any> = (Args<T> | Init<T> | Assign<T> | string | void)[];
|
|
49
|
+
/**
|
|
50
|
+
* State constructor callback - is called when State finishes intializing.
|
|
51
|
+
* Returned function will run when state is destroyed.
|
|
52
|
+
*/
|
|
53
|
+
type Init<T extends State = State> = (this: T, thisArg: T) => Promise<void> | (() => void) | Args<T> | Assign<T> | void;
|
|
54
|
+
/** Object overlay to override values and methods on a state. */
|
|
55
|
+
type Assign<T> = Record<string, unknown> & { [K in Field<T>]?: T[K] extends ((...args: infer A) => infer R) ? (this: T, ...args: A) => R : T[K] };
|
|
56
|
+
/** Subset of `keyof T` which are not methods or defined by base State U. **/
|
|
57
|
+
type Field<T> = Exclude<keyof T, keyof State>;
|
|
58
|
+
/** Any valid key for state, including but not limited to Field<T>. */
|
|
59
|
+
type Event<T> = Field<T> | number | symbol | (string & {});
|
|
60
|
+
/** Export/Import compatible value for a given property in a State. */
|
|
61
|
+
type Export<R> = R extends {
|
|
62
|
+
get(): infer T;
|
|
63
|
+
} ? T : R;
|
|
64
|
+
/** Value for a property managed by a state. */
|
|
65
|
+
type Value<T extends State, K extends State.Event<T>> = K extends keyof T ? Export<T[K]> : unknown;
|
|
66
|
+
type Setter<T> = (value: T, previous: T) => boolean | void | (() => T);
|
|
67
|
+
type OnEvent<T extends State> = (this: T, key: unknown, source: T) => void | (() => void) | null;
|
|
68
|
+
type OnUpdate<T extends State, K extends State.Event<T>> = (this: T, key: K, thisArg: K) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Values from current state of given state.
|
|
71
|
+
* Differs from `Values` as values here will drill
|
|
72
|
+
* into "real" values held by exotics like ref.Object.
|
|
73
|
+
*/
|
|
74
|
+
type Values<T> = { [P in Field<T>]: Export<T[P]> };
|
|
75
|
+
/** Object comperable to data found in T. */
|
|
76
|
+
type Partial<T> = { [P in Field<T>]?: Export<T[P]> };
|
|
77
|
+
/** Exotic value, where actual value is contained within. */
|
|
78
|
+
type Ref<T = any> = {
|
|
79
|
+
(next: T): void;
|
|
80
|
+
current: T | null;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* A callback function which is subscribed to parent and updates when accessed properties change.
|
|
84
|
+
*
|
|
85
|
+
* @param current - Current state of this state. This is a proxy which detects properties which
|
|
86
|
+
* where accessed, and thus depended upon to stay current.
|
|
87
|
+
*
|
|
88
|
+
* @param update - Set of properties which have changed, and events fired, since last update.
|
|
89
|
+
*
|
|
90
|
+
* @returns A callback function which will be called when this effect is stale.
|
|
91
|
+
*/
|
|
92
|
+
type Effect<T> = (this: T, current: T, update: Set<State.Event<T>>) => EffectCallback | Promise<void> | null | void;
|
|
93
|
+
/**
|
|
94
|
+
* A callback function returned by effect. Will be called when effect is stale.
|
|
95
|
+
*
|
|
96
|
+
* @param update - `true` if update is pending, `false` effect has been cancelled, `null` if state is destroyed.
|
|
97
|
+
*/
|
|
98
|
+
type EffectCallback = (update: boolean | null) => void;
|
|
116
99
|
}
|
|
117
100
|
interface State {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Loopback to instance of this state. This is useful when in a subscribed context,
|
|
103
|
+
* to keep write access to `this` after a destructure. You can use it to read variables silently as well.
|
|
104
|
+
**/
|
|
105
|
+
is: this;
|
|
123
106
|
}
|
|
124
107
|
declare abstract class State implements Observable {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
108
|
+
constructor(...args: State.Args);
|
|
109
|
+
[Observable](callback: Observable.Callback, required?: boolean): this;
|
|
110
|
+
/**
|
|
111
|
+
* Optional lifecycle hook called during State initialization.
|
|
112
|
+
* Can return a cleanup function to run when state is destroyed.
|
|
113
|
+
*/
|
|
114
|
+
protected new?(): void | (() => void);
|
|
115
|
+
/**
|
|
116
|
+
* Pull current values from state. Flattens all states and exotic values recursively.
|
|
117
|
+
*
|
|
118
|
+
* @returns Object with all values from this state.
|
|
119
|
+
**/
|
|
120
|
+
get(): State.Values<this>;
|
|
121
|
+
/**
|
|
122
|
+
* Run a function which will run automatically when accessed values change.
|
|
123
|
+
*
|
|
124
|
+
* @param effect Function to run, and again whenever accessed values change.
|
|
125
|
+
* If effect returns a function, it will be called when a change occurs (syncronously),
|
|
126
|
+
* effect is cancelled, or parent state is destroyed.
|
|
127
|
+
* @returns Function to cancel listener.
|
|
128
|
+
*/
|
|
129
|
+
get(effect: State.Effect<this>): () => void;
|
|
130
|
+
/**
|
|
131
|
+
* Get value of a property.
|
|
132
|
+
*
|
|
133
|
+
* @param key - Property to get value of.
|
|
134
|
+
* @param required - If true, will throw an error if property is not available.
|
|
135
|
+
* @returns Value of property.
|
|
136
|
+
*/
|
|
137
|
+
get<T extends State.Event<this>>(key: T, required?: boolean): State.Value<this, T>;
|
|
138
|
+
/**
|
|
139
|
+
* Run a function when a property is updated.
|
|
140
|
+
*
|
|
141
|
+
* @param key - Property to watch for updates.
|
|
142
|
+
* @param callback - Function to call when property is updated.
|
|
143
|
+
* @returns Function to cancel listener.
|
|
144
|
+
*/
|
|
145
|
+
get<T extends State.Event<this>>(key: T, callback: State.OnUpdate<this, T>): () => void;
|
|
146
|
+
/**
|
|
147
|
+
* Check if state is expired.
|
|
148
|
+
*
|
|
149
|
+
* @param status - `null` to check if state is expired.
|
|
150
|
+
* @returns `true` if state is expired, `false` otherwise.
|
|
151
|
+
*/
|
|
152
|
+
get(status: null): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Callback when state is to be destroyed.
|
|
155
|
+
*
|
|
156
|
+
* @param callback - Function to call when state is destroyed.
|
|
157
|
+
* @returns Function to cancel listener.
|
|
158
|
+
*/
|
|
159
|
+
get(status: null, callback: () => void): () => void;
|
|
160
|
+
/**
|
|
161
|
+
* Get update in progress.
|
|
162
|
+
*
|
|
163
|
+
* @returns Promise which resolves object with updated values, `undefined` if there no update is pending.
|
|
164
|
+
**/
|
|
165
|
+
set(): PromiseLike<State.Event<this>[]> | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Update mulitple properties at once. Merges argument with current state.
|
|
168
|
+
* Properties which are not managed by this state will be ignored.
|
|
169
|
+
*
|
|
170
|
+
* @param assign - Object with properties to update.
|
|
171
|
+
* @param silent - If an update does occur, listeners will not be refreshed automatically.
|
|
172
|
+
* @returns Promise resolving an array of keys updated, `undefined` (immediately) if a noop.
|
|
173
|
+
*/
|
|
174
|
+
set(assign?: State.Assign<this>, silent?: boolean): PromiseLike<State.Event<this>[]> | undefined;
|
|
175
|
+
/**
|
|
176
|
+
* Push an update. This will not change the value of associated property.
|
|
177
|
+
*
|
|
178
|
+
* Useful where a property value internally has changed, but the object is the same.
|
|
179
|
+
* For example: An array has pushed a new value, or a nested property is updated.
|
|
180
|
+
*
|
|
181
|
+
* You can also use this to dispatch arbitrary events.
|
|
182
|
+
* Symbols are recommended as non-property events, however you can use any string.
|
|
183
|
+
* If doing so, be sure to avoid collisions with property names! An easy way to do this is
|
|
184
|
+
* to prefix an event with "!" and/or use dash-case. e.g. `set("!event")` or `set("my-event")`.
|
|
185
|
+
*
|
|
186
|
+
* @param key - Property or event to dispatch.
|
|
187
|
+
* @returns Promise resolves an array of keys updated.
|
|
188
|
+
*/
|
|
189
|
+
set(key: State.Event<this>): PromiseLike<State.Event<this>[]>;
|
|
190
|
+
/**
|
|
191
|
+
* Set a value for a property. This will update the value and notify listeners.
|
|
192
|
+
*
|
|
193
|
+
* **Use with caution!** Key nor value are checked for validity.
|
|
194
|
+
*
|
|
195
|
+
* This is meant for assigning values programmatically,
|
|
196
|
+
* where simple assignment is not practicable.
|
|
197
|
+
*
|
|
198
|
+
* For example: `(this as any)[myProperty] = value;`
|
|
199
|
+
*
|
|
200
|
+
* @param key - Property to set value for.
|
|
201
|
+
* @param value - Value to set for property.
|
|
202
|
+
* @param init - If true, state will begin to manage the property if it is not already.
|
|
203
|
+
* @returns Promise resolves an array of keys updated.
|
|
204
|
+
*/
|
|
205
|
+
set(key: State.Event<this>, value: unknown, init?: boolean): PromiseLike<State.Event<this>[]>;
|
|
206
|
+
/**
|
|
207
|
+
* Call a function when update occurs.
|
|
208
|
+
*
|
|
209
|
+
* Given function is called for every assignment (which changes value) or explicit `set`.
|
|
210
|
+
*
|
|
211
|
+
* To run logic on final value only, callback may return a function. Using the same
|
|
212
|
+
* function for one or more events will ensure it is called only when events are settled.
|
|
213
|
+
*
|
|
214
|
+
* @param callback - Function to call when update occurs.
|
|
215
|
+
* @returns Function to remove listener. Will return `true` if removed, `false` if inactive already.
|
|
216
|
+
*
|
|
217
|
+
*/
|
|
218
|
+
set(callback: State.OnEvent<this>): () => boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Call a function when a property is updated.
|
|
221
|
+
* Unlike `get`, this calls synchronously and will fire as many times as the property is updated.
|
|
222
|
+
*
|
|
223
|
+
* @param callback - Function to call when property is updated.
|
|
224
|
+
* @param event - Property to watch for updates.
|
|
225
|
+
*/
|
|
226
|
+
set(callback: State.OnEvent<this>, event: State.Event<this> | null): () => boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Declare an end to updates. This event is final and will freeze state.
|
|
229
|
+
* This event can be watched for as well, to run cleanup logic and internally will remove all listeners.
|
|
230
|
+
*
|
|
231
|
+
* @param status - `null` to end updates.
|
|
232
|
+
*/
|
|
233
|
+
set(status: null): void;
|
|
234
|
+
/**
|
|
235
|
+
* Iterate over managed properties in this instance of State.
|
|
236
|
+
* Yeilds the key and current value for each property.
|
|
237
|
+
*/
|
|
238
|
+
[Symbol.iterator](): Iterator<[string, unknown]>;
|
|
239
|
+
/**
|
|
240
|
+
* Create and activate a new instance of this state.
|
|
241
|
+
*
|
|
242
|
+
* **Important** - Unlike `new this(...)` - this method also activates state.
|
|
243
|
+
*
|
|
244
|
+
* @param args - arguments sent to constructor
|
|
245
|
+
*/
|
|
246
|
+
static new<T extends State>(this: State.Type<T>, ...args: State.Args<T>): T;
|
|
247
|
+
/**
|
|
248
|
+
* Static equivalent of `x instanceof this`.
|
|
249
|
+
* Determines if provided class is a subtype of this one.
|
|
250
|
+
* If so, language server will make available all static
|
|
251
|
+
* methods and properties of this class.
|
|
252
|
+
*/
|
|
253
|
+
static is<T extends State.Extends>(this: T, maybe: unknown): maybe is T;
|
|
254
|
+
/**
|
|
255
|
+
* Register a callback to run when any instance of this State is updated.
|
|
256
|
+
*/
|
|
257
|
+
static on<T extends State>(this: State.Extends<T>, listener: State.OnEvent<T>): () => boolean;
|
|
270
258
|
}
|
|
271
|
-
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/instruction/use.d.ts
|
|
272
261
|
/**
|
|
273
262
|
* Property initializer, will run upon instance creation.
|
|
274
263
|
* Optional returned callback will run when once upon first access.
|
|
275
264
|
*/
|
|
276
265
|
type Instruction<T = any, M extends State = any> = (this: M, key: Extract<State.Field<M>, string>, thisArg: M, state: State.Values<M>) => Instruction.Descriptor<T> | ((source: M) => T) | void;
|
|
277
266
|
declare namespace Instruction {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
267
|
+
type Getter<T> = (source: State) => T;
|
|
268
|
+
type Descriptor<T = any> = {
|
|
269
|
+
get?: Getter<T> | boolean;
|
|
270
|
+
set?: State.Setter<T> | boolean;
|
|
271
|
+
enumerable?: boolean;
|
|
272
|
+
value?: T;
|
|
273
|
+
};
|
|
285
274
|
}
|
|
286
275
|
declare function use<T>(instruction: Instruction<T>): T extends void ? unknown : T;
|
|
287
|
-
declare function use<T extends State>(Type: State.
|
|
288
|
-
declare function use<T extends State>(Type: State.
|
|
289
|
-
|
|
276
|
+
declare function use<T extends State>(Type: State.Type<T>, required: false): T | undefined;
|
|
277
|
+
declare function use<T extends State>(Type: State.Type<T>, ready?: (i: T) => void): T;
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region src/instruction/get.d.ts
|
|
290
280
|
declare namespace get {
|
|
291
|
-
|
|
281
|
+
type Callback<T = any> = (state: T, subject: State) => void | boolean | (() => void);
|
|
292
282
|
}
|
|
293
283
|
/**
|
|
294
284
|
* Fetches upstream State from context with optional lifecycle callback.
|
|
@@ -317,11 +307,12 @@ declare function get<T extends State>(Type: State.Extends<T>, required: false):
|
|
|
317
307
|
* @param callback - Optional lifecycle callback, receives (state, subject). May return false to prevent registration.
|
|
318
308
|
*/
|
|
319
309
|
declare function get<T extends State>(Type: State.Extends<T>, downstream: true, callback?: get.Callback<T>): readonly T[];
|
|
320
|
-
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/instruction/set.d.ts
|
|
321
312
|
declare namespace set {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
313
|
+
type Callback<T, S = any> = (this: S, next: T, previous: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
314
|
+
type Compute<T, S = any> = (on: S, key: string) => T;
|
|
315
|
+
type Factory<T, S = any> = (this: S, key: string) => Promise<T> | T;
|
|
325
316
|
}
|
|
326
317
|
/**
|
|
327
318
|
* Set property as `undefined` but required.
|
|
@@ -381,38 +372,35 @@ declare function set<R, T = any>(reactiveToThis: true, method: set.Compute<R, T>
|
|
|
381
372
|
* @param compute - Compute function. Bound to a subscriber-proxy of source, returns output value. Will update automatically as input values change.
|
|
382
373
|
*/
|
|
383
374
|
declare function set<R, T extends State>(reactiveTo: T, compute: set.Compute<R, T>): R;
|
|
384
|
-
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/instruction/ref.d.ts
|
|
385
377
|
declare namespace ref {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
[P in State.Field<T>]-?: R;
|
|
413
|
-
} & {
|
|
414
|
-
get(): T;
|
|
415
|
-
};
|
|
378
|
+
type Callback<T> = (argument: T) => ((next: T | null) => void) | Promise<void> | void | boolean;
|
|
379
|
+
interface Object<T = any> {
|
|
380
|
+
/** Current value held by this reference. */
|
|
381
|
+
current: T;
|
|
382
|
+
/** State instance this reference belongs to. */
|
|
383
|
+
is: State;
|
|
384
|
+
/** Key of property on state this reference belongs to. */
|
|
385
|
+
key: string;
|
|
386
|
+
/**
|
|
387
|
+
* Subscribe to changes of this reference.
|
|
388
|
+
*
|
|
389
|
+
* @param callback - Callback to invoke with the current value when it changes.
|
|
390
|
+
* @returns Unsubscribe function to stop listening to changes.
|
|
391
|
+
*/
|
|
392
|
+
get(callback: (value: T) => void): () => void;
|
|
393
|
+
/** Retrieve current value. */
|
|
394
|
+
get(): T | null;
|
|
395
|
+
}
|
|
396
|
+
/** Object with references to all managed values of `T`. */
|
|
397
|
+
/** Object with references to all managed values of `T`. */
|
|
398
|
+
type Proxy<T extends State> = { [P in State.Field<T>]-?: Object<T[P]> } & {
|
|
399
|
+
get(): T;
|
|
400
|
+
};
|
|
401
|
+
type CustomProxy<T extends State, R> = { [P in State.Field<T>]-?: R } & {
|
|
402
|
+
get(): T;
|
|
403
|
+
};
|
|
416
404
|
}
|
|
417
405
|
/**
|
|
418
406
|
* Creates an object with references to all managed values.
|
|
@@ -451,62 +439,64 @@ declare function ref<T>(callback?: ref.Callback<T>): ref.Object<T>;
|
|
|
451
439
|
* @param ignoreNull - Default `true`. If `false`, will still callback with `null`.
|
|
452
440
|
*/
|
|
453
441
|
declare function ref<T>(callback: ref.Callback<T | null>, ignoreNull: boolean): ref.Object<T>;
|
|
454
|
-
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/context.d.ts
|
|
455
444
|
declare namespace Context {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
445
|
+
type Multiple<T extends State> = {
|
|
446
|
+
[key: string | number]: State.Type<T> | T;
|
|
447
|
+
};
|
|
448
|
+
type Accept<T extends State = State> = T | State.Type<T> | Multiple<T>;
|
|
449
|
+
type Expect<T extends State = State> = (state: T) => (() => void) | void;
|
|
461
450
|
}
|
|
462
451
|
interface Context {
|
|
463
|
-
|
|
452
|
+
[key: symbol]: State | Context.Expect | null | undefined;
|
|
464
453
|
}
|
|
465
454
|
declare class Context {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
455
|
+
/**
|
|
456
|
+
* Get the context for a specified State. If a callback is provided, it will be run when
|
|
457
|
+
* the context becomes available.
|
|
458
|
+
*/
|
|
459
|
+
static get<T extends State>(on: State, callback: (got: Context) => void): void;
|
|
460
|
+
/**
|
|
461
|
+
* Get the context for a specified State. Returns undefined if none are found.
|
|
462
|
+
*/
|
|
463
|
+
static get<T extends State>(on: State): Context | undefined;
|
|
464
|
+
id: string;
|
|
465
|
+
protected inputs: Record<string | number, State | State.Extends>;
|
|
466
|
+
protected cleanup: Set<() => void>;
|
|
467
|
+
constructor(inputs?: Context.Accept);
|
|
468
|
+
/** Find specified type registered to a parent context. Throws if none are found. */
|
|
469
|
+
get<T extends State>(Type: State.Extends<T>, require: true): T;
|
|
470
|
+
/** Find specified type registered to a parent context. Returns undefined if none are found. */
|
|
471
|
+
get<T extends State>(Type: State.Extends<T>, require?: boolean): T | undefined;
|
|
472
|
+
/** Run callback when a specified type is registered in context downstream. */
|
|
473
|
+
get<T extends State>(Type: State.Extends<T>, callback: (state: T) => void): () => void;
|
|
474
|
+
/**
|
|
475
|
+
* Adds a State to this context.
|
|
476
|
+
*/
|
|
477
|
+
protected add<T extends State>(input: T | State.Type<T>, implicit?: boolean): T;
|
|
478
|
+
/**
|
|
479
|
+
* Register one or more States to this context.
|
|
480
|
+
*
|
|
481
|
+
* Context will add or remove States as needed to keep with provided input.
|
|
482
|
+
*
|
|
483
|
+
* @param inputs State, State class, or map of States / State classes to register.
|
|
484
|
+
* @param forEach Optional callback to run for each State registered.
|
|
485
|
+
*/
|
|
486
|
+
use<T extends State>(inputs: Context.Accept<T>, forEach?: Context.Expect<T>): void;
|
|
487
|
+
/**
|
|
488
|
+
* Create a child context, optionally registering one or more States to it.
|
|
489
|
+
*
|
|
490
|
+
* @param inputs State, State class, or map of States / State classes to register.
|
|
491
|
+
*/
|
|
492
|
+
push(inputs?: Context.Accept): this;
|
|
493
|
+
/**
|
|
494
|
+
* Remove all States from this context.
|
|
495
|
+
*
|
|
496
|
+
* Will also run any cleanup callbacks registered when States were added.
|
|
497
|
+
*/
|
|
498
|
+
pop(): void;
|
|
510
499
|
}
|
|
511
|
-
|
|
512
|
-
export { Context, Instruction, METHOD, Observable, State,
|
|
500
|
+
//#endregion
|
|
501
|
+
export { Context, type Instruction, METHOD, Observable, State, State as default, addListener, event, get, ref, set, use, watch };
|
|
502
|
+
//# sourceMappingURL=index.d.ts.map
|