|
@@ -1,73 +1,69 @@
|
|
|
-export interface VariableModuleData {
|
|
|
- [key: string]: VariableName;
|
|
|
-}
|
|
|
+export type ModuleData = Record<string, VarName>;
|
|
|
|
|
|
-interface VariableName {
|
|
|
- [key: string]: VariableData;
|
|
|
-}
|
|
|
+export type VarName = Record<string, VarData>;
|
|
|
|
|
|
-interface VariableData {
|
|
|
+interface VarData {
|
|
|
type: string;
|
|
|
value: unknown;
|
|
|
encoded_name: string;
|
|
|
}
|
|
|
|
|
|
// This class hold the information of variables and real-time value of variables
|
|
|
-export class VariableManager {
|
|
|
+export class DataManager {
|
|
|
// key: encoded name, value: real-time value
|
|
|
_data: Record<string, unknown>;
|
|
|
// Initial data fetched from taipy-gui backend
|
|
|
- _variables: VariableModuleData;
|
|
|
+ _init_data: ModuleData;
|
|
|
|
|
|
- constructor(variableModuleData: VariableModuleData) {
|
|
|
+ constructor(variableModuleData: ModuleData) {
|
|
|
this._data = {};
|
|
|
- this._variables = {};
|
|
|
+ this._init_data = {};
|
|
|
this.init(variableModuleData);
|
|
|
}
|
|
|
|
|
|
- init(variableModuleData: VariableModuleData) {
|
|
|
+ init(variableModuleData: ModuleData) {
|
|
|
// Identify changes between the new and old data
|
|
|
- const changes: VariableModuleData = {};
|
|
|
- for (const context in this._variables) {
|
|
|
+ const changes: ModuleData = {};
|
|
|
+ for (const context in this._init_data) {
|
|
|
if (!(context in variableModuleData)) {
|
|
|
- changes[context] = this._variables[context];
|
|
|
+ changes[context] = this._init_data[context];
|
|
|
continue;
|
|
|
}
|
|
|
- for (const variable in this._variables[context]) {
|
|
|
+ for (const variable in this._init_data[context]) {
|
|
|
if (!(variable in variableModuleData[context])) {
|
|
|
if (!(context in changes)) {
|
|
|
changes[context] = {};
|
|
|
}
|
|
|
- changes[context][variable] = this._variables[context][variable];
|
|
|
+ changes[context][variable] = this._init_data[context][variable];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (Object.keys(changes).length === 0) {
|
|
|
+ if (Object.keys(changes).length !== 0) {
|
|
|
console.error("Unmatched data tree! Removed changes: ", changes);
|
|
|
}
|
|
|
// Reset the initial data
|
|
|
- this._variables = variableModuleData;
|
|
|
+ this._init_data = variableModuleData;
|
|
|
this._data = {};
|
|
|
- for (const context in this._variables) {
|
|
|
- for (const variable in this._variables[context]) {
|
|
|
- const vData = this._variables[context][variable];
|
|
|
+ for (const context in this._init_data) {
|
|
|
+ for (const variable in this._init_data[context]) {
|
|
|
+ const vData = this._init_data[context][variable];
|
|
|
this._data[vData["encoded_name"]] = vData.value;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
getEncodedName(varName: string, module: string): string | undefined {
|
|
|
- if (module in this._variables && varName in this._variables[module]) {
|
|
|
- return this._variables[module][varName].encoded_name;
|
|
|
+ if (module in this._init_data && varName in this._init_data[module]) {
|
|
|
+ return this._init_data[module][varName].encoded_name;
|
|
|
}
|
|
|
return undefined;
|
|
|
}
|
|
|
|
|
|
// return [name, moduleName]
|
|
|
getName(encodedName: string): [string, string] | undefined {
|
|
|
- for (const context in this._variables) {
|
|
|
- for (const variable in this._variables[context]) {
|
|
|
- const vData = this._variables[context][variable];
|
|
|
+ for (const context in this._init_data) {
|
|
|
+ for (const variable in this._init_data[context]) {
|
|
|
+ const vData = this._init_data[context][variable];
|
|
|
if (vData.encoded_name === encodedName) {
|
|
|
return [variable, context];
|
|
|
}
|
|
@@ -83,10 +79,10 @@ export class VariableManager {
|
|
|
return this._data[encodedName];
|
|
|
}
|
|
|
|
|
|
- getInfo(encodedName: string): VariableData | undefined {
|
|
|
- for (const context in this._variables) {
|
|
|
- for (const variable in this._variables[context]) {
|
|
|
- const vData = this._variables[context][variable];
|
|
|
+ getInfo(encodedName: string): VarData | undefined {
|
|
|
+ for (const context in this._init_data) {
|
|
|
+ for (const variable in this._init_data[context]) {
|
|
|
+ const vData = this._init_data[context][variable];
|
|
|
if (vData.encoded_name === encodedName) {
|
|
|
return { ...vData, value: this._data[encodedName] };
|
|
|
}
|
|
@@ -95,8 +91,8 @@ export class VariableManager {
|
|
|
return undefined;
|
|
|
}
|
|
|
|
|
|
- getDataTree(): VariableModuleData {
|
|
|
- return this._variables;
|
|
|
+ getDataTree(): ModuleData {
|
|
|
+ return this._init_data;
|
|
|
}
|
|
|
|
|
|
getAllData(): Record<string, unknown> {
|