@expressive/mvc 1.0.0-beta.40 → 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,7 +442,8 @@ 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
449
  static use<T extends Class, I extends InstanceOf<T>>(this: T, apply: Model.Compat<I>, keys?: Model.Event<I>[]): I;
package/lib/index.esm.js CHANGED
@@ -1120,15 +1120,19 @@ 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
1137
  static use(a, b) {
1134
1138
  const instance = useModel(this, a, b);