Skip to content

Commit bf65045

Browse files
committed
Clearing all dice-wrapper element children in onDiceConnected so duplicate dice buttons aren't created if you connect the same die twice
1 parent ad07207 commit bf65045

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ GoDice.prototype.onDiceConnected = (diceId, diceInstance) => {
3030
// get new die element or it's instance if it's already exists
3131
const diceHtmlEl = getDiceHtmlEl(diceId);
3232

33+
// clear existing die element content if it exists
34+
while (diceHtmlEl.firstChild) {
35+
diceHtmlEl.removeChild(diceHtmlEl.lastChild);
36+
}
37+
3338
// get die host from html, where we will put our connected dices
3439
const diceHost = document.getElementById("dice-host");
3540

0 commit comments

Comments
 (0)