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