@gi-tcg/gts-runtime 0.4.0 → 0.4.1

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
@@ -139,11 +139,15 @@ type BlockDefinitionRewriteMeta<BlockDef extends AttributeBlockDefinition, NewMe
139
139
  interface IViewModel<ModelT, BlockDef extends AttributeBlockDefinition, CtorArgs extends any[]> {
140
140
  parse(view: View<BlockDefinitionRewriteMeta<BlockDef, unknown>>, ...args: CtorArgs): ModelT;
141
141
  /**
142
- * Creates a new ViewModel with the same actions and binders, but with a different constructor
143
- * that accepts the specified arguments. This is useful for creating binding ViewModels directly
144
- * that forwards the binding logic to inner ViewModels.
142
+ * Creates a new ViewModel with the same actions and binders, but with
143
+ * - a different constructor that accepts the specified arguments, and/or
144
+ * - a different initial Meta.
145
+ *
146
+ * This is useful for creating binding ViewModels directly that forwards
147
+ * the binding logic to inner ViewModels.
145
148
  */
146
- bind(...args: CtorArgs): ViewModel<ModelT, BlockDef, []>;
149
+ bind<NewMeta = BlockDef[Meta]>(): ViewModel<ModelT, BlockDefinitionRewriteMeta<BlockDef, NewMeta>, CtorArgs>;
150
+ bind<NewMeta = BlockDef[Meta]>(...args: CtorArgs): ViewModel<ModelT, BlockDefinitionRewriteMeta<BlockDef, NewMeta>, []>;
147
151
  "~namedDefinition": BlockDef;
148
152
  }
149
153
  type LazyAttributeActionOrBinder<ModelT> = (model: ModelT, positionals: () => unknown[], named: View<any>) => unknown;
@@ -153,7 +157,8 @@ declare class ViewModel<ModelT, BlockDef extends AttributeBlockDefinition, CtorA
153
157
  constructor(Ctor: new (...args: CtorArgs) => ModelT);
154
158
  "~setActionOrBinder"(context: "action" | "binder", name: PropertyKey, action: LazyAttributeActionOrBinder<ModelT>): void;
155
159
  parse(view: View<BlockDefinitionRewriteMeta<BlockDef, unknown>>, ...args: CtorArgs): ModelT;
156
- bind(...args: CtorArgs): ViewModel<ModelT, BlockDef, []>;
160
+ bind<NewMeta = BlockDef[Meta]>(): ViewModel<ModelT, BlockDefinitionRewriteMeta<BlockDef, NewMeta>, CtorArgs>;
161
+ bind<NewMeta = BlockDef[Meta]>(...args: CtorArgs): ViewModel<ModelT, BlockDefinitionRewriteMeta<BlockDef, NewMeta>, []>;
157
162
  }
158
163
  interface SimpleAttributeOptions {
159
164
  required?: true;
package/dist/index.js CHANGED
@@ -64,6 +64,7 @@ var ViewModel = class ViewModel {
64
64
  return newVM;
65
65
  }
66
66
  bind(...args) {
67
+ if (args.length === 0) return this;
67
68
  const newModel = this.#clone();
68
69
  newModel.#Ctor = class extends this.#Ctor {
69
70
  constructor() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gi-tcg/gts-runtime",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/piovium/gts.git"
package/src/view_model.ts CHANGED
@@ -31,11 +31,21 @@ export interface IViewModel<
31
31
  ...args: CtorArgs
32
32
  ): ModelT;
33
33
  /**
34
- * Creates a new ViewModel with the same actions and binders, but with a different constructor
35
- * that accepts the specified arguments. This is useful for creating binding ViewModels directly
36
- * that forwards the binding logic to inner ViewModels.
34
+ * Creates a new ViewModel with the same actions and binders, but with
35
+ * - a different constructor that accepts the specified arguments, and/or
36
+ * - a different initial Meta.
37
+ *
38
+ * This is useful for creating binding ViewModels directly that forwards
39
+ * the binding logic to inner ViewModels.
37
40
  */
38
- bind(...args: CtorArgs): ViewModel<ModelT, BlockDef, []>;
41
+ bind<NewMeta = BlockDef[Meta]>(): ViewModel<
42
+ ModelT,
43
+ BlockDefinitionRewriteMeta<BlockDef, NewMeta>,
44
+ CtorArgs
45
+ >;
46
+ bind<NewMeta = BlockDef[Meta]>(
47
+ ...args: CtorArgs
48
+ ): ViewModel<ModelT, BlockDefinitionRewriteMeta<BlockDef, NewMeta>, []>;
39
49
  "~namedDefinition": BlockDef;
40
50
  }
41
51
 
@@ -109,11 +119,22 @@ class ViewModel<
109
119
  return newVM;
110
120
  }
111
121
 
112
- bind(...args: CtorArgs): ViewModel<ModelT, BlockDef, []> {
113
- const newModel = this.#clone() as ViewModel<any, BlockDef, any>;
114
- newModel.#Ctor = class extends (
115
- (this.#Ctor as new (...args: CtorArgs) => any)
116
- ) {
122
+ bind<NewMeta = BlockDef[Meta]>(): ViewModel<
123
+ ModelT,
124
+ BlockDefinitionRewriteMeta<BlockDef, NewMeta>,
125
+ CtorArgs
126
+ >;
127
+ bind<NewMeta = BlockDef[Meta]>(
128
+ ...args: CtorArgs
129
+ ): ViewModel<ModelT, BlockDefinitionRewriteMeta<BlockDef, NewMeta>, []>;
130
+ bind<NewMeta = BlockDef[Meta]>(
131
+ ...args: any[]
132
+ ): ViewModel<ModelT, BlockDefinitionRewriteMeta<BlockDef, NewMeta>, any> {
133
+ if (args.length === 0) {
134
+ return this as any;
135
+ }
136
+ const newModel = this.#clone() as ViewModel<any, any, any>;
137
+ newModel.#Ctor = class extends (this.#Ctor as new (...args: any[]) => any) {
117
138
  constructor() {
118
139
  super(...args);
119
140
  }
@@ -303,7 +324,7 @@ export function defineSimpleViewModel<const T extends StandardJSONSchemaV1>(
303
324
  });
304
325
  }
305
326
  helper["~assignActions"](defResult);
306
- return vm;
327
+ return vm as any;
307
328
  }
308
329
 
309
330
  export interface AttributeDefinition {