Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit a9c4aee

Browse files
committed
Rename some function's name and call remove() if the listEl is invalid
1 parent 87c7a7f commit a9c4aee

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

extension/sidebar-pane.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ async function _update() {
1515
}
1616

1717
async function _updateSelectedNode(selectedNode) {
18-
// Get new <ul> element to avoid updating by previous processes.
19-
const issueListEl = _getNewULElement("#selected ul");
18+
// Get new <ul> element to avoid updating by previous rendering.
19+
const issueListEl = _getIssuesListRootElement("#selected ul");
2020

2121
_recursiveNodesIssuesRendering(0, [selectedNode], true, issueListEl, []).then(() => {
22-
if (!_isCurrentProcess(issueListEl)) {
22+
if (!_isCurrentlyRendering(issueListEl)) {
2323
return;
2424
}
2525

@@ -31,8 +31,8 @@ async function _updateSelectedNode(selectedNode) {
3131

3232
async function _updateSubtree(selectedNode) {
3333
const subtreeEl = document.getElementById("subtree");
34-
// Get new <ul> element to avoid updating by previous processes.
35-
const issueListEl = _getNewULElement("#subtree ul");
34+
// Get new <ul> element to avoid updating by previous rendering.
35+
const issueListEl = _getIssuesListRootElement("#subtree ul");
3636

3737
subtreeEl.classList.add("processing");
3838
const progressEl = subtreeEl.querySelector("aside label");
@@ -43,7 +43,7 @@ async function _updateSubtree(selectedNode) {
4343
progressEl.textContent = "Getting web compatibility issues";
4444
issueListEl.innerHTML = "";
4545
_recursiveNodesIssuesRendering(0, nodesInSubtree, false, issueListEl, []).then(() => {
46-
if (!_isCurrentProcess(issueListEl)) {
46+
if (!_isCurrentlyRendering(issueListEl)) {
4747
return;
4848
}
4949

@@ -54,14 +54,22 @@ async function _updateSubtree(selectedNode) {
5454
});
5555
}
5656

57-
function _getNewULElement(selector) {
57+
/**
58+
* Return <ul> element for the issues.
59+
* Note: This function creates new <ul> element and replaces from old <ul> element that
60+
* is matched by the given selector.
61+
*
62+
* @param {String} - selector
63+
* @return {Element} - new <ul> element that was replaced
64+
*/
65+
function _getIssuesListRootElement(selector) {
5866
const oldElement = document.querySelector(selector);
5967
const newElement = document.createElement("ul");
6068
oldElement.parentElement.replaceChild(newElement, oldElement);
6169
return newElement;
6270
}
6371

64-
function _isCurrentProcess(listEl) {
72+
function _isCurrentlyRendering(listEl) {
6573
return !!listEl.parentElement;
6674
}
6775

@@ -83,8 +91,9 @@ function _isCurrentProcess(listEl) {
8391
*/
8492
async function _recursiveNodesIssuesRendering(index, nodes,
8593
skipPseudo, listEl, groupsCache) {
86-
if (!_isCurrentProcess(listEl)) {
87-
// New updating process is running.
94+
if (!_isCurrentlyRendering(listEl)) {
95+
// New rendering is running.
96+
listEl.remove();
8897
return;
8998
}
9099

0 commit comments

Comments
 (0)