@expressive/mvc 0.48.0 → 0.50.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/dist/index.d.ts CHANGED
@@ -61,21 +61,19 @@ declare namespace Model {
61
61
  * @param update - `true` if update is pending, `false` effect has been cancelled, `null` if controller is destroyed.
62
62
  */
63
63
  type EffectCallback = ((update: boolean | null) => void);
64
- namespace Instruction {
65
- type Getter<T> = (source: Model) => T;
66
- type Setter<T> = (value: T, previous: T) => boolean | void | (() => T);
67
- type Descriptor<T = any> = {
68
- get?: Getter<T> | boolean;
69
- set?: Setter<T> | false;
70
- enumerable?: boolean;
71
- value?: T;
72
- };
73
- }
74
64
  /**
75
65
  * Property initializer, will run upon instance creation.
76
66
  * Optional returned callback will run when once upon first access.
77
67
  */
78
- type Instruction<T = any, M extends Model = any> = (this: M, key: Field<M> & string, thisArg: M, state: State<M>) => Instruction.Descriptor<T> | Instruction.Getter<T> | void;
68
+ type Instruction<T = any, M extends Model = any> = (this: M, key: Field<M> & string, thisArg: M, state: State<M>) => Descriptor<T> | Getter<T> | void;
69
+ type Getter<T> = (source: Model) => T;
70
+ type Setter<T> = (value: T, previous: T) => boolean | void | (() => T);
71
+ type Descriptor<T = any> = {
72
+ get?: Getter<T> | boolean;
73
+ set?: Setter<T> | false;
74
+ enumerable?: boolean;
75
+ value?: T;
76
+ };
79
77
  }
80
78
  interface Model {
81
79
  /**
@@ -309,7 +307,7 @@ declare function ref<T = HTMLElement>(callback: ref.Callback<T | null>, ignoreNu
309
307
 
310
308
  declare namespace set {
311
309
  type Callback<T, S = any> = (this: S, next: T, previous: T) => ((next: T) => void) | Promise<any> | void | boolean;
312
- type Factory<T, S = any> = (this: S, key: string, thisArg: S) => Promise<T> | T;
310
+ type Factory<T, S = any> = (this: S, key: string) => Promise<T> | T;
313
311
  }
314
312
  /**
315
313
  * Set property with a placeholder.
@@ -348,31 +346,42 @@ declare function use<T extends Model>(Type: Model.Type<T>, required: false): T |
348
346
  declare function use<T extends Model>(Type: Model.Type<T>, ready?: (i: T) => void): T;
349
347
 
350
348
  declare namespace has {
351
- type Callback<T = any> = (model: T) => void | boolean | (() => void);
349
+ type Callback<T = any> = (model: T, recipient: Model) => void | boolean | (() => void);
352
350
  }
353
- declare function has<T extends Model>(type: Model.Type<T>, one: true): T;
354
- declare function has<T extends Model>(type: Model.Type<T>, required: boolean): T | undefined;
355
- declare function has<T extends Model>(type: Model.Type<T>, arg?: has.Callback<T>): Set<T>;
351
+ declare function has<T extends Model>(type: Model.Type<T>, callback?: has.Callback<T>): readonly T[];
352
+ declare function has(callback?: has.Callback): readonly Model[];
353
+
354
+ type Effect<T extends {}> = (this: T, argument: T) => ((update: boolean | null) => void) | Promise<void> | null | void;
355
+ /**
356
+ * Create a side-effect which will update whenever values accessed change.
357
+ * Callback is called immediately and if ever values are stale.
358
+ *
359
+ * @param target - Instance of Model to observe.
360
+ * @param callback - Function to invoke when values change.
361
+ * @param requireValues - If `true` will throw if accessing a value which is `undefined`.
362
+ */
363
+ declare function effect<T extends {}>(target: T, callback: Effect<Required<T>>, requireValues: true): () => void;
364
+ declare function effect<T extends {}>(target: T, callback: Effect<T>, requireValues?: boolean): () => void;
356
365
 
357
366
  declare namespace Context {
358
367
  type Input = Record<string | number, Model | Model.Type<Model>>;
368
+ type Expect = (model: Model) => (() => void) | void;
359
369
  }
360
370
  declare class Context {
361
371
  static get<T extends Model>(on: Model, callback: ((got: Context) => void)): void;
362
372
  static get<T extends Model>(on: Model): Context | undefined;
363
373
  id: string;
364
- protected downstream: WeakMap<Model.Type<Model>, symbol>;
365
- protected upstream: WeakMap<Model.Type<Model>, symbol>;
366
374
  protected layer: Map<string | number, Model | Model.Type<Model>>;
375
+ protected cleanup: Set<() => void>;
367
376
  constructor(inputs?: Context.Input);
368
- key(T: Model.Type, upstream?: boolean): keyof this;
369
- has(model: Model): (() => void) | undefined;
370
377
  get<T extends Model>(Type: Model.Type<T>): T | undefined;
371
- include(inputs: Context.Input, forEach?: (added: Model, explicit: boolean) => void): void;
372
- put<T extends Model>(T: Model.Type<T>, I: T | ((model: T) => void), implicit?: boolean, writable?: boolean): void;
373
- add<T extends Model>(input: T | Model.Type<T>, implicit?: boolean): T;
378
+ get<T extends Model>(Type: Model.Type<T>, callback: (model: T) => void): void;
374
379
  push(inputs?: Context.Input): this;
375
380
  pop(): void;
381
+ include(inputs: Context.Input, forEach?: (added: Model, explicit: boolean) => void): void;
382
+ protected add<T extends Model>(input: T | Model.Type<T>, implicit?: boolean): T;
383
+ protected has<T extends Model>(type: Model.Type<T>, model: T): void;
384
+ protected put<T extends Model>(T: Model.Type<T>, I: T | ((model: T) => void), implicit?: boolean): void;
376
385
  }
377
386
 
378
387
  declare global {
@@ -392,4 +401,4 @@ declare global {
392
401
  }
393
402
  }
394
403
 
395
- export { Context, Model, Model as default, get, has, ref, set, use };
404
+ export { Context, Model, Model as default, effect, get, has, ref, set, use };