mus
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

Mus - FSM in TypeScript

finite-state machine in TypeScript for Angular

Build Status codecov.io Maintainability

Goal

  • basic state
  • annotation support

Draft

  1. Annotation
@transition(field='state', source='new', target='published', conditions=[can_publish])
  1. Simple DSL Support
@transition(
    field='state',
    source='for_moderators',
    target=GET_STATE(
        lambda self, allowed: 'published' if allowed else 'rejected',
        states=['published', 'rejected']))
  1. Self Usage

e.x. Transit Status

  • beginTransit
  • endTransit
  • failTransit
  • doTransit

References

JavaScript Example:

var fsm = new StateMachine({
  init: 'solid',
  transitions: [
    { name: 'melt',     from: 'solid',  to: 'liquid' },
    { name: 'freeze',   from: 'liquid', to: 'solid'  },
    { name: 'vaporize', from: 'liquid', to: 'gas'    },
    { name: 'condense', from: 'gas',    to: 'liquid' }
  ],
  methods: {
    onMelt:     function() { console.log('I melted')    },
    onFreeze:   function() { console.log('I froze')     },
    onVaporize: function() { console.log('I vaporized') },
    onCondense: function() { console.log('I condensed') }
  }
});

License

Phodal's Idea

@ 2018 A Phodal Huang's Idea. This code is distributed under the MIT license. See LICENSE in this directory.

Readme

Keywords

Package Sidebar

Install

npm i mus

Weekly Downloads

3

Version

0.0.4

License

MIT

Unpacked Size

230 kB

Total Files

30

Last publish

Collaborators

  • phodal