Skip to content

Commit 758093d

Browse files
committed
(add) Memoize object for selectorsto prevent duplicates during D3 rendering
1 parent 45ddca9 commit 758093d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/app/components/AtomsRelationship.jsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ const root = '#d2f5e3';
2121
//
2222

2323
const clusterData = {};
24+
const selectorsCache = {}
2425

2526
let isFired = false
2627
function clusterDataPopulate(props) {
2728
let atomCompObj = reorganizedCompObj(props);
28-
console.log(props)
29-
console.log(atomCompObj)
3029

3130
//this is to set the root name property
3231
if (props[0].name) {
@@ -39,14 +38,16 @@ function clusterDataPopulate(props) {
3938

4039
for(let key in props[0].atomSelectors){
4140
let outerobj = {}
42-
outerobj.name = key
41+
outerobj.name = key
42+
selectorsCache[key] = true
4343

4444
if(props[0].atomSelectors[key].length){
4545
for(let i=0; i<props[0].atomSelectors[key].length;i++){
4646

4747
if(!outerobj.children) outerobj.children = []
4848
let innerobj = {}
4949
innerobj.name = props[0].atomSelectors[key][i]
50+
selectorsCache[props[0].atomSelectors[key][i]] = true
5051

5152
//if atoms contain components
5253
if(atomCompObj[props[0].atomSelectors[key][i]]){
@@ -69,7 +70,19 @@ function clusterDataPopulate(props) {
6970
clusterData.children.push(outerobj)
7071
}
7172
}
72-
console.log(clusterData)
73+
74+
for (let key in atomCompObj){
75+
let outObj = {};
76+
if(!selectorsCache[key]){
77+
outObj.name = key
78+
for (let i=0; i<atomCompObj[key].length;i++){
79+
if(!outObj.children) outObj.children = []
80+
outObj.children.push({name:atomCompObj[key][i]})
81+
}
82+
clusterData.children.push(outObj)
83+
}
84+
}
85+
7386
isFired = true
7487
}
7588

0 commit comments

Comments
 (0)