Skip to content

Commit

Permalink
fix: apply suggestions into PR
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpereznext authored and josex2r committed Dec 21, 2021
1 parent 216a4da commit 5c73504
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
37 changes: 20 additions & 17 deletions addon/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import { buildWaiter } from '@ember/test-waiters';

const openWaiter = buildWaiter('ember-modal-service:open-waiter');
const closeWaiter = buildWaiter('ember-modal-service:close-waiter');
const isNotDestroyed = (target, key, descriptor) => {
const targetMethod = descriptor.value;

descriptor.value = function(...args) {
// istanbul ignore if: lifecycle check.
if (this.isDestroyed) {
return null;
}

return targetMethod.apply(this, args);
};

return descriptor;
};

export default class ModalComponent extends Component {
@service modal;
Expand All @@ -30,22 +44,19 @@ export default class ModalComponent extends Component {
return String(this.visible);
}

init() {
super.init(...arguments);
didInsertElement() {
super.didInsertElement(...arguments);

next(this, '_open');
}

@isNotDestroyed
_safeDidOpen() {
this.didOpen && this.didOpen();
}

@isNotDestroyed
_open() {
// istanbul ignore if: lifecycle check.
if (this.isDestroyed) {
return;
}

const element = this.element;

this.visible = true;
Expand All @@ -67,12 +78,8 @@ export default class ModalComponent extends Component {
}
}

@isNotDestroyed
_close() {
// istanbul ignore if: lifecycle check.
if (this.isDestroyed || this.isDestroying) {
return;
}

const element = this.element;

// Close modal.
Expand All @@ -96,12 +103,8 @@ export default class ModalComponent extends Component {
}
}

@isNotDestroyed
_remove() {
// istanbul ignore if: lifecycle check.
if (this.isDestroyed) {
return;
}

this.modal._closeByModel(this.model);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
"validate-coverage": "test \"$(cat coverage/coverage-summary.json | json total.lines.total)\" -gt 0"
},
"dependencies": {
"@ember/test-waiters": "^3.0.0",
"@glimmer/tracking": "^1.0.1",
"ember-cli-babel": "^7.19.0",
"ember-cli-htmlbars": "^5.3.1",
"ember-transition-end": "^2.0.0",
"@ember/test-waiters": "^3.0.0"
"ember-transition-end": "^2.0.0"
},
"devDependencies": {
"@commitlint/cli": "^9.1.2",
Expand Down

0 comments on commit 5c73504

Please sign in to comment.