2023-04-03 10:41:15 +00:00
|
|
|
import type { DataTree } from "entities/DataTree/dataTreeFactory";
|
|
|
|
|
import { isEmpty } from "lodash";
|
|
|
|
|
import type { EvalContext } from "workers/Evaluation/evaluate";
|
2023-05-11 05:26:03 +00:00
|
|
|
import getEvaluationContext from "./utils/getEvaluationContext";
|
2023-04-03 10:41:15 +00:00
|
|
|
|
|
|
|
|
class GlobalData {
|
|
|
|
|
globalDataWithFunctions: EvalContext = {};
|
|
|
|
|
globalDataWithoutFunctions: EvalContext = {};
|
|
|
|
|
unevalTree: DataTree = {};
|
|
|
|
|
cloudHosting = false;
|
|
|
|
|
|
|
|
|
|
initialize(unevalTree: DataTree, cloudHosting: boolean) {
|
|
|
|
|
this.globalDataWithFunctions = {};
|
|
|
|
|
this.globalDataWithoutFunctions = {};
|
|
|
|
|
this.unevalTree = unevalTree;
|
|
|
|
|
this.cloudHosting = cloudHosting;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getGlobalData(withFunctions: boolean) {
|
|
|
|
|
// Our goal is to create global data (with or without functions) only once during a linting cycle
|
|
|
|
|
if (withFunctions) {
|
|
|
|
|
if (isEmpty(this.globalDataWithFunctions)) {
|
|
|
|
|
this.globalDataWithFunctions = getEvaluationContext(
|
|
|
|
|
this.unevalTree,
|
|
|
|
|
this.cloudHosting,
|
|
|
|
|
{
|
|
|
|
|
withFunctions: true,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return this.globalDataWithFunctions;
|
|
|
|
|
} else {
|
|
|
|
|
if (isEmpty(this.globalDataWithoutFunctions)) {
|
|
|
|
|
this.globalDataWithoutFunctions = getEvaluationContext(
|
|
|
|
|
this.unevalTree,
|
|
|
|
|
this.cloudHosting,
|
|
|
|
|
{
|
|
|
|
|
withFunctions: false,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return this.globalDataWithoutFunctions;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const globalData = new GlobalData();
|