@expressive/mvc 0.21.8 → 0.23.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/lib/index.d.ts CHANGED
@@ -77,12 +77,12 @@ declare namespace Control {
77
77
  render: () => T;
78
78
  } | void;
79
79
  type GetHook = <T>(adapter: GetAdapter<T>) => T | null;
80
- type UseAdapter<T extends Model> = (refresh: RequestRefresh) => {
81
- instance: T;
80
+ type UseAdapter<T extends Model, R> = (refresh: RequestRefresh) => {
81
+ local: T;
82
82
  mount: () => (() => void) | void;
83
- render: (props: Model.Compat<T>) => T;
83
+ render: R;
84
84
  };
85
- type UseHook = <T extends Model>(adapter: UseAdapter<T>) => (props: Model.Compat<T>) => T;
85
+ type UseHook = <T extends Model, R>(adapter: UseAdapter<T, R>) => R;
86
86
  }
87
87
  declare class Control<T extends Model = any> {
88
88
  subject: T;
@@ -171,7 +171,7 @@ declare function get$1<T extends Model, R>(this: Model.Type<T>, compute: Model.G
171
171
  declare function get$1<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, Promise<R>>, expect?: boolean): NoVoid<R> | null;
172
172
  declare function get$1<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, R>, expect?: boolean): NoVoid<R>;
173
173
 
174
- declare function use$1<T extends Model>(this: Model.New<T>, callback?: (instance: T) => void): T;
174
+ declare function use$1<T extends Model>(this: Model.New<T>, callback?: (instance: T) => void, repeat?: boolean): T;
175
175
  declare function use$1<T extends Model>(this: Model.New<T>, apply?: Model.Compat<T>, repeat?: boolean): T;
176
176
 
177
177
  type InstanceOf<T> = T extends {
package/lib/index.esm.js CHANGED
@@ -296,14 +296,12 @@ const notEqual = (a, b) => (b !== a && (!Array.isArray(a) ||
296
296
  function use$1(arg1, arg2) {
297
297
  const render = Control.use(dispatch => {
298
298
  const instance = this.new();
299
- const proxy = Control.watch(instance, () => onUpdate);
299
+ const local = Control.watch(instance, () => onUpdate);
300
300
  const refresh = () => dispatch(x => x + 1);
301
301
  let onUpdate;
302
- let applyProps = typeof arg1 === "object";
303
- if (typeof arg1 == "function")
304
- arg1(instance);
302
+ let apply = !!arg1;
305
303
  return {
306
- instance,
304
+ local,
307
305
  mount() {
308
306
  onUpdate = refresh;
309
307
  return () => {
@@ -312,15 +310,19 @@ function use$1(arg1, arg2) {
312
310
  };
313
311
  },
314
312
  render(props) {
315
- if (applyProps) {
313
+ if (apply) {
316
314
  onUpdate = undefined;
317
- applyProps = !!arg2;
318
- for (const key in props)
319
- if (instance.hasOwnProperty(key))
320
- instance[key] = props[key];
315
+ if (typeof props == "function")
316
+ props(instance);
317
+ else if (props)
318
+ for (const key in instance)
319
+ if (props.hasOwnProperty(key))
320
+ instance[key] = props[key];
321
+ if (!arg2)
322
+ apply = false;
321
323
  instance.on(0).then(() => onUpdate = refresh);
322
324
  }
323
- return proxy;
325
+ return local;
324
326
  }
325
327
  };
326
328
  });
@@ -446,12 +448,12 @@ class Control {
446
448
  }
447
449
  else if (value instanceof Model)
448
450
  setRecursive(this, key, value);
449
- else if (typeof value != "function")
451
+ else
450
452
  this.watch(key, { value });
451
453
  }
452
454
  watch(key, output) {
453
455
  const { state } = this;
454
- const { get, set, enumerable } = output;
456
+ const { get, set, enumerable = true } = output;
455
457
  const subs = new Set();
456
458
  this.observers.set(key, subs);
457
459
  if ("value" in output)
package/lib/index.js CHANGED
@@ -300,14 +300,12 @@ const notEqual = (a, b) => (b !== a && (!Array.isArray(a) ||
300
300
  function use$1(arg1, arg2) {
301
301
  const render = Control.use(dispatch => {
302
302
  const instance = this.new();
303
- const proxy = Control.watch(instance, () => onUpdate);
303
+ const local = Control.watch(instance, () => onUpdate);
304
304
  const refresh = () => dispatch(x => x + 1);
305
305
  let onUpdate;
306
- let applyProps = typeof arg1 === "object";
307
- if (typeof arg1 == "function")
308
- arg1(instance);
306
+ let apply = !!arg1;
309
307
  return {
310
- instance,
308
+ local,
311
309
  mount() {
312
310
  onUpdate = refresh;
313
311
  return () => {
@@ -316,15 +314,19 @@ function use$1(arg1, arg2) {
316
314
  };
317
315
  },
318
316
  render(props) {
319
- if (applyProps) {
317
+ if (apply) {
320
318
  onUpdate = undefined;
321
- applyProps = !!arg2;
322
- for (const key in props)
323
- if (instance.hasOwnProperty(key))
324
- instance[key] = props[key];
319
+ if (typeof props == "function")
320
+ props(instance);
321
+ else if (props)
322
+ for (const key in instance)
323
+ if (props.hasOwnProperty(key))
324
+ instance[key] = props[key];
325
+ if (!arg2)
326
+ apply = false;
325
327
  instance.on(0).then(() => onUpdate = refresh);
326
328
  }
327
- return proxy;
329
+ return local;
328
330
  }
329
331
  };
330
332
  });
@@ -450,12 +452,12 @@ class Control {
450
452
  }
451
453
  else if (value instanceof Model)
452
454
  setRecursive(this, key, value);
453
- else if (typeof value != "function")
455
+ else
454
456
  this.watch(key, { value });
455
457
  }
456
458
  watch(key, output) {
457
459
  const { state } = this;
458
- const { get, set, enumerable } = output;
460
+ const { get, set, enumerable = true } = output;
459
461
  const subs = new Set();
460
462
  this.observers.set(key, subs);
461
463
  if ("value" in output)
package/package.json CHANGED
@@ -27,5 +27,5 @@
27
27
  "preversion": "npm run test && npm run build",
28
28
  "postversion": "git push & npm publish"
29
29
  },
30
- "version": "0.21.8"
30
+ "version": "0.23.0"
31
31
  }