@expressive/mvc 0.44.0 → 0.45.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
@@ -1,3 +1,4 @@
1
+ type MaybeAsync<T> = T | Promise<T>;
1
2
  declare namespace Model {
2
3
  /** Any type of Model, using own class constructor as its identifier. */
3
4
  type Type<T extends Model = Model> = (abstract new (...args: any[]) => T) & typeof Model;
@@ -5,9 +6,9 @@ declare namespace Model {
5
6
  * Model constructor callback - is called when Model finishes intializing.
6
7
  * Returned function will call when model is destroyed.
7
8
  */
8
- type Callback<T extends Model = Model> = (this: T, thisArg: T) => (() => void) | Assign<T> | Promise<void> | void;
9
+ type Callback<T extends Model = Model> = (this: T, thisArg: T) => MaybeAsync<(() => void) | Assign<T> | void>;
9
10
  /** Model constructor argument */
10
- type Argument<T extends Model = Model> = string | Callback<T> | Assign<T> | void;
11
+ type Argument<T extends Model = Model> = string | Assign<T> | Callback<T> | Promise<Assign<T> | (() => void) | void> | void;
11
12
  /** Model constructor arguments */
12
13
  type Args<T extends Model = any> = Argument<T>[];
13
14
  /** Subset of `keyof T` which are not methods or defined by base Model U. **/
@@ -16,7 +17,7 @@ declare namespace Model {
16
17
  type Event<T> = Field<T> | (string & {}) | number | symbol;
17
18
  /** Object overlay which may be used to override values and methods while creating model. */
18
19
  type Assign<T> = {
19
- [K in Exclude<keyof T, keyof Model>]?: T[K] extends (...args: any[]) => infer R ? (this: T, ...args: Parameters<T[K]>) => ReturnType<T[K]> : T[K];
20
+ [K in Exclude<keyof T, keyof Model>]?: T[K] extends (...args: infer A) => infer R ? (this: T, ...args: A) => R : T[K];
20
21
  } & Record<string, unknown>;
21
22
  /** Export/Import compatible value for a given property in a Model. */
22
23
  type Export<R> = R extends {
package/dist/index.js CHANGED
@@ -174,19 +174,23 @@ var Model = class _Model {
174
174
  Type = Object.getPrototypeOf(Type);
175
175
  }
176
176
  addListener(this, () => {
177
- const cleanup = /* @__PURE__ */ new Set();
178
- for (const arg of args) {
179
- const use2 = typeof arg == "function" ? arg.call(this, this) : arg;
180
- if (use2 instanceof Promise)
181
- use2.catch((err) => {
182
- console.error(`Async error in constructor for ${this}:`);
183
- console.error(err);
184
- });
185
- else if (typeof use2 == "object")
186
- assign(this, use2);
187
- else if (typeof use2 == "function")
188
- cleanup.add(use2);
189
- }
177
+ let done;
178
+ (async () => {
179
+ const cleanup = /* @__PURE__ */ new Set();
180
+ for (const arg of args) {
181
+ let use2 = typeof arg == "function" ? arg.call(this, this) : arg;
182
+ if (use2 instanceof Promise)
183
+ use2 = await use2.catch((err) => {
184
+ console.error(`Async error in constructor for ${this}:`);
185
+ console.error(err);
186
+ });
187
+ if (typeof use2 == "object")
188
+ assign(this, use2);
189
+ else if (typeof use2 == "function")
190
+ cleanup.add(use2);
191
+ }
192
+ done = cleanup;
193
+ })();
190
194
  for (const key in this) {
191
195
  const desc = Object.getOwnPropertyDescriptor(this, key);
192
196
  if ("value" in desc) {
@@ -201,10 +205,12 @@ var Model = class _Model {
201
205
  }
202
206
  }
203
207
  addListener(this, () => {
208
+ if (!done)
209
+ throw new Error(`Tried to destroy ${this} but not fully initialized.`);
204
210
  for (const [_, value] of this)
205
211
  if (value instanceof _Model && PARENT.get(value) === this)
206
212
  value.set(null);
207
- cleanup.forEach((x) => x());
213
+ done.forEach((x) => x());
208
214
  Object.freeze(state);
209
215
  }, null);
210
216
  return null;
package/dist/index.mjs CHANGED
@@ -140,19 +140,23 @@ var Model = class _Model {
140
140
  Type = Object.getPrototypeOf(Type);
141
141
  }
142
142
  addListener(this, () => {
143
- const cleanup = /* @__PURE__ */ new Set();
144
- for (const arg of args) {
145
- const use2 = typeof arg == "function" ? arg.call(this, this) : arg;
146
- if (use2 instanceof Promise)
147
- use2.catch((err) => {
148
- console.error(`Async error in constructor for ${this}:`);
149
- console.error(err);
150
- });
151
- else if (typeof use2 == "object")
152
- assign(this, use2);
153
- else if (typeof use2 == "function")
154
- cleanup.add(use2);
155
- }
143
+ let done;
144
+ (async () => {
145
+ const cleanup = /* @__PURE__ */ new Set();
146
+ for (const arg of args) {
147
+ let use2 = typeof arg == "function" ? arg.call(this, this) : arg;
148
+ if (use2 instanceof Promise)
149
+ use2 = await use2.catch((err) => {
150
+ console.error(`Async error in constructor for ${this}:`);
151
+ console.error(err);
152
+ });
153
+ if (typeof use2 == "object")
154
+ assign(this, use2);
155
+ else if (typeof use2 == "function")
156
+ cleanup.add(use2);
157
+ }
158
+ done = cleanup;
159
+ })();
156
160
  for (const key in this) {
157
161
  const desc = Object.getOwnPropertyDescriptor(this, key);
158
162
  if ("value" in desc) {
@@ -167,10 +171,12 @@ var Model = class _Model {
167
171
  }
168
172
  }
169
173
  addListener(this, () => {
174
+ if (!done)
175
+ throw new Error(`Tried to destroy ${this} but not fully initialized.`);
170
176
  for (const [_, value] of this)
171
177
  if (value instanceof _Model && PARENT.get(value) === this)
172
178
  value.set(null);
173
- cleanup.forEach((x) => x());
179
+ done.forEach((x) => x());
174
180
  Object.freeze(state);
175
181
  }, null);
176
182
  return null;
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.44.0",
32
- "gitHead": "b9a450ae7d25a8845d344faed39495bbdfc69b47"
31
+ "version": "0.45.0",
32
+ "gitHead": "011596452831f785cc685c9124adff02176b489f"
33
33
  }