Bluebird deprecated their Promise.defer() mechanism for various reasons. While I think I understand the dangers of the defer-anti-pattern, I'm wondering if my use case requires it.
I want to return a promise that is resolved/rejected based on user input from a modal*. The modal is non-blocking and does not return a promise itself. Instead, functions are called when the user clicks on their response. Therefore, the function that constructs the promise does not have enough information to resolve/reject in its scope.
Javascript
export class FooClass {
canDeactivate() {
this.modal.open();
this.deferred = Promise.defer();
return this.deferred.promise;
// How can I use `new Promise(resolver_func)` without defer migration?
}
cancel() {
this.deferred.reject();
}
discard() {
this.deferred.resolve();
}
}
HTML
<div id="modal" md-modal md-modal.ref="modal">
<div class="modal-content">
<h4>Modal Header</h4>
<p>A bunch of text</p>
</div>
<div class="modal-footer">
<a click.delegate="discard()" ...>Discard Changes</a>
<a click.delegate="cancel()" ...>Stay on Page</a>
</div>
</div>
*This is an Aurelia app and my specific use case is to return a promise during the canDeactivate route lifecycle. A Materialize modal appears when the user tries to navigate away from the page asking if they want to discard changes and continue to navigate away or stay on the page.