Skip to content

Commit

Permalink
chore: changed evaluateTree to use klonaJSON (#37976)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsvamsi1 authored Dec 7, 2024
1 parent ef0ef1b commit 061e5a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions app/client/src/workers/Evaluation/__tests__/evaluation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import WidgetFactory from "WidgetProvider/factory";
import { generateDataTreeWidget } from "entities/DataTree/dataTreeWidget";
import { sortObjectWithArray } from "../../../utils/treeUtils";
import klona from "klona";

import { APP_MODE } from "entities/App";

const klonaFullSpy = jest.fn();
Expand All @@ -31,6 +32,17 @@ jest.mock("klona/full", () => ({
return klona.klona(arg);
},
}));
const klonaJsonSpy = jest.fn();

jest.mock("klona/json", () => ({
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
klona: (arg: any) => {
klonaJsonSpy(arg);

return klona.klona(arg);
},
}));

export const WIDGET_CONFIG_MAP: WidgetTypeConfigMap = {
CONTAINER_WIDGET: {
Expand Down Expand Up @@ -581,7 +593,8 @@ describe("DataTreeEvaluator", () => {
);
evaluator.evalAndValidateFirstTree();
// Hard check to not regress on the number of clone operations. Try to improve this number.
expect(klonaFullSpy).toBeCalledTimes(41);
expect(klonaFullSpy).toBeCalledTimes(40);
expect(klonaJsonSpy).toBeCalledTimes(3);
});

it("Evaluates a binding in first run", () => {
Expand Down Expand Up @@ -1102,6 +1115,7 @@ describe("DataTreeEvaluator", () => {
unEvalUpdates,
);
// Hard check to not regress on the number of clone operations. Try to improve this number.
expect(klonaFullSpy).toBeCalledTimes(7);
expect(klonaFullSpy).toBeCalledTimes(6);
expect(klonaJsonSpy).toBeCalledTimes(2);
});
});
2 changes: 1 addition & 1 deletion app/client/src/workers/common/DataTreeEvaluator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ export default class DataTreeEvaluator {
staleMetaIds: string[];
contextTree: DataTree;
} {
const safeTree = klona(unEvalTree);
const safeTree = klonaJSON(unEvalTree);
const dataStore = DataStore.getDataStore();
const dataStoreClone = klonaJSON(dataStore);

Expand Down

0 comments on commit 061e5a8

Please sign in to comment.