@gi-tcg/gts-runtime 0.3.11 → 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 +10 -5
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/view_model.ts +31 -10
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
|
|
143
|
-
* that accepts the specified arguments
|
|
144
|
-
*
|
|
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(
|
|
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(
|
|
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
package/package.json
CHANGED
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
|
|
35
|
-
* that accepts the specified arguments
|
|
36
|
-
*
|
|
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(
|
|
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
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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 {
|