Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coffee_state_machine

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coffee_state_machine

a finite state machine made in and for coffeescript (javascript)

  • 0.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

coffee_state_machine Build Status

a finite state machine made in and for CoffeeScript (javascript).

currently there is no separated documentation - but just take a look into tests/. it is very easy to use.

this libray is licensed under the MIT license.

some brief, high-level features include:
  • defining state machines on any javascript object or class (constructor)

  • state-driven instance behavior (methods and attributes)

  • hierarchical states (states could have parent/child relationships)

  • state (enter, exit) and transitions callbacks

  • flexible and very readable DSL based around states, events and transitions. design original based on pluginaweek/state_machine, but now it's slightly different ..

  • high code-coverage using the mocha test framework

  • written in 100% CoffeeScript

cheat sheet

sm = state_machine 'state', (state, event, transition) ->

   state.initial 'foo'

   state 'plah', ->

      one: -> yes
      two: -> no

   state 'bar', parent: 'plah', enter: (-> "onEnterBar"), exit: (-> "onExitBar"), ->

      one: -> no
      two: -> yes


   event 'boom', ->

      transition
         plah: foo
         bar: plah

      transition.from 'foo', to: 'bar', if: -> true, unless: -> false


   event 'bang', ->

      transition.from ['foo', 'bar'], to: 'bar', action: (oldState, newState) -> "..."

      transition.all except: 'bar', only: ['foo'], to: 'plah'



   sm.two = 2
   sm.boom three: 42

   sm.three is 42             # => yes
   sm.two()                   # => yes
   sm.state is 'bar'          # => yes
   sm.is_state('plah')        # => yes

FAQs

Package last updated on 01 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc