Skip to content

Commit

Permalink
feat: wait until modal is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
next-joserepresa authored and josex2r committed Nov 24, 2021
1 parent 579cc8f commit b84d425
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions addon/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ export default class ModalComponent extends Component.extend({
reject(data, label = `Component '${this.model.fullname}': rejection`) {
this.model.reject(data, label);
}

willDestroy() {
super.willDestroy(...arguments);

this.modal.trigger('will-destroy', this.model);
}
}
10 changes: 9 additions & 1 deletion addon/services/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ export default class ModalService extends Service.extend(Evented) {
}

_closeByModel(model) {
this.trigger('close', model);
const destroyCallback = (destroyedModal) => {
if (destroyedModal === model) {
this.trigger('close', model);
}
};

// Setup DOM removal listener
this.one('will-destroy', destroyCallback);
// Remove from DOM
this.content.removeObject(model);
}

Expand Down

0 comments on commit b84d425

Please sign in to comment.