@expressive/mvc 1.0.0-beta.39 → 1.0.0-beta.41

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
@@ -442,11 +442,19 @@ declare class MVC extends Model {
442
442
  *
443
443
  * @param callback - Run after creation of instance.
444
444
  */
445
- static new<T extends Class>(this: T, callback?: (instance: InstanceOf<T>) => void): InstanceOf<T>;
445
+ static new<T extends Class, I extends InstanceOf<T>>(this: T, callback?: (instance: I) => void): I;
446
+ static new<T extends Class, I extends InstanceOf<T>>(this: T, apply: Model.Compat<I>): I;
446
447
  static use<T extends Class, I extends InstanceOf<T>>(this: T, watch: Model.Field<I>[], callback?: (instance: I) => void): I;
447
448
  static use<T extends Class, I extends InstanceOf<T>>(this: T, callback?: (instance: I) => void): I;
448
- static uses<T extends typeof MVC, I extends InstanceOf<T>, D extends Partial<I>>(this: T, data: D, only?: (keyof D & string)[]): InstanceOf<T>;
449
- static using<T extends typeof MVC, I extends InstanceOf<T>, D extends Partial<I>>(this: T, data: D, only?: (keyof D & string)[]): InstanceOf<T>;
449
+ static use<T extends Class, I extends InstanceOf<T>>(this: T, apply: Model.Compat<I>, keys?: Model.Event<I>[]): I;
450
+ /**
451
+ * @deprecated consider doing this manually - not worth minor efficiency gain over using.
452
+ */
453
+ static uses<T extends typeof MVC, I extends InstanceOf<T>, D extends Model.Compat<I>>(this: T, apply: D, keys?: (keyof D)[]): InstanceOf<T>;
454
+ /**
455
+ * @deprecated is now replaced by overload of `use` method.
456
+ */
457
+ static using<T extends typeof MVC, I extends InstanceOf<T>>(this: T, apply: Model.Compat<I>, keys?: Model.Event<I>[]): I;
450
458
  static meta<T extends Class>(this: T): T;
451
459
  static meta<T extends Class, K extends keyof T>(this: T, key: K, expect: true): Exclude<T[K], undefined>;
452
460
  static meta<T extends Class, K extends keyof T>(this: T, key: K, expect?: boolean): T[K];
package/lib/index.esm.js CHANGED
@@ -1120,30 +1120,38 @@ class MVC extends Model {
1120
1120
  static tap(key, expect) {
1121
1121
  return useTap(this, key, expect);
1122
1122
  }
1123
- /**
1124
- * **React Hook** - Spawn and maintain a controller from within a component.
1125
- *
1126
- * More efficient than `use()` if you don't need hook-based features.
1127
- *
1128
- * @param callback - Run after creation of instance.
1129
- */
1130
- static new(callback) {
1131
- return useModel(this, [], callback);
1123
+ static new(arg) {
1124
+ return React.useMemo(() => {
1125
+ const instance = new this();
1126
+ control(instance);
1127
+ if (typeof arg == "function")
1128
+ arg(instance);
1129
+ else if (arg)
1130
+ getOwnPropertyNames(instance).forEach(key => {
1131
+ if (key in arg)
1132
+ instance[key] = arg[key];
1133
+ });
1134
+ return instance;
1135
+ }, []);
1132
1136
  }
1133
- static use(arg, callback) {
1134
- const instance = useModel(this, arg, callback);
1137
+ static use(a, b) {
1138
+ const instance = useModel(this, a, b);
1135
1139
  usePeerContext(instance.get);
1136
1140
  return instance;
1137
1141
  }
1138
- static uses(data, only) {
1142
+ /**
1143
+ * @deprecated consider doing this manually - not worth minor efficiency gain over using.
1144
+ */
1145
+ static uses(apply, keys) {
1139
1146
  return this.use(instance => {
1140
- instance.import(data, only);
1147
+ instance.import(apply, keys);
1141
1148
  });
1142
1149
  }
1143
- static using(data, only) {
1144
- const instance = this.use();
1145
- instance.import(data, only);
1146
- return instance;
1150
+ /**
1151
+ * @deprecated is now replaced by overload of `use` method.
1152
+ */
1153
+ static using(apply, keys) {
1154
+ return this.use(apply, keys);
1147
1155
  }
1148
1156
  static meta(path, expect) {
1149
1157
  return useTap(() => this, path, expect);