@expressive/mvc 0.49.0 → 0.50.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/index.d.ts CHANGED
@@ -2,6 +2,8 @@ type MaybeAsync<T> = T | Promise<T>;
2
2
  declare namespace Model {
3
3
  /** Any type of Model, using own class constructor as its identifier. */
4
4
  type Type<T extends Model = Model> = (abstract new (...args: any[]) => T) & typeof Model;
5
+ /** A Model constructor, but which is not abstract. */
6
+ type Init<T extends Model = Model> = (new (...args: Model.Args<T>) => T) & Omit<typeof Model, never>;
5
7
  /**
6
8
  * Model constructor callback - is called when Model finishes intializing.
7
9
  * Returned function will call when model is destroyed.
@@ -61,21 +63,19 @@ declare namespace Model {
61
63
  * @param update - `true` if update is pending, `false` effect has been cancelled, `null` if controller is destroyed.
62
64
  */
63
65
  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
66
  /**
75
67
  * Property initializer, will run upon instance creation.
76
68
  * Optional returned callback will run when once upon first access.
77
69
  */
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;
70
+ type Instruction<T = any, M extends Model = any> = (this: M, key: Field<M> & string, thisArg: M, state: State<M>) => Descriptor<T> | Getter<T> | void;
71
+ type Getter<T> = (source: Model) => T;
72
+ type Setter<T> = (value: T, previous: T) => boolean | void | (() => T);
73
+ type Descriptor<T = any> = {
74
+ get?: Getter<T> | boolean;
75
+ set?: Setter<T> | false;
76
+ enumerable?: boolean;
77
+ value?: T;
78
+ };
79
79
  }
80
80
  interface Model {
81
81
  /**
@@ -84,7 +84,7 @@ interface Model {
84
84
  **/
85
85
  is: this;
86
86
  }
87
- declare class Model {
87
+ declare abstract class Model {
88
88
  constructor(...args: Model.Args);
89
89
  /** Pull current values from state. Flattens all models and exotic values recursively. */
90
90
  get(): Model.State<this>;
@@ -186,14 +186,14 @@ declare class Model {
186
186
  *
187
187
  * @param args - arguments sent to constructor
188
188
  */
189
- static new<T extends Model>(this: Model.Type<T>, ...args: Model.Args<T>): T;
189
+ static new<T extends Model>(this: Model.Init<T>, ...args: Model.Args<T>): T;
190
190
  /**
191
191
  * Static equivalent of `x instanceof this`.
192
192
  * Determines if provided class is a subtype of this one.
193
193
  * If so, language server will make available all static
194
194
  * methods and properties of this class.
195
195
  */
196
- static is<T extends Model.Type>(this: T, maybe: any): maybe is T;
196
+ static is<T extends Model.Type>(this: T, maybe: unknown): maybe is T;
197
197
  /**
198
198
  * Register a callback to run when any instance of this Model is updated.
199
199
  */
@@ -295,7 +295,7 @@ declare function ref<O extends Model, R>(target: O, mapper: (key: Model.Field<O>
295
295
  *
296
296
  * @param callback - Optional callback to synchronously fire when reference is first set or does update.
297
297
  */
298
- declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>;
298
+ declare function ref<T>(callback?: ref.Callback<T>): ref.Object<T>;
299
299
  /**
300
300
  * Creates a ref-compatible property.
301
301
  * Will persist value, and updates to this are made part of controller event-stream.
@@ -305,11 +305,11 @@ declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>
305
305
  * @param callback - Optional callback to synchronously fire when reference is first set or does update.
306
306
  * @param ignoreNull - Default `true`. If `false`, will still callback with `null`.
307
307
  */
308
- declare function ref<T = HTMLElement>(callback: ref.Callback<T | null>, ignoreNull: boolean): ref.Object<T>;
308
+ declare function ref<T>(callback: ref.Callback<T | null>, ignoreNull: boolean): ref.Object<T>;
309
309
 
310
310
  declare namespace set {
311
311
  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;
312
+ type Factory<T, S = any> = (this: S, key: string) => Promise<T> | T;
313
313
  }
314
314
  /**
315
315
  * Set property with a placeholder.
@@ -344,15 +344,14 @@ declare function set<T>(factory: set.Factory<T> | Promise<T>, required?: boolean
344
344
  declare function set<T>(value: T | undefined, onUpdate: set.Callback<T>): T;
345
345
 
346
346
  declare function use<T = any>(instruction: Model.Instruction): T;
347
- declare function use<T extends Model>(Type: Model.Type<T>, required: false): T | undefined;
348
- declare function use<T extends Model>(Type: Model.Type<T>, ready?: (i: T) => void): T;
347
+ declare function use<T extends Model>(Type: Model.Init<T>, required: false): T | undefined;
348
+ declare function use<T extends Model>(Type: Model.Init<T>, ready?: (i: T) => void): T;
349
349
 
350
350
  declare namespace has {
351
- type Callback<T = any> = (model: T) => void | boolean | (() => void);
351
+ type Callback<T = any> = (model: T, recipient: Model) => void | boolean | (() => void);
352
352
  }
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>;
353
+ declare function has<T extends Model>(type: Model.Type<T>, callback?: has.Callback<T>): readonly T[];
354
+ declare function has(callback?: has.Callback): readonly Model[];
356
355
 
357
356
  type Effect<T extends {}> = (this: T, argument: T) => ((update: boolean | null) => void) | Promise<void> | null | void;
358
357
  /**
@@ -367,24 +366,25 @@ declare function effect<T extends {}>(target: T, callback: Effect<Required<T>>,
367
366
  declare function effect<T extends {}>(target: T, callback: Effect<T>, requireValues?: boolean): () => void;
368
367
 
369
368
  declare namespace Context {
370
- type Input = Record<string | number, Model | Model.Type<Model>>;
369
+ type Input = Record<string | number, Model | Model.Init>;
370
+ type Expect = (model: Model) => (() => void) | void;
371
+ }
372
+ interface Context {
373
+ [key: symbol]: Model | Context.Expect | null | undefined;
371
374
  }
372
375
  declare class Context {
373
376
  static get<T extends Model>(on: Model, callback: ((got: Context) => void)): void;
374
377
  static get<T extends Model>(on: Model): Context | undefined;
375
378
  id: string;
376
- protected downstream: WeakMap<Model.Type<Model>, symbol>;
377
- protected upstream: WeakMap<Model.Type<Model>, symbol>;
378
379
  protected layer: Map<string | number, Model | Model.Type<Model>>;
380
+ protected cleanup: Set<() => void>;
379
381
  constructor(inputs?: Context.Input);
380
- key(T: Model.Type, upstream?: boolean): keyof this;
381
- has(model: Model): (() => void) | undefined;
382
382
  get<T extends Model>(Type: Model.Type<T>): T | undefined;
383
- include(inputs: Context.Input, forEach?: (added: Model, explicit: boolean) => void): void;
384
- put<T extends Model>(T: Model.Type<T>, I: T | ((model: T) => void), implicit?: boolean, writable?: boolean): void;
385
- add<T extends Model>(input: T | Model.Type<T>, implicit?: boolean): T;
383
+ get<T extends Model>(Type: Model.Type<T>, callback: (model: T) => void): void;
386
384
  push(inputs?: Context.Input): this;
387
385
  pop(): void;
386
+ include(inputs: Context.Input, forEach?: (added: Model, explicit: boolean) => void): void;
387
+ protected add<T extends Model>(input: T | Model.Init<T>, implicit?: boolean): T;
388
388
  }
389
389
 
390
390
  declare global {