Permalink
Browse files

feat(dialog-controller): add param to canDeactivate / deactivate func…

…tions.
  • Loading branch information...
ydbondt committed Mar 28, 2017
1 parent 183c825 commit 42ad7f33e4c717449ce5ba53f3b8c2cd17283750
Showing with 22 additions and 19 deletions.
  1. +22 −19 src/dialog-controller.ts
View
@@ -45,8 +45,8 @@ export class DialogController {
/**
* @internal
*/
public releaseResources(): Promise<void> {
return invokeLifecycle(this.controller.viewModel || {}, 'deactivate')
public releaseResources(dialogResult?: any): Promise<void> {
return invokeLifecycle(this.controller.viewModel || {}, 'deactivate', dialogResult)
.then(() => this.renderer.hideDialog(this))
.then(() => { this.controller.unbind(); });
}
@@ -97,25 +97,28 @@ export class DialogController {
return this.closePromise;
}
return this.closePromise = invokeLifecycle(this.controller.viewModel || {}, 'canDeactivate').catch(reason => {
this.closePromise = undefined;
return Promise.reject(reason);
}).then(canDeactivate => {
if (!canDeactivate) {
this.closePromise = undefined; // we are done, do not block consecutive calls
return this.cancelOperation();
}
return this.releaseResources().then(() => {
if (!this.settings.rejectOnCancel || ok) {
this.resolve({ wasCancelled: !ok, output } as DialogCloseResult);
} else {
this.reject(createDialogCancelError(output));
}
return { wasCancelled: false };
}).catch(reason => {
const dialogResult = { wasCancelled: !ok, output } as DialogCloseResult;
return this.closePromise = invokeLifecycle(this.controller.viewModel || {}, 'canDeactivate', dialogResult)
.catch(reason => {
this.closePromise = undefined;
return Promise.reject(reason);
});
}).then(canDeactivate => {
if (!canDeactivate) {
this.closePromise = undefined; // we are done, do not block consecutive calls
return this.cancelOperation();
}
return this.releaseResources(dialogResult).then(() => {
if (!this.settings.rejectOnCancel || ok) {
this.resolve(dialogResult);
} else {
this.reject(createDialogCancelError(output));
}
return { wasCancelled: false };
}).catch(reason => {
this.closePromise = undefined;
return Promise.reject(reason);
});
});
}
}

0 comments on commit 42ad7f3

Please sign in to comment.