Almin

Almin

  • Docs
  • API
  • Blog
  • Help
  • GitHub

›Guides

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

UseCase LifeCycle

Almin has life-cycle events. These events are useful for logging like almin-logger.

For more information about logging, see Logging tips.

LifeCycle events

EventWhen
onBeginTransactionA transaction begin
onEndTransactionA transaction end
onWillNotExecuteEachUseCaseA UseCase will not Execute
onWillExecuteEachUseCaseEach UseCase will Execute
onDispatch @1UseCase calls this.dispatch(payload)
onErrorDispatch @1UseCase calls this.throwError(new Error())
onDidExecuteEachUseCaseEach UseCase did executed
onCompleteEachUseCaseEach UseCase is completed

@1 A single UseCase can call multiple.

For more details, see LifeCycleEventHub · API Reference.

What the difference between onDidExecuteEachUseCase and onCompleteEachUseCase?

Some UseCase's task is async. The difference is came up at the async case.

For example, We can write AsyncUseCase like following:

import { UseCase } from "almin";
export class AsyncUseCase extends UseCase {
    execute() {
        this.dispatch({ type: "start" });
        return Promise.resolve().then(() => {
            // does async function
        });
    }
}

The LifeCycle events of AsyncUseCase:

  1. Sync call onWillExecuteEachUseCase
  2. Sync call onDispatch
  3. Sync call onDidExecuteEachUseCase
  4. Async call onCompleteEachUseCase

The following is to illustrate the lifecycle in the code.

// IMAGE CODE!!!
import {UseCase} from "almin";
export class AsyncUseCase extends UseCase {
    // 1. call onWillExecuteEachUseCase
    execute() {
        // 2. call onDispatch
        this.dispatch({ type : "start" });
        return Promise.resolve().then(() => {
            // does async function
        }).then(() => {
            // 4. call onCompleteEachUseCase
        });
    }
    // 3. call onDidExecuteEachUseCase
}
// listen on*
context.events.onWillExecuteEachUseCase((payload, meta) => {});
context.events.onDispatch((payload, meta) => {});
context.events.onDidExecuteEachUseCase((payload, meta) => {});
context.events.onCompleteEachUseCase((payload, meta) => {});

onCompleteEachUseCase is always called after the onDidExecuteEachUseCase.

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