Skip to content

Commit ecdf59d

Browse files
authored
Merge pull request #29 from oslabs-beta/keyla/debugBadgeNumber
Fixed the bug that increases the badge twice
2 parents 6edce72 + 7fd138c commit ecdf59d

File tree

1 file changed

+12
-22
lines changed
  • src/components/left-sidebar/ComponentTab

1 file changed

+12
-22
lines changed

src/components/left-sidebar/ComponentTab/Icons.vue

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Description:
1414
<br />
1515
<span>{{ elementName }}</span>
1616
</button>
17-
17+
<!-- Child Component Icons-->
1818
<button
1919
@click.prevent="changeState(elementName)"
2020
v-for="(elementName, idx) in childrenComp"
@@ -55,33 +55,23 @@ export default {
5555
elementStorage: function () {
5656
let computedElementalStorage = {};
5757
if (this.activeComponent) {
58+
computedElementalStorage = {};
5859
59-
this.componentMap[this.activeComponent].htmlList.forEach((el) => {
60-
if (!computedElementalStorage[el.text]) {
61-
computedElementalStorage[el.text] = 1;
62-
}
63-
else if (computedElementalStorage[el.text]) {
64-
computedElementalStorage[el.text] += 1;
65-
}
66-
});
67-
//show the badge for all nested children arrays
68-
const checkChild = array => {
60+
//function searches through HtmlList and is invoke recursively to search its children(Html Elements that are nested)
61+
const checkHtmlElements = array => {
6962
for (let html of array) {
70-
console.log(html)
7163
if (html.children.length) {
72-
checkChild(html.children)
64+
checkHtmlElements(html.children)
65+
}
66+
if (!computedElementalStorage[html.text]) {
67+
computedElementalStorage[html.text] = 1
7368
} else {
74-
if (!computedElementalStorage[html.text]) {
75-
computedElementalStorage[html.text] = 1
76-
} else {
77-
++computedElementalStorage[html.text]
78-
}
69+
++computedElementalStorage[html.text]
7970
}
8071
}
8172
}
82-
//invoke the recursive function
83-
checkChild(this.componentMap[this.activeComponent].htmlList)
84-
73+
//invoke the recursive function
74+
checkHtmlElements(this.componentMap[this.activeComponent].htmlList)
8575
} else if (this.activeComponent === "") {
8676
// if component was switched from existing component to '', reset cache and update items
8777
if (computedElementalStorage !== {}) computedElementalStorage = {};
@@ -95,9 +85,9 @@ export default {
9585
}
9686
return computedElementalStorage;
9787
},
88+
//Compute Child Components of the activeComponent to include them as icons
9889
childrenComp: function () {
9990
let childrenAvailable = [];
100-
10191
if(this.activeComponent) {
10292
childrenAvailable = this.componentMap[this.activeComponent].children
10393
}

0 commit comments

Comments
 (0)