UseCase: Fluent style UseCase #193

Closed
azu opened this Issue May 9, 2017 · 3 comments

Comments

Projects
None yet
1 participant
@azu
Member

azu commented May 9, 2017

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

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?

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu May 10, 2017

Member

If we will add middleware to UseCase, UseCaseExecutor#execute and UseCaseExecutor#executor should be one method.

I've changed UseCaseExecutor#execute as folloinwg:

execute(...args: Array<any>): Promise<void> {
        return this.executor((useCase) => useCase.execute(...args));
}

It make execute() syntax suger of executor.

Member

azu commented May 10, 2017

If we will add middleware to UseCase, UseCaseExecutor#execute and UseCaseExecutor#executor should be one method.

I've changed UseCaseExecutor#execute as folloinwg:

execute(...args: Array<any>): Promise<void> {
        return this.executor((useCase) => useCase.execute(...args));
}

It make execute() syntax suger of executor.

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu May 31, 2017

Member

Make exist execute() catchable(try-catch)

I've merged #194 for improving error handing on UseCase.
But, it does not means that executor is stable.(It maybe changed until next release)

We continue to investigate this Fluent style UseCase.

Member

azu commented May 31, 2017

Make exist execute() catchable(try-catch)

I've merged #194 for improving error handing on UseCase.
But, it does not means that executor is stable.(It maybe changed until next release)

We continue to investigate this Fluent style UseCase.

@azu azu referenced this issue Jul 8, 2017

Closed

almin: 0.13 #225

@azu azu referenced this issue Jul 20, 2017

Open

Update Flow type definition for Almin 0.13 #252

0 of 6 tasks complete
@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu Jan 27, 2018

Member

Move to #107

Member

azu commented Jan 27, 2018

Move to #107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment