@gi-tcg/gts-runtime 0.6.2 → 0.6.4

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
@@ -87,6 +87,7 @@ interface IViewModel<ModelT, BlockDef extends AttributeBlockDefinition, CtorArgs
87
87
  "~namedDefinition": BlockDef;
88
88
  }
89
89
  type LazyAttributeActionOrBinder<ModelT> = (model: ModelT, positionals: () => unknown[], named: View<any>) => unknown;
90
+ declare function getCurrentContext(): "action" | "binder" | null;
90
91
  declare class ViewModel<ModelT, BlockDef extends AttributeBlockDefinition, CtorArgs extends any[]> implements IViewModel<ModelT, BlockDef, CtorArgs> {
91
92
  #private;
92
93
  "~namedDefinition": BlockDef;
@@ -272,4 +273,4 @@ interface SimpleViewModel<T, Options extends SimpleViewModelOptions = {}> extend
272
273
  }
273
274
  declare function defineSimpleViewModel<const T extends StandardJSONSchemaV1, const Options extends SimpleViewModelOptions = {}>(schema: T, options?: Options): SimpleViewModel<StandardJSONSchemaV1.InferInput<T>, Options>;
274
275
  //#endregion
275
- export { type AttributeReturn as AR, type AttributeReturn, type Action, type AttributeBlockDefinition, type AttributeDefinition, type IViewModel, type Meta, type NamedAttributesNode, type NamedDefinition, type SimpleAttributeOptions, type SimpleViewModel, type SimpleViewModelOptions, type SingleAttributeNode, type View, createBinding, createDefine, defineSimpleViewModel, defineViewModel };
276
+ export { type AttributeReturn as AR, type AttributeReturn, type Action, type AttributeBlockDefinition, type AttributeDefinition, type IViewModel, type Meta, type NamedAttributesNode, type NamedDefinition, type SimpleAttributeOptions, type SimpleViewModel, type SimpleViewModelOptions, type SingleAttributeNode, type View, createBinding, createDefine, defineSimpleViewModel, defineViewModel, getCurrentContext };
package/dist/index.js CHANGED
@@ -30,6 +30,10 @@ function createBinding(rootVM, node) {
30
30
  }
31
31
  //#endregion
32
32
  //#region src/view_model.ts
33
+ let currentContext = null;
34
+ function getCurrentContext() {
35
+ return currentContext;
36
+ }
33
37
  var ViewModel = class ViewModel {
34
38
  #registeredActions = /* @__PURE__ */ new Map();
35
39
  #registeredBinders = /* @__PURE__ */ new Map();
@@ -42,6 +46,7 @@ var ViewModel = class ViewModel {
42
46
  else this.#registeredBinders.set(name, action);
43
47
  }
44
48
  parse(view, ...args) {
49
+ currentContext = view._bindingCtx ? "binder" : "action";
45
50
  const model = new this.#Ctor(...args);
46
51
  for (const attrNode of view._node.attributes) {
47
52
  let { name, positionals, named, binding } = attrNode;
@@ -56,6 +61,7 @@ var ViewModel = class ViewModel {
56
61
  const value = fn(model, positionals, new View(named, view._bindingCtx));
57
62
  if (binding && view._bindingCtx) view._bindingCtx.addBinding(value);
58
63
  }
64
+ currentContext = null;
59
65
  return model;
60
66
  }
61
67
  #clone() {
@@ -202,4 +208,4 @@ function defineSimpleViewModel(schema, options) {
202
208
  return createSimpleViewModelFromJsonSchema(schema["~standard"].jsonSchema.input({ target: "draft-2020-12" }), resolvedOptions);
203
209
  }
204
210
  //#endregion
205
- export { createBinding, createDefine, defineSimpleViewModel, defineViewModel };
211
+ export { createBinding, createDefine, defineSimpleViewModel, defineViewModel, getCurrentContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gi-tcg/gts-runtime",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/piovium/gts.git"
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export {
2
2
  defineViewModel,
3
+ getCurrentContext,
3
4
  type AttributeDefinition,
4
5
  type IViewModel,
5
6
  type SimpleAttributeOptions,
package/src/view_model.ts CHANGED
@@ -69,6 +69,11 @@ type LazyAttributeActionOrBinder<ModelT> = (
69
69
  named: View<any>,
70
70
  ) => unknown;
71
71
 
72
+ let currentContext: "action" | "binder" | null = null;
73
+ export function getCurrentContext(): "action" | "binder" | null {
74
+ return currentContext;
75
+ }
76
+
72
77
  export class ViewModel<
73
78
  ModelT,
74
79
  BlockDef extends AttributeBlockDefinition,
@@ -103,6 +108,7 @@ export class ViewModel<
103
108
  view: View<BlockDefinitionRewriteMeta<BlockDef, unknown>>,
104
109
  ...args: CtorArgs
105
110
  ): ModelT {
111
+ currentContext = view._bindingCtx ? "binder" : "action";
106
112
  const model = new this.#Ctor(...args);
107
113
  for (const attrNode of view._node.attributes) {
108
114
  let { name, positionals, named, binding } = attrNode;
@@ -123,6 +129,7 @@ export class ViewModel<
123
129
  view._bindingCtx.addBinding(value);
124
130
  }
125
131
  }
132
+ currentContext = null;
126
133
  return model;
127
134
  }
128
135