-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathDataManager.js
More file actions
63 lines (63 loc) · 1.9 KB
/
DataManager.js
File metadata and controls
63 lines (63 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
export default {
methods: {
dataFields(screen, definition) {
const localVariables = this.variables.filter(
(v) => !this.isComputedVariable(v.name, definition)
);
localVariables.forEach((v) => {
const { component } = v.element;
const dataFormat = v.config.dataFormat || null;
const safeDotName = this.safeDotName(v.name);
// For checkboxes, use explicit undefined checks to preserve false values
const isCheckbox = component === "FormCheckbox";
const vdataCheck = isCheckbox ? "vdataVal !== undefined" : "vdataVal";
const dataCheck = isCheckbox ? "dataVal !== undefined" : "dataVal";
this.addData(
screen,
safeDotName,
`
(() => {
const vdataVal = this.getValue(${JSON.stringify(
v.name
)}, this.vdata);
if (${vdataCheck}) return vdataVal;
const dataVal = this.getValue(${JSON.stringify(v.name)}, data);
if (${dataCheck}) return dataVal;
return this.initialValue('${component}', '${dataFormat}', ${JSON.stringify(
v.config
)});
})()
`,
v.name
);
this.addWatch(
screen,
`vdata.${v.name}`,
`if (this.canUpdate("${safeDotName}")) {
this.${safeDotName} = value;
}`
);
});
this.addProp(screen, "vdata", null);
},
/**
* Replace `.` by `_DOT_` in a variable name
* @param {string} name
* @returns {string}
*/
safeDotName(name) {
// if starts with _parent returns as is
if (name.startsWith("_parent")) {
return name;
}
return name.replace(/\./g, "_DOT_");
}
},
mounted() {
this.extensions.push({
onbuild({ screen, definition }) {
this.dataFields(screen, definition);
}
});
}
};