Skip to content

Commit

Permalink
fix(dialogs): de-spawn dialogs upon remove
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickocoffeyo committed Jul 19, 2018
1 parent 4499e63 commit 2e4c909
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/aframe/components/spawnDialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import parseSceneFromExperience from '../../lib/parseSceneFromExperience';
*/
const spawnDialogs = {
multiple: false,
dialogs: [],
init() {
this.spawn();
},
remove() {
this.deSpawn();
},
shouldComponentUpdateRouting(oldProps, newProps) {
if (oldProps.history.location !== newProps.history.location) {
return true;
Expand All @@ -34,12 +38,20 @@ const spawnDialogs = {
didReceiveRoute() {
this.spawn();
},
deSpawn() {
this.dialogs.forEach(dialog => {
this.el.removeChild(dialog);
});
this.dialogs = [];
},
spawn() {
// If there is no router or experience data, exit.
if (!this.router || !this.props.experience.field_scenes) {
return;
}

this.deSpawn();

const {
props: { experience },
router: {
Expand Down Expand Up @@ -92,6 +104,7 @@ const spawnDialogs = {

e.setAttribute('dialog-popup', dialogPopup);
this.el.appendChild(e);
this.dialogs.push(e);
});
}
}
Expand Down

0 comments on commit 2e4c909

Please sign in to comment.