Skip to content

Commit

Permalink
fix incorrect elements.count
Browse files Browse the repository at this point in the history
  • Loading branch information
mnater committed Mar 24, 2019
1 parent 91b4622 commit cd78861
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Hyphenopoly.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@
return elo;
}

/**
* Removes elements from the list and updates the counter
* @param {string} lang - The lang of the elements to remove
*/
function rem(lang) {
let langCount = 0;
if (list.has(lang)) {
langCount = list.get(lang).length;
list.delete(lang);
counter[0] -= langCount;
if (counter[0] === 0) {
H.events.dispatch("hyphenopolyEnd");
}
}
}

/**
* Execute fn for each element
* @param {function} fn The function to execute
Expand All @@ -204,7 +220,8 @@
"add": add,
"counter": counter,
"each": each,
"list": list
"list": list,
"rem": rem
};
}

Expand Down Expand Up @@ -1074,8 +1091,7 @@
"loadError",
function onLoadError(e) {
if (e.msg !== "wasm") {
elements.list.delete(e.name);
elements.counter[0] -= 1;
elements.rem(e.name);
}
},
false
Expand Down

0 comments on commit cd78861

Please sign in to comment.