Skip to content

Commit ee9eb2f

Browse files
committed
Setting up memoization object to optimize performance for filtering out duplicate snapshots without having to re-render the clusterData object everytime
1 parent d662ee7 commit ee9eb2f

File tree

1 file changed

+22
-46
lines changed

1 file changed

+22
-46
lines changed

src/app/components/AtomsRelationship.jsx

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,44 @@ export const background = '#242529';
1717
// children?: NodeShape[];
1818
//
1919

20-
function clusterDataPopulate(props) {
21-
let data = {};
20+
const clusterData = {};
2221

22+
function clusterDataPopulate(props) {
2323
console.log(props)
2424
let atomCompObj = reorganizedObj(props);
2525

2626
console.log(atomCompObj);
2727

2828
if (props[0].name) {
29-
data.name = props[0].name;
29+
clusterData.name = props[0].name;
3030
}
3131

32+
33+
let memoizeObj = {}
3234
let counter = 0
35+
3336
for(let key in atomCompObj){
34-
if(!data.children) data.children = []
35-
data.children.push({name: key})
3637
if(atomCompObj[key].length){
3738
for(let i=0; i<atomCompObj[key].length;i++){
38-
if(!data.children[counter].children) data.children[counter].children = []
39-
data.children[counter].children.push ({name:atomCompObj[key][i]})
39+
40+
41+
42+
43+
44+
if(!clusterData.children) clusterData.children = []
45+
clusterData.children.push({name: key})}
46+
if(!clusterData.children[counter].children) {
47+
clusterData.children[counter].children = []
48+
clusterData.children[counter].children.push ({name:atomCompObj[key][i]})}
49+
50+
if (!memoizeObj[key]){
51+
memoizeObj[key] = []
52+
memoizeObj[key].push[atomCompObj[key][i]]
4053
}
4154
}
4255
counter++
4356
}
44-
console.log(data)
57+
console.log(clusterData)
4558
}
4659

4760
function reorganizedObj(props) {
@@ -60,44 +73,7 @@ function reorganizedObj(props) {
6073
return reorganizedObj;
6174
}
6275

63-
const clusterData = {
64-
name: 'root',
65-
66-
children: [
67-
{
68-
name: 'darkMode',
69-
children: [
70-
{ name: 'A1' },
71-
{ name: 'A2' },
72-
{
73-
name: 'C',
74-
children: [
75-
{
76-
name: 'C1',
77-
},
78-
],
79-
},
80-
],
81-
},
82-
83-
84-
85-
{
86-
name: 'B',
87-
children: [{ name: 'B1' }, { name: 'B2' }, { name: 'B3' }],
88-
},
89-
90-
91-
{
92-
name: 'X',
93-
children: [
94-
{
95-
name: 'Z',
96-
},
97-
],
98-
},
99-
],
100-
};
76+
10177

10278
function Node({ node }) {
10379
const isRoot = node.depth === 0;

0 commit comments

Comments
 (0)