shlomiassaf / ngx-modialog

Modal / Dialog for Angular
http://shlomiassaf.github.io/ngx-modialog
MIT License
686 stars 242 forks source link

refactor: dont return a promise when opening a dialog #383

Closed shlomiassaf closed 7 years ago

shlomiassaf commented 7 years ago

BREAKING CHANGE: Calling modal.open() returned a Promise of DialogRef. The async operation is not required and exists due to legacy angular implementation of dynamic components. modal.open() now returns the DialogRef instance and NOT the Promise.

You need to refactor your codebase to accomodate this change, this is a big change and it is required to remove the complexity working with DialogRef.

Plugin authoers: Maybe type does not exists anymore. If you retuned the dialog instance from your Modal implementations there is not much to refactor other then types here and there.

If you return Promise of DialogRef you will have to refactor your code.

alfupe commented 7 years ago

Thanks a lot @shlomiassaf. So sorry, I'm a bit lost, how do you refactor this?

openDetailModal(event) {
  event.preventDefault();

  const dialog = this.modal.open(BuyerCRMDetailModalComponent, overlayConfigFactory({buyer: this.buyer}, BSModalContext));

  dialog.then(resultPromise => {
    return resultPromise.result
      .then(
        result => {
          this.log.info('openDetailModal()', 'then', result);

          if (!result) return;
          this.log.info('do something with', result);
        },
        () => {
          this.log.info('openDetailModal()', 'Rejected');
        });
    });
}
Gbacc commented 6 years ago

Looking at the code change i guess :

openDetailModal(event) {
  event.preventDefault();

  const dialog = this.modal.open(BuyerCRMDetailModalComponent, overlayConfigFactory({buyer: this.buyer}, BSModalContext));

  dialog.then(
        result => {
          this.log.info('openDetailModal()', 'then', result);

          if (!result) return;
          this.log.info('do something with', result);
        },
        () => {
          this.log.info('openDetailModal()', 'Rejected');
        });
}
alfupe commented 6 years ago

@Gbacc Thanks for helping out!

The code you put is almost working though we need to call result on dialog:

...
dialog.result.then(
...