Giter Club home page Giter Club logo

typescript-fsm's People

Contributors

anhldbk avatar dependabot[bot] avatar eram avatar f3nrir92 avatar jasondentler avatar lukasio avatar nicholaides avatar waynewaynetsai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

typescript-fsm's Issues

Add context to FSM

One of the main reasons to use a FSM is to protect the internal state of the model (the context).
Normally the context is defined inside the FSM and is only accessible on transitions and onEnter/onExit executions (so you avoid side effects).

The only way to change the context of a FSM is sending an event to it.

Conditional transitions

Would be really nice to have conditional transitions.
Normally in a FSM you can define more than one transition for the same state/event and depending on the condition one transition is selected or not (first transition that fulfil a condition is chosen even if another transition would be a good candidate).

The transitions are evaluated on order of declaration.

Send context on callbacks - protect from side effects

The transition callbacks should receive and instance of the fsm event handler and the state from/to:

function onOpen(eh: EventHandler, from: State, to: State): Promise<void> {

    console.log("onOpen...");
    return eh.dispatch(Events.openComplete);
}

With your current code I would not be able to execute 2 instances of the same FSM, which is a problem if for example you want to use an FSM per user (to handle his user state).

Add onEnter and onExit hooks

Sometimes in a FSM is needed to just do something not on the transition but when you enter or exit one state. Would be nice to add this functionality.

Good example is your state "breaking" where you want only to log and you have to define the action for all the states that reach that state (would have more sense to do onEnter).

url leads to 404

the example linked in the readme is broken
also, how do you generate the state machine chart there from typescript-fsm?

Typed dispatch args

Hi,

would you be open to a PR that adds strong types to the dispatch method?

Something like

StateMachine<STATE, EVENT extends string | number | symbol, CALLBACK extends Record<EVENT, Callback> = Record<EVENT, Callback>> {
 ...
  async dispatch<E extends EVENT>(event: E, ...args: Parameters<CALLBACK[E]>): Promise<void> {

and usage

interface ICallbacks extends Record<Events, Callback> {
  [Events.open]: (test: number) => void;
  [Events.close]: (te: string) => void
}

class Door extends StateMachine<States, Events, ICallbacks> {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.