@expressive/mvc 0.51.0 → 0.51.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
@@ -17,7 +17,7 @@ declare namespace Model {
17
17
  type Field<T> = Exclude<keyof T, keyof Model>;
18
18
  /** Any valid key for controller, including but not limited to Field<T>. */
19
19
  type Event<T> = Field<T> | (string & {}) | number | symbol;
20
- /** Object overlay which may be used to override values and methods on a model. */
20
+ /** Object overlay to override values and methods on a model. */
21
21
  type Assign<T> = {
22
22
  [K in Exclude<keyof T, keyof Model>]?: T[K] extends (...args: infer A) => infer R ? (this: T, ...args: A) => R : T[K];
23
23
  } & Record<string, unknown>;
@@ -67,12 +67,13 @@ declare namespace Model {
67
67
  * Property initializer, will run upon instance creation.
68
68
  * Optional returned callback will run when once upon first access.
69
69
  */
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;
70
+ type Instruction<T = any, M extends Model = any> = (this: M, key: Extract<Field<M>, string>, thisArg: M, state: State<M>) => Descriptor<T> | ((source: M) => T) | void;
71
+ type VoidInstruction<M extends Model = any> = (this: M, key: Extract<Field<M>, string>, thisArg: M, state: State<M>) => ((source: Model) => void) | void;
71
72
  type Getter<T> = (source: Model) => T;
72
73
  type Setter<T> = (value: T, previous: T) => boolean | void | (() => T);
73
74
  type Descriptor<T = any> = {
74
75
  get?: Getter<T> | boolean;
75
- set?: Setter<T> | false;
76
+ set?: Setter<T> | boolean;
76
77
  enumerable?: boolean;
77
78
  value?: T;
78
79
  };
@@ -177,12 +178,15 @@ declare abstract class Model {
177
178
  * @param silent - if true, will not notify listeners of an update
178
179
  */
179
180
  set<K extends string>(key: K, value?: Model.Value<this, K>, silent?: boolean): PromiseLike<Model.Event<this>[]> | undefined;
180
- /** Iterate over managed properties in this instance of Model. */
181
+ /**
182
+ * Iterate over managed properties in this instance of Model.
183
+ * Yeilds the key and underlying value for each property.
184
+ */
181
185
  [Symbol.iterator](): Iterator<[string, unknown]>;
182
186
  /**
183
- * Creates a new instance of this controller.
187
+ * Create and activate a new instance of this controller.
184
188
  *
185
- * **Important** - Use instead of `new this(...)` as this method also activates state.
189
+ * **Important** - Unlike `new this(...)` - this method also activates state.
186
190
  *
187
191
  * @param args - arguments sent to constructor
188
192
  */
@@ -343,7 +347,8 @@ declare function set<T>(factory: set.Factory<T> | Promise<T>, required?: boolean
343
347
  */
344
348
  declare function set<T>(value: T | undefined, onUpdate: set.Callback<T>): T;
345
349
 
346
- declare function use<T = any>(instruction: Model.Instruction): T;
350
+ declare function use(instruction: Model.VoidInstruction): unknown;
351
+ declare function use<T>(instruction: Model.Instruction<T>): T;
347
352
  declare function use<T extends Model>(Type: Model.Init<T>, required: false): T | undefined;
348
353
  declare function use<T extends Model>(Type: Model.Init<T>, ready?: (i: T) => void): T;
349
354
 
package/dist/index.js CHANGED
@@ -271,8 +271,10 @@ var Model = class _Model {
271
271
  if (typeof key2 == "string")
272
272
  return arg1.call(self, key2, self);
273
273
  });
274
- if (arg1 === null)
275
- return emit(this, null);
274
+ if (arg1 === null) {
275
+ emit(this, null);
276
+ return;
277
+ }
276
278
  if (typeof arg1 == "object")
277
279
  assign(self, arg1);
278
280
  else if (arg1 == void 0)
@@ -293,14 +295,17 @@ var Model = class _Model {
293
295
  }).then(res)
294
296
  };
295
297
  }
296
- /** Iterate over managed properties in this instance of Model. */
298
+ /**
299
+ * Iterate over managed properties in this instance of Model.
300
+ * Yeilds the key and underlying value for each property.
301
+ */
297
302
  [Symbol.iterator]() {
298
303
  return Object.entries(STATE.get(this.is))[Symbol.iterator]();
299
304
  }
300
305
  /**
301
- * Creates a new instance of this controller.
306
+ * Create and activate a new instance of this controller.
302
307
  *
303
- * **Important** - Use instead of `new this(...)` as this method also activates state.
308
+ * **Important** - Unlike `new this(...)` - this method also activates state.
304
309
  *
305
310
  * @param args - arguments sent to constructor
306
311
  */
package/dist/index.mjs CHANGED
@@ -237,8 +237,10 @@ var Model = class _Model {
237
237
  if (typeof key2 == "string")
238
238
  return arg1.call(self, key2, self);
239
239
  });
240
- if (arg1 === null)
241
- return emit(this, null);
240
+ if (arg1 === null) {
241
+ emit(this, null);
242
+ return;
243
+ }
242
244
  if (typeof arg1 == "object")
243
245
  assign(self, arg1);
244
246
  else if (arg1 == void 0)
@@ -259,14 +261,17 @@ var Model = class _Model {
259
261
  }).then(res)
260
262
  };
261
263
  }
262
- /** Iterate over managed properties in this instance of Model. */
264
+ /**
265
+ * Iterate over managed properties in this instance of Model.
266
+ * Yeilds the key and underlying value for each property.
267
+ */
263
268
  [Symbol.iterator]() {
264
269
  return Object.entries(STATE.get(this.is))[Symbol.iterator]();
265
270
  }
266
271
  /**
267
- * Creates a new instance of this controller.
272
+ * Create and activate a new instance of this controller.
268
273
  *
269
- * **Important** - Use instead of `new this(...)` as this method also activates state.
274
+ * **Important** - Unlike `new this(...)` - this method also activates state.
270
275
  *
271
276
  * @param args - arguments sent to constructor
272
277
  */
package/package.json CHANGED
@@ -28,6 +28,10 @@
28
28
  "prebuild": "rm -rf dist",
29
29
  "preversion": "npm run test && npm run build"
30
30
  },
31
- "version": "0.51.0",
32
- "gitHead": "9f020cb09a146bcb14e9deb765c07beab345ea95"
31
+ "devDependencies": {
32
+ "jest": "^27.0.6",
33
+ "tsup": "^8.0.2"
34
+ },
35
+ "version": "0.51.1",
36
+ "gitHead": "b5169ea695a97e020e0266f84db55ab4a12fa3b5"
33
37
  }