Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public onClickOkCancel(type: 'ok' | 'cancel'): void {
const trigger = { ok: this.nzOnOk, cancel: this.nzOnCancel }[type];
const loadingKey = { ok: 'nzOkLoading', cancel: 'nzCancelLoading' }[type];
if (trigger instanceof EventEmitter) {
trigger.emit(this.getContentComponent());
} else if (typeof trigger === 'function') {
const result = trigger(this.getContentComponent());
const caseClose = (doClose: boolean | void | {}) => doClose !== false && this.close(doClose as R); // Users can return "false" to prevent closing by default
if (isPromise(result)) {
this[loadingKey] = true;
const handleThen = (doClose: boolean | void | {}) => {
this[loadingKey] = false;
caseClose(doClose);
};
result.then(handleThen).catch(handleThen);
} else {
caseClose(result);
}
}
}
public onButtonClick(button: ModalButtonOptions): void {
const result = this.getButtonCallableProp(button, 'onClick'); // Call onClick directly
if (isPromise(result)) {
button.loading = true;
result.then(() => (button.loading = false)).catch(() => (button.loading = false));
}
}