export declare class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher implements UseCaseExecutor<T> {
useCase: T;
executor(executor: (useCase: Pick<T, "execute">) => any): Promise<void>;
execute(): Promise<void>;
execute<T>(args: T): Promise<void>;
release(): void;
}
export declare class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher implements UseCaseExecutor<T> {
UseCaseExecutor
is a helper class for executing UseCase.
You can not create the instance of UseCaseExecutor directory.
You can get the instance by Context#useCase(useCase)
,
A executable useCase
- Stability: Experimental
- This feature is subject to change. It may change or be removed in future versions.
- If you inserting in this, please see almin#193
Similar to execute(arguments)
, but it accept an executor function insteadof arguments
executor(useCase => useCase.execute())
return a Promise object that resolved with undefined.
This method is type-safe. It is useful for TypeScript.
context.useCase(new MyUseCase())
.executor(useCase => useCase.execute("value"))
.then(() => {
console.log("test");
});
The execute(arguments)
is a alias of following codes:
context.useCase(new MyUseCase())
.execute("value")
// ===
context.useCase(new MyUseCase())
.executor(useCase => useCase.execute("value"))
Yes. It is type-safe by default. In other words, JavaScript User have not benefits.
UseCaseExecutor always resolve undefined
data by design.
In CQRS, the command always have returned void type.
So, Almin return only command result that is success or failure. You should not relay on the data of the command result.
execute(): Promise<void>;
execute<T>(args: T): Promise<void>;
execute UseCase instance.
UseCase is a executable object that has execute
method.
This method invoke UseCase's execute
method and return a promise.
The promise will be resolved when the UseCase is completed finished.
The execute(arguments)
is shortcut of executor(useCase => useCase.execute(arguments)
release all events handler. You can call this when no more call event handler