@expressive/mvc 0.43.0 → 0.43.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
@@ -7,7 +7,7 @@ declare namespace Model {
7
7
  * Model constructor callback - is called when Model finishes intializing.
8
8
  * Returned function will call when model is destroyed.
9
9
  */
10
- type Callback<T extends Model = Model> = (this: T, thisArg: T) => (() => void) | Assign<T> | void;
10
+ type Callback<T extends Model = Model> = (this: T, thisArg: T) => (() => void) | Assign<T> | Promise<void> | void;
11
11
  /** Model constructor argument */
12
12
  type Argument<T extends Model = Model> = string | Callback<T> | Assign<T> | undefined;
13
13
  /** Subset of `keyof T` which are not methods or defined by base Model U. **/
package/dist/index.js CHANGED
@@ -160,7 +160,7 @@ var Model = class _Model {
160
160
  constructor(arg) {
161
161
  const state = {};
162
162
  let Type = this.constructor;
163
- bind(Type);
163
+ bindMethods(Type);
164
164
  define(this, "is", { value: this });
165
165
  STATE.set(this, state);
166
166
  NAMES.set(this, typeof arg == "string" ? arg : `${Type}-${uid()}`);
@@ -172,7 +172,12 @@ var Model = class _Model {
172
172
  }
173
173
  addListener(this, () => {
174
174
  const apply = typeof arg == "function" ? arg.call(this, this) : arg;
175
- if (typeof apply == "object")
175
+ if (apply instanceof Promise)
176
+ apply.catch((err) => {
177
+ console.error(`Async error in constructor for ${this}:`);
178
+ console.error(err);
179
+ });
180
+ else if (typeof apply == "object")
176
181
  assign(this, apply);
177
182
  for (const key in this) {
178
183
  const desc = Object.getOwnPropertyDescriptor(this, key);
@@ -372,26 +377,26 @@ function assign(to, values) {
372
377
  if (applicable.has(key))
373
378
  to[key] = values[key];
374
379
  }
375
- function bind(type) {
380
+ function bindMethods(type) {
376
381
  let keys = METHODS.get(type);
377
382
  if (!keys) {
378
- METHODS.set(type, keys = bind2(Object.getPrototypeOf(type)).slice());
383
+ METHODS.set(type, keys = bindMethods(Object.getPrototypeOf(type)).slice());
379
384
  const desc = Object.getOwnPropertyDescriptors(type.prototype);
380
385
  for (const key in desc)
381
386
  if (key != "constructor" && "value" in desc[key]) {
382
- let bind3 = function(method) {
387
+ let bind2 = function(method) {
383
388
  const value2 = method.bind(this.is);
384
389
  METHOD.set(value2, method);
385
390
  define(this.is, key, { value: value2, writable: true });
386
391
  return value2;
387
392
  };
388
- var bind2 = bind3;
393
+ var bind = bind2;
389
394
  let { value } = desc[key];
390
395
  keys.push(key);
391
396
  Object.defineProperty(type.prototype, key, {
392
- set: bind3,
397
+ set: bind2,
393
398
  get() {
394
- return this.hasOwnProperty(key) ? value : bind3.call(this, value);
399
+ return this.hasOwnProperty(key) ? value : bind2.call(this, value);
395
400
  }
396
401
  });
397
402
  }
package/dist/index.mjs CHANGED
@@ -126,7 +126,7 @@ var Model = class _Model {
126
126
  constructor(arg) {
127
127
  const state = {};
128
128
  let Type = this.constructor;
129
- bind(Type);
129
+ bindMethods(Type);
130
130
  define(this, "is", { value: this });
131
131
  STATE.set(this, state);
132
132
  NAMES.set(this, typeof arg == "string" ? arg : `${Type}-${uid()}`);
@@ -138,7 +138,12 @@ var Model = class _Model {
138
138
  }
139
139
  addListener(this, () => {
140
140
  const apply = typeof arg == "function" ? arg.call(this, this) : arg;
141
- if (typeof apply == "object")
141
+ if (apply instanceof Promise)
142
+ apply.catch((err) => {
143
+ console.error(`Async error in constructor for ${this}:`);
144
+ console.error(err);
145
+ });
146
+ else if (typeof apply == "object")
142
147
  assign(this, apply);
143
148
  for (const key in this) {
144
149
  const desc = Object.getOwnPropertyDescriptor(this, key);
@@ -338,26 +343,26 @@ function assign(to, values) {
338
343
  if (applicable.has(key))
339
344
  to[key] = values[key];
340
345
  }
341
- function bind(type) {
346
+ function bindMethods(type) {
342
347
  let keys = METHODS.get(type);
343
348
  if (!keys) {
344
- METHODS.set(type, keys = bind2(Object.getPrototypeOf(type)).slice());
349
+ METHODS.set(type, keys = bindMethods(Object.getPrototypeOf(type)).slice());
345
350
  const desc = Object.getOwnPropertyDescriptors(type.prototype);
346
351
  for (const key in desc)
347
352
  if (key != "constructor" && "value" in desc[key]) {
348
- let bind3 = function(method) {
353
+ let bind2 = function(method) {
349
354
  const value2 = method.bind(this.is);
350
355
  METHOD.set(value2, method);
351
356
  define(this.is, key, { value: value2, writable: true });
352
357
  return value2;
353
358
  };
354
- var bind2 = bind3;
359
+ var bind = bind2;
355
360
  let { value } = desc[key];
356
361
  keys.push(key);
357
362
  Object.defineProperty(type.prototype, key, {
358
- set: bind3,
363
+ set: bind2,
359
364
  get() {
360
- return this.hasOwnProperty(key) ? value : bind3.call(this, value);
365
+ return this.hasOwnProperty(key) ? value : bind2.call(this, value);
361
366
  }
362
367
  });
363
368
  }
package/package.json CHANGED
@@ -28,6 +28,6 @@
28
28
  "prebuild": "rm -rf dist",
29
29
  "preversion": "npm run test && npm run build"
30
30
  },
31
- "version": "0.43.0",
32
- "gitHead": "ec66b5e7a3b7d2c525c2e9503c8cd4fd81e121a6"
31
+ "version": "0.43.2",
32
+ "gitHead": "42ef497ab04cb9921fd76e8b70b5bf9072176c82"
33
33
  }