Skip to content
A typescript finite state machine library
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
README.md
jest.config.js
package-lock.json
package.json
tsconfig.json

README.md

typescript-state-machine

A typescript finite state machine library

Install

Download the source file and add state-machine to you project.

Usage

1. Define States

First define the states:

enum EHreoStatus {
    stand,
    kneel,
    leap
}

2. Create a state machine

A state machine can be constructed:

const option = {
    init: EHreoStatus.stand,
    transitions: {
        squat: BuildTransition(EHreoStatus.stand, EHreoStatus.kneel),
        standup: BuildTransition(EHreoStatus.kneel, EHreoStatus.stand),
        jump: BuildTransition(EHreoStatus.stand, EHreoStatus.leap),
        land: BuildTransition(EHreoStatus.leap, EHreoStatus.stand),
    }
};
const fsm = new StateMachine(option);

Then you can transition to different state:

fsm.transition().squat();
fsm.transition().standup();
fsm.transition().jump();
fsm.transition().land();
You can’t perform that action at this time.