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

TypeScript

This document note some need-to-know things for TypeScript User.

Type Definition

Almin has built-in Type definition file(.d.ts).

If you want to use almin with TypeScript, you just install Almin. Type definition file(.d.ts) will be loaded automatically.

Payload

You can use abstract Payload class for creating own payload. This Payload class pattern is simple in TypeScript.

Example: StartLoadingUseCase

StartLoadingUseCase.ts

import { Payload, UseCase } from "almin";
export class StartLoadingPayload implements Payload {
    type = "StartLoadingPayload";
}

export class StartLoadingUseCase extends UseCase {
    execute() {
        this.dispatch(new StartLoadingPayload());
    }
}

Also, you just use instanceof type-guard.

import { Payload, UseCase } from "almin";
import { StartLoadingPayload } from "./StartLoadingUseCase.ts";
export class ExampleStore extends Store {
    receivePayload(payload: any) {
        if(payload instanceof StartLoadingPayload){
            // payload is StartLoadingPayload
        }
    }
    // ...
}

Further reading

  • Tackling State – Angular
  • Redux & Typescript typed Actions with less keystrokes

UseCase

You should use executor method instead of execute method. Because, executor is type-safe method, but execute is not type-safe.

// OK
context.useCase(someUseCase).executor(useCase => useCase.execute(args))
// NG
context.useCase(someUseCase).execute(args);

This limitation come from TypeScript feature. For more details, see following link.

  • TypeScript: improve UseCase#execute typing · Issue #107 · almin/almin

Helper

  • almin/ddd-base: DDD base class library for JavaScript application.

Examples

Almin + TypeScript real examples.

  • azu/faao: Faao is a GitHub issue/pull-request client on Electron.
  • azu/irodr: RSS reader client like LDR for Inoreader.
  • proofdict/editor: Proofdict editor.
← UseCase LifeCycleUseCase is already released →
Almin
Docs
Getting StartedTutorialAPI Reference
Community
User ShowcaseStack OverflowTwitter
GitHub
GitHubReleasesIssuesStar
Copyright © 2021 azu