@expressive/mvc 0.52.2-alpha.74 → 0.53.2

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/index.d.ts CHANGED
@@ -1,3 +1,30 @@
1
+ /**
2
+ * Update callback function.
3
+ *
4
+ * @param key -
5
+ * - `string` - property which has updated.
6
+ * - `false` - a normal update has completed.
7
+ * - `true` - initial event; instance is ready.
8
+ * - `null` - terminal event; instance is expired.
9
+ * @param source - Instance of Model for which update has occured.
10
+ */
11
+ type OnUpdate<T extends Model = any> = (this: T, key: unknown, source: T) => (() => void) | null | void;
12
+ type OnAccess<T extends Model = any, R = unknown> = (from: T, key: string | number, value: R) => unknown;
13
+ type Effect<T extends Model> = (this: T, proxy: T) => ((update: boolean | null) => void) | Promise<void> | null | void;
14
+ type Event = number | string | null | boolean | symbol;
15
+ declare function addListener<T extends Model>(subject: T, callback: OnUpdate<T>, select?: Event): () => boolean;
16
+ declare function createProxy<T extends Model>(from: T, observer: OnAccess<T>): T;
17
+ /**
18
+ * Create a side-effect which will update whenever values accessed change.
19
+ * Callback is called immediately and if ever values are stale.
20
+ *
21
+ * @param target - Instance of Model to observe.
22
+ * @param callback - Function to invoke when values change.
23
+ * @param requireValues - If `true` will throw if accessing a value which is `undefined`.
24
+ */
25
+ declare function createEffect<T extends Model>(target: T, callback: Effect<Required<T>>, requireValues: true): () => void;
26
+ declare function createEffect<T extends Model>(target: T, callback: Effect<T>, requireValues?: boolean): () => void;
27
+
1
28
  declare namespace Model {
2
29
  /** Any type of Model, using own class constructor as its identifier. */
3
30
  type Type<T extends Model = Model> = (abstract new (...args: any[]) => T) & typeof Model;
@@ -27,7 +54,7 @@ declare namespace Model {
27
54
  /** Value for a property managed by a model. */
28
55
  type Value<T extends Model, K extends Event<T>> = K extends keyof T ? Export<T[K]> : unknown;
29
56
  type OnEvent<T extends Model> = (this: T, key: unknown, source: T) => (() => void) | void | null;
30
- type OnUpdate<T extends Model, K extends Event<T>> = (this: T, value: Value<T, K>, key: K, thisArg: K) => void;
57
+ type OnUpdate<T extends Model, K extends Event<T>> = (this: T, key: K, thisArg: K) => void;
31
58
  /**
32
59
  * Values from current state of given model.
33
60
  * Differs from `Values` as values here will drill
@@ -141,9 +168,10 @@ declare abstract class Model {
141
168
  * Properties which are not managed by this model will be ignored.
142
169
  *
143
170
  * @param assign - Object with properties to update.
171
+ * @param silent - If an update does occur, listeners will not be refreshed automatically.
144
172
  * @returns Promise resolving an array of keys updated, `undefined` (immediately) if a noop.
145
173
  */
146
- set(assign: Model.Assign<this>): PromiseLike<Model.Event<this>[]> | undefined;
174
+ set(assign: Model.Assign<this>, silent?: boolean): PromiseLike<Model.Event<this>[]> | undefined;
147
175
  /**
148
176
  * Push an update. This will not change the value of associated property.
149
177
  *
@@ -159,15 +187,6 @@ declare abstract class Model {
159
187
  * @returns Promise resolves an array of keys updated.
160
188
  */
161
189
  set(key: Model.Event<this>): PromiseLike<Model.Event<this>[]>;
162
- /**
163
- * Update a property with value.
164
- *
165
- * @param key - property to update
166
- * @param value - value to update property with (if the same as current, no update will occur)
167
- * @param silent - if true, will not notify listeners of an update
168
- * @returns Promise resolving an array of keys updated, `undefined` (immediately) if a noop.
169
- */
170
- set<K extends string>(key: K, value: Model.Value<this, K>, silent?: boolean): PromiseLike<Model.Event<this>[]> | undefined;
171
190
  /**
172
191
  * Call a function when update occurs.
173
192
  *
@@ -190,7 +209,7 @@ declare abstract class Model {
190
209
  set(status: null): void;
191
210
  /**
192
211
  * Iterate over managed properties in this instance of Model.
193
- * Yeilds the key and underlying value for each property.
212
+ * Yeilds the key and current value for each property.
194
213
  */
195
214
  [Symbol.iterator](): Iterator<[string, unknown]>;
196
215
  /**
@@ -215,9 +234,10 @@ declare abstract class Model {
215
234
  }
216
235
 
217
236
  declare namespace get {
218
- type Function<T, S = any> = (on: S, key: string) => T;
237
+ type Compute<T, S = any> = (on: S, key: string) => T;
219
238
  type Factory<T, S = any> = (this: S, key: string, thisArg: S) => T;
220
239
  type Source<T extends Model = Model> = (resolve: (x: T) => void) => void;
240
+ type Effect<T> = (model: T, key: string) => (() => void) | void;
221
241
  }
222
242
  /**
223
243
  * Fetches and assigns the controller which spawned this host.
@@ -244,14 +264,14 @@ declare function get<T extends Model>(Type: Model.Type<T>, required?: false): T
244
264
  * @param source - Type of Model to fetch for computation.
245
265
  * @param compute - Compute function. Will update automatically as input values change.
246
266
  */
247
- declare function get<R, T extends Model>(Type: Model.Type<T>, compute: get.Function<R, T>): R;
267
+ declare function get<T extends Model>(Type: Model.Type<T>, effect: get.Effect<T>): T;
248
268
  /**
249
269
  * Implement a computed value; output will be generated by provided function.
250
270
  *
251
271
  * @param source - Source model from which computed value will be a subscriber.
252
272
  * @param compute - Compute function. Bound to a subscriber-proxy of source, returns output value. Will update automatically as input values change.
253
273
  */
254
- declare function get<R, T extends Model>(source: T, compute: get.Function<R, T>): R;
274
+ declare function get<R, T extends Model>(source: T, compute: get.Compute<R, T>): R;
255
275
  /**
256
276
  * Implement a computed value; output is returned by function from provided factory.
257
277
  *
@@ -367,33 +387,6 @@ declare namespace has {
367
387
  declare function has<T extends Model>(type: Model.Type<T>, callback?: has.Callback<T>): readonly T[];
368
388
  declare function has(callback?: has.Callback): readonly Model[];
369
389
 
370
- /**
371
- * Update callback function.
372
- *
373
- * @param key -
374
- * - `string` - property which has updated.
375
- * - `false` - a normal update has completed.
376
- * - `true` - initial event; instance is ready.
377
- * - `null` - terminal event; instance is expired.
378
- * @param source - Instance of Model for which update has occured.
379
- */
380
- type OnUpdate<T = any> = (this: T, key: unknown, source: T) => (() => void) | null | void;
381
- type OnAccess<T, R = unknown> = (from: T, key: string | number, value: R) => unknown;
382
- type Event = number | string | null | boolean | symbol;
383
- declare function addListener(subject: {}, callback: OnUpdate, select?: Event): () => boolean;
384
- declare function createProxy<T extends {}>(from: T, observer: OnAccess<T>): any;
385
- type Effect<T extends {}> = (this: T, argument: T) => ((update: boolean | null) => void) | Promise<void> | null | void;
386
- /**
387
- * Create a side-effect which will update whenever values accessed change.
388
- * Callback is called immediately and if ever values are stale.
389
- *
390
- * @param target - Instance of Model to observe.
391
- * @param callback - Function to invoke when values change.
392
- * @param requireValues - If `true` will throw if accessing a value which is `undefined`.
393
- */
394
- declare function createEffect<T extends {}>(target: T, callback: Effect<Required<T>>, requireValues: true): () => void;
395
- declare function createEffect<T extends {}>(target: T, callback: Effect<T>, requireValues?: boolean): () => void;
396
-
397
390
  declare namespace Context {
398
391
  type Multiple<T extends Model> = {
399
392
  [key: string | number]: Model.Init<T> | T;