From 90a10083ca35770e445ba0362c7fe5f0c369c5dc Mon Sep 17 00:00:00 2001 From: nickschot Date: Thu, 15 Jul 2021 16:06:59 +0200 Subject: [PATCH 1/2] fix backdrop not animating immediately after the last modal is closed --- addon/modal.js | 9 ++++++++- addon/services/modals.js | 6 ++++-- tests/unit/services/modals-test.js | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/addon/modal.js b/addon/modal.js index 2f633565..543518b3 100644 --- a/addon/modal.js +++ b/addon/modal.js @@ -1,3 +1,5 @@ +// eslint-disable-next-line ember/no-computed-properties-in-native-classes +import { computed, set } from '@ember/object'; import { waitForPromise } from '@ember/test-waiters'; import { defer } from 'rsvp'; @@ -18,6 +20,11 @@ export default class Modal { return this._result; } + @computed('_deferredOutAnimation') + get isClosing() { + return Boolean(this._deferredOutAnimation); + } + close(result) { if (this._componentInstance) { this._componentInstance.closeModal(result); @@ -30,7 +37,7 @@ export default class Modal { _resolve(result) { if (!this._deferredOutAnimation) { - this._deferredOutAnimation = defer(); + set(this, '_deferredOutAnimation', defer()); this._result = result; this._deferred.resolve(result); diff --git a/addon/services/modals.js b/addon/services/modals.js index caba0e18..5dc4195a 100644 --- a/addon/services/modals.js +++ b/addon/services/modals.js @@ -1,12 +1,14 @@ import { A } from '@ember/array'; -import { set } from '@ember/object'; +import { computed, set } from '@ember/object'; import { alias } from '@ember/object/computed'; import Service from '@ember/service'; import Modal from '../modal'; export default Service.extend({ - count: alias('_stack.length'), + count: computed('_stack.@each.isClosing', function () { + return this._stack.filter(modal => !modal.isClosing).length; + }), top: alias('_stack.lastObject'), clickOutsideDeactivates: true, diff --git a/tests/unit/services/modals-test.js b/tests/unit/services/modals-test.js index 226b8967..6f029cef 100644 --- a/tests/unit/services/modals-test.js +++ b/tests/unit/services/modals-test.js @@ -57,4 +57,19 @@ module('Service | modals', function (hooks) { modal._remove(); }); + + test('modals do not show up in openCount when closing', async function (assert) { + let modals = this.owner.lookup('service:modals'); + let modal = modals.open('modal'); + + assert.equal(modals.count, 1); + + modal._resolve(); + + assert.equal(modals.count, 0); + + modal._remove(); + + assert.equal(modals.count, 0); + }); }); From c9c820dff2c644b46a4747267a5863cecfac678e Mon Sep 17 00:00:00 2001 From: nickschot Date: Thu, 15 Jul 2021 16:35:22 +0200 Subject: [PATCH 2/2] add ember-decorators-polyfill to ember-try for ember 3.4 and 3.8 --- config/ember-try.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/ember-try.js b/config/ember-try.js index fdc61792..edd26b9c 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -11,6 +11,7 @@ module.exports = async function () { npm: { devDependencies: { 'ember-source': '~3.4.0', + 'ember-decorators-polyfill': '^1.1.5', }, }, }, @@ -19,6 +20,7 @@ module.exports = async function () { npm: { devDependencies: { 'ember-source': '~3.8.0', + 'ember-decorators-polyfill': '^1.1.5', }, }, },