UNPKG

ember-promise-modals

Version:

The better way to handle modals in your Ember.js apps.

71 lines (68 loc) 1.99 kB
import { computed, set } from '@ember/object'; import { waitForPromise } from '@ember/test-waiters'; import { defer } from 'rsvp'; import { n } from 'decorator-transforms/runtime'; // eslint-disable-next-line ember/no-computed-properties-in-native-classes class Modal { constructor(service, componentClass, data, options = {}) { this._service = service; this._componentClass = componentClass; this._data = data; this._options = { className: '', onAnimationModalOutEnd: undefined, ...options }; this._result = undefined; this._deferred = defer(); this._deferredOutAnimation = undefined; this._componentInstance = undefined; } get result() { return this._result; } get isClosing() { return Boolean(this._deferredOutAnimation); } static { n(this.prototype, "isClosing", [computed('_deferredOutAnimation')]); } close(result) { if (this._componentInstance) { this._componentInstance.closeModal(result); } } then(onFulfilled, onRejected) { return this._deferred.promise.then(onFulfilled, onRejected); } _destroy() { if (!this._componentInstance) { return; } this._componentInstance.destroyModal(); } _resolve(result) { if (this._deferredOutAnimation) { return; } set(this, '_deferredOutAnimation', defer()); if (this._options.onAnimationModalOutEnd) { this._deferredOutAnimation.promise.then(() => this._options.onAnimationModalOutEnd()).catch(() => {}); } this._result = result; this._deferred.resolve(result); waitForPromise(this._deferredOutAnimation.promise); } _remove() { this._service._stack.removeObject(this); if (this._service._stack.length === 0) { this._service._onLastModalRemoved(); } this._componentInstance = undefined; if (this._deferredOutAnimation) { this._deferredOutAnimation.resolve(); } } } export { Modal as default }; //# sourceMappingURL=modal.js.map