Giter Site home page Giter Site logo

nxtep-io / nano-fsm Goto Github PK

View Code? Open in Web Editor NEW
10.0 10.0 1.0 1.62 MB

Minimalistic finite state machine for Typescript / Javascript environments.

Home Page: https://nxtep-io.github.io/nano-fsm

License: MIT License

TypeScript 96.93% Shell 3.07%

nano-fsm's People

Contributors

dependabot[bot] avatar luiseduardobrito avatar rangelfinal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

pedrolcn

nano-fsm's Issues

Transition should fail if beforeTransition or afterTransition return false

Only the return value of onTransition is considered on a transition change - if beforeTransition or afterTransition return false, the transition will still work as expected.

Also, if beforeTransition throws it works as expected because the error bubbles up and goTo throws before calling setTo.
But if afterTransition throws, goTo still throws, but setTo is called and the state is changed.

BUG: Winston 3 Logger

Winston 3 no longer accepts using new Logger() and this always throws an error when you try to initialize a StateMachine without passing the logger:
Simple logger constructor is deprecated in Winston 3, use Logger.initialize() instead (stackId: bb8e6b70-5ffc-488e-ad17-607805315b87)

Get back to 100% test coverage

There are currently two ternary operators not fully covered by the test suit, as all test cases follow the same branch of it.

Moving to same state will only call afterTransition lifecycle

An state change to the same state is defined here:

if (to === state && !this.options.allowSameState) {
throw new Error(`Machine is already in "${state}" state`);
} else if (to === state) {
await this.setState(state, to, []);
return true;
}

And the afterTransition lifecycle is called by setState
protected async setState(
from: State | (State | string)[],
to: State,
actions: Action<Instance, State>[]
): Promise<void> {
// Set the next state locally
this._state = to;
// Notify we're entered the next state
await Promise.all(actions.map(action => action.afterTransition(this.instance)));
await this.afterTransition(from, to);
}

But no other lifecycles are called on this case.

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.