Skip to content

UseCase: Fluent style UseCase #193

@azu

Description

@azu

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

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");
    });

almin-test ts - almin 2017-05-10 00-12-17

Active middleware that has a side effect is needed to plugin/mixin system.
It does write too.
For example, modify Context#useCase and 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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions