-
Notifications
You must be signed in to change notification settings - Fork 42
UseCase: Fluent style UseCase #193
Description
This idea from almin-thinking/02-Fluent-UseCase.ts at master · almin/almin-thinking.
new UseCaseExecutor(new MyUseCase())
.executor(useCase => useCase.execute("test"))
.then(value => {
console.log(value);
});I called it "Fluent style UseCase".
It has some advantages:
Pros
- Type safe
- Maybe extensible feature: plugin/middleware #2
- Make exist
execute()catchable(try-catch)
Type safe
I've created a very initial POC of fluent syle UseCase.
#194
It is actually type safe.
class MyUseCase extends UseCase {
execute(value: string) {
this.dispatch({
type: "ChildUseCase",
value
});
}
}
context.useCase(new MyUseCase())
.executor(useCase => useCase.execute(42))
.then(() => {
console.log("test");
});Active middleware that has a side effect is needed to plugin/mixin system.
It does write too.
For example, modifyContext#useCaseand make it accepting custom object which is not a UseCase instance.We will focus on Active midldleware.
#2 (comment)
I think that this fluent style may be extensible.
This wrap UseCase and pass it to executor(useCase => ).
We can add middleware system to this wrapping.
Cons
- A bit complex syntax?
- Conflict with current UseCaseExecutor#execute
If we will add middleware to UseCase, UseCaseExecutor#execute and UseCaseExecutor#executor should be one method.
I think that executor(executorFunction) is not good name.
Make it more meaningful name...
Any idea?
