@gi-tcg/gts-runtime 0.3.10 → 0.4.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/dist/index.d.ts +7 -0
- package/dist/index.js +16 -1
- package/package.json +1 -1
- package/src/view_model.ts +25 -0
package/dist/index.d.ts
CHANGED
|
@@ -138,6 +138,12 @@ type BlockDefinitionRewriteMeta<BlockDef extends AttributeBlockDefinition, NewMe
|
|
|
138
138
|
}> extends infer R extends AttributeBlockDefinition ? R : never;
|
|
139
139
|
interface IViewModel<ModelT, BlockDef extends AttributeBlockDefinition, CtorArgs extends any[]> {
|
|
140
140
|
parse(view: View<BlockDefinitionRewriteMeta<BlockDef, unknown>>, ...args: CtorArgs): ModelT;
|
|
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.
|
|
145
|
+
*/
|
|
146
|
+
bind(...args: CtorArgs): ViewModel<ModelT, BlockDef, []>;
|
|
141
147
|
"~namedDefinition": BlockDef;
|
|
142
148
|
}
|
|
143
149
|
type LazyAttributeActionOrBinder<ModelT> = (model: ModelT, positionals: () => unknown[], named: View<any>) => unknown;
|
|
@@ -147,6 +153,7 @@ declare class ViewModel<ModelT, BlockDef extends AttributeBlockDefinition, CtorA
|
|
|
147
153
|
constructor(Ctor: new (...args: CtorArgs) => ModelT);
|
|
148
154
|
"~setActionOrBinder"(context: "action" | "binder", name: PropertyKey, action: LazyAttributeActionOrBinder<ModelT>): void;
|
|
149
155
|
parse(view: View<BlockDefinitionRewriteMeta<BlockDef, unknown>>, ...args: CtorArgs): ModelT;
|
|
156
|
+
bind(...args: CtorArgs): ViewModel<ModelT, BlockDef, []>;
|
|
150
157
|
}
|
|
151
158
|
interface SimpleAttributeOptions {
|
|
152
159
|
required?: true;
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ function createBinding(rootVM, node) {
|
|
|
29
29
|
}
|
|
30
30
|
//#endregion
|
|
31
31
|
//#region src/view_model.ts
|
|
32
|
-
var ViewModel = class {
|
|
32
|
+
var ViewModel = class ViewModel {
|
|
33
33
|
#registeredActions = /* @__PURE__ */ new Map();
|
|
34
34
|
#registeredBinders = /* @__PURE__ */ new Map();
|
|
35
35
|
#Ctor;
|
|
@@ -57,6 +57,21 @@ var ViewModel = class {
|
|
|
57
57
|
}
|
|
58
58
|
return model;
|
|
59
59
|
}
|
|
60
|
+
#clone() {
|
|
61
|
+
const newVM = new ViewModel(this.#Ctor);
|
|
62
|
+
newVM.#registeredActions = new Map(this.#registeredActions);
|
|
63
|
+
newVM.#registeredBinders = new Map(this.#registeredBinders);
|
|
64
|
+
return newVM;
|
|
65
|
+
}
|
|
66
|
+
bind(...args) {
|
|
67
|
+
const newModel = this.#clone();
|
|
68
|
+
newModel.#Ctor = class extends this.#Ctor {
|
|
69
|
+
constructor() {
|
|
70
|
+
super(...args);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return newModel;
|
|
74
|
+
}
|
|
60
75
|
};
|
|
61
76
|
var AttributeDefHelper = class AttributeDefHelper {
|
|
62
77
|
#viewModel;
|
package/package.json
CHANGED
package/src/view_model.ts
CHANGED
|
@@ -30,6 +30,12 @@ export interface IViewModel<
|
|
|
30
30
|
view: View<BlockDefinitionRewriteMeta<BlockDef, unknown>>,
|
|
31
31
|
...args: CtorArgs
|
|
32
32
|
): ModelT;
|
|
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.
|
|
37
|
+
*/
|
|
38
|
+
bind(...args: CtorArgs): ViewModel<ModelT, BlockDef, []>;
|
|
33
39
|
"~namedDefinition": BlockDef;
|
|
34
40
|
}
|
|
35
41
|
|
|
@@ -95,6 +101,25 @@ class ViewModel<
|
|
|
95
101
|
}
|
|
96
102
|
return model;
|
|
97
103
|
}
|
|
104
|
+
|
|
105
|
+
#clone() {
|
|
106
|
+
const newVM = new ViewModel(this.#Ctor);
|
|
107
|
+
newVM.#registeredActions = new Map(this.#registeredActions);
|
|
108
|
+
newVM.#registeredBinders = new Map(this.#registeredBinders);
|
|
109
|
+
return newVM;
|
|
110
|
+
}
|
|
111
|
+
|
|
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
|
+
) {
|
|
117
|
+
constructor() {
|
|
118
|
+
super(...args);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
return newModel;
|
|
122
|
+
}
|
|
98
123
|
}
|
|
99
124
|
|
|
100
125
|
interface SimpleAttributeOptions {
|