Almin

Almin

  • Docs
  • API
  • Blog
  • Help
  • GitHub

›API

Introduction

  • Getting Started
  • Components of Almin
  • Principles
  • Hello World

Tutorial

  • Example projects
  • Counter Tutorial
  • Todo App tutorial

Guides

  • Logging
  • Nesting UseCase
  • Performance profile
  • Strict mode
  • UseCase LifeCycle
  • TypeScript

Troubleshooting

  • UseCase is already released

Appendix

  • GLOSSARY

API

  • API Index
  • Context
  • Dispatcher
  • DispatcherPayloadMeta
  • LifeCycleEventHub
  • Store
  • StoreGroup
  • UseCase
  • UseCaseContext
  • UseCaseExecutor
Edit

UseCaseExecutor

Interface

export declare class UseCaseExecutorImpl<T extends UseCaseLike> extends Dispatcher implements UseCaseExecutor<T> {
    useCase: T;
    onReleaseOnce(handler: () => void): void;
    executor(executor: (useCase: Pick<T, "execute">) => any): Promise<void>;
    execute<P extends Arguments<T["execute"]>>(...args: P): Promise<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),


useCase: T;

A executable useCase


onReleaseOnce(handler: () => void): void;

Call handler when this UseCaseExecutor will be released

param handler


executor(executor: (useCase: Pick<T, "execute">) => any): Promise<void>;

Stability: Deprecated(Previously: experimental)

  • This feature is subject to change. It may change or be removed in future versions.
  • If you inserting in this, please see https://github.com/almin/almin/issues/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.

Example

context.useCase(new MyUseCase())
 .executor(useCase => useCase.execute("value"))
 .then(() => {
   console.log("test");
 });

Notes

What is difference between executor(executor) and execute(arguments)?

The execute(arguments) is a alias of following codes:

context.useCase(new MyUseCase())
 .execute("value")
// ===
context.useCase(new MyUseCase())
 .executor(useCase => useCase.execute("value"))

Why executor's result always to be undefined?

execute() return a Promise that will resolve undefined by design. In CQRS, the command always have returned void type.

  • http://cqrs.nu/Faq

So, execute() only return command result that is success or failure. You should not relay on the result value of the useCase#execute.

deprecated Use execute() instead of executor() Almin 0.18+ make execute type complete. It will be remove in the future.

Please apply migration scripts: https://github.com/almin/almin/issues/356


execute<P extends Arguments<T["execute"]>>(...args: P): 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.

Why executor's result always to be undefined?

execute() return a Promise that will resolve undefined by design. In CQRS, the command always have returned void type.

  • http://cqrs.nu/Faq

So, execute() only return command result that is success or failure. You should not relay on the result value of the useCase#execute.

Notes

Added: Almin 0.17.0+

execute() support type check in Almin 0.17.0. However, it has a limitation about argument lengths. For more details, please see https://github.com/almin/almin/issues/107#issuecomment-384993458

Added: Almin 0.18.0+

execute() support type check completely. No more need to use executor() for typing.


← UseCaseContext
Almin
Docs
Getting StartedTutorialAPI Reference
Community
User ShowcaseStack OverflowTwitter
GitHub
GitHubReleasesIssuesStar
Copyright © 2021 azu