presenter refactoring
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
export interface CommandResultViewModel {
|
||||
success: boolean;
|
||||
errorCode?: string;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export class CommandResultPresenter {
|
||||
private result: CommandResultViewModel | null = null;
|
||||
|
||||
presentSuccess(message?: string): void {
|
||||
this.result = {
|
||||
success: true,
|
||||
message,
|
||||
};
|
||||
}
|
||||
|
||||
presentFailure(errorCode: string, message?: string): void {
|
||||
this.result = {
|
||||
success: false,
|
||||
errorCode,
|
||||
message,
|
||||
};
|
||||
}
|
||||
|
||||
getViewModel(): CommandResultViewModel | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): CommandResultViewModel {
|
||||
if (!this.result) {
|
||||
throw new Error('Presenter not presented');
|
||||
}
|
||||
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user