-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
180 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/client/src/workers/Evaluation/handlers/evalTreeUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { DataTree } from "entities/DataTree/dataTreeTypes"; | ||
import { getJSEntities } from "../JSObject"; | ||
|
||
export const mergeJSObjectsToUnevalTree = ( | ||
prevUevalTree: DataTree | undefined, | ||
currUnevalTree: DataTree, | ||
jsPatches: any, | ||
) => { | ||
const { patches, shouldReplaceAllNodes } = jsPatches; | ||
const unevalTreeWithPatches = patches.reduce( | ||
(acc: DataTree, patch: any) => { | ||
acc[patch.path] = patch.value; | ||
return acc; | ||
}, | ||
{ ...currUnevalTree }, | ||
); | ||
//in the case of shouldReplaceAllNodes, the patches represent all JSObjects that the current unevalTree consists of | ||
if (shouldReplaceAllNodes) { | ||
return unevalTreeWithPatches; | ||
} | ||
// In the case of patches, we need to merge the patches with the previous uneval tree | ||
const prevJSObjects = getJSEntities(prevUevalTree || {}); | ||
return { ...prevJSObjects, ...unevalTreeWithPatches }; | ||
}; | ||
|
||
export const getAffectedJSObjectIds = ( | ||
prevUnEvalValue: DataTree, | ||
currUevalTree: DataTree, | ||
jsPatches: any, | ||
) => { | ||
const { patches, shouldReplaceAllNodes } = jsPatches; | ||
if (shouldReplaceAllNodes) { | ||
// This is a list of all JS object ids in the current uneval tree as well as the previous uneval tree | ||
// When we diff the JS objects we use this list and during the shouldReplaceAllNodes all JSObjects are included and no node is missed out. | ||
const allJSObjectIds = Object.values({ | ||
...getJSEntities(currUevalTree || {}), | ||
...getJSEntities(prevUnEvalValue || {}), | ||
}).map((jsObject) => jsObject.actionId); | ||
|
||
return Array.from(new Set(allJSObjectIds)); | ||
} | ||
return patches.map((patch: any) => patch.value.actionId); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters