@amodx/schemas 0.0.1 → 0.0.2

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.
@@ -1,4 +1,5 @@
1
1
  import { Property } from "../Properties/Property";
2
+ import { PropertyInputBase } from "../Inputs/PropertyInput";
2
3
  import { PropertyInputRegister } from "../Inputs/PropertyInputRegister";
3
4
  import { Observable } from "@amodx/core/Observers/index";
4
5
  import { Pipeline } from "@amodx/core/Pipelines";
@@ -13,6 +14,7 @@ export class TemplateNode {
13
14
  class SchemaNodeObservers {
14
15
  stateUpdated = new Observable();
15
16
  updated = new Observable();
17
+ set = new Observable();
16
18
  loadedIn = new Observable();
17
19
  updatedOrLoadedIn = new Observable();
18
20
  evaluate = new Observable();
@@ -34,6 +36,8 @@ class SchemaNodeProxy {
34
36
  export class SchemaNode {
35
37
  property;
36
38
  root;
39
+ _updateData;
40
+ _loadInData;
37
41
  children = null;
38
42
  conditions = [];
39
43
  input;
@@ -43,9 +47,17 @@ export class SchemaNode {
43
47
  constructor(property, root) {
44
48
  this.property = property;
45
49
  this.root = root;
50
+ this._updateData = {
51
+ node: this,
52
+ newValue: this.getValue(),
53
+ };
54
+ this._loadInData = {
55
+ node: this,
56
+ value: this.getValue(),
57
+ };
46
58
  if (property.input) {
47
- const inputClass = PropertyInputRegister.getProperty(property.input.type);
48
- this.input = new inputClass(property.input, this);
59
+ const abstractInput = PropertyInputRegister.getProperty(property.input.type);
60
+ this.input = new PropertyInputBase(abstractInput, property.input, this);
49
61
  }
50
62
  }
51
63
  proxy = null;
@@ -81,8 +93,8 @@ export class SchemaNode {
81
93
  this.conditions.push(action);
82
94
  }
83
95
  }
84
- if (property.input?.validator) {
85
- const validator = ObjectPropertyValidatorRegister.getValidator(property.input.validator);
96
+ if (property.input?.properties.validator) {
97
+ const validator = ObjectPropertyValidatorRegister.getValidator(property.input.properties.validator);
86
98
  this.observers.updatedOrLoadedIn.subscribe(this, () => {
87
99
  const response = validator.validate(this.get(), this);
88
100
  this.validatorResponse = response;
@@ -128,10 +140,8 @@ export class SchemaNode {
128
140
  return this.pipelines.onStore.pipe(Property.Create(this.property)).value;
129
141
  }
130
142
  loadIn(value) {
131
- this.setValue(this.pipelines.loadedIn.pipe({
132
- node: this,
133
- value,
134
- }).value);
143
+ this._loadInData.value = value;
144
+ this.setValue(this.pipelines.loadedIn.pipe(this._loadInData).value);
135
145
  this.observers.loadedIn.notify(this);
136
146
  this.observers.updatedOrLoadedIn.notify(this);
137
147
  }
@@ -140,19 +150,18 @@ export class SchemaNode {
140
150
  }
141
151
  update(newValue) {
142
152
  const oldValue = this.getValue();
143
- this.setValue(this.pipelines.updated.pipe({
144
- node: this,
145
- newValue,
146
- }).newValue);
147
- const newFinalValue = this.getValue();
153
+ this._updateData.newValue = newValue;
154
+ const finalNewValue = this.pipelines.updated.pipe(this._updateData).newValue;
155
+ this.setValue(finalNewValue);
156
+ this.observers.set.notify(this);
148
157
  if (this.input) {
149
- if (!this.input.compare(oldValue, newFinalValue)) {
158
+ if (!this.input.compare(oldValue, finalNewValue)) {
150
159
  this.observers.updated.notify(this);
151
160
  this.observers.updatedOrLoadedIn.notify(this);
152
161
  }
153
162
  return;
154
163
  }
155
- if (oldValue != newFinalValue) {
164
+ if (oldValue != finalNewValue) {
156
165
  this.observers.updated.notify(this);
157
166
  this.observers.updatedOrLoadedIn.notify(this);
158
167
  }
package/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from "./Schemas/ObjectSchema";
6
6
  export * from "./Schemas/BinaryObjectSchema";
7
7
  export * from "./Schemas/ObjectSchemaInstance";
8
8
  export * from "./Properties/ObjectPath";
9
+ export * from "./Schemas/SchemaNode";
package/index.js CHANGED
@@ -6,3 +6,4 @@ export * from "./Schemas/ObjectSchema";
6
6
  export * from "./Schemas/BinaryObjectSchema";
7
7
  export * from "./Schemas/ObjectSchemaInstance";
8
8
  export * from "./Properties/ObjectPath";
9
+ export * from "./Schemas/SchemaNode";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amodx/schemas",
3
- "version": "0.0.01",
3
+ "version": "0.0.02",
4
4
  "module": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",