0.1.6 • Published 10 years ago

avs-statechart v0.1.6

Weekly downloads
1
License
MIT
Repository
-
Last release
10 years ago

Statechart API for Node

A Node.js module for working with David Harel's statecharts.

Installation

Install via npm

npm install avs-statechart

Usage overview

var Statechart = require('avs-statechart').Statechart
var State = require('avs-statechart').State

Basic description

A state is either active or inactive.
A state may have children states.
A state may be concurrent or not.
When entering a state:
  - the state becomes active,
  - its 'onEnter' method is triggered,
  - its first child is entered unless the state is concurrent (in which case all chidlren states are entered).
When exiting a state:
  - all active children are exited,
  - its 'onExit' method is triggered,
  - the state becomes inactive.
When active, the state 'onEvent' method is triggered each time an event is propagated through the statechart in a top-down way.

All events have a name.
Events are propagated (and consumed) by the statechart (cf. example below: stc.process name:'connect').
A statechart must contain an inital or root state.

Coffeescript example

stc = new Statechart new State
      name:'root'
      onExit: (event) => #do something
      children: [
        new State
          name:'waiting' 
          onEvent: (event) -> session if event.name is 'connect'
        session = new State
          name:'session'
          onEnter: (event) => #do something
          children: [
            idle = new State
              name:'idle'
              onEvent: (event) -> record if event.name is 'record'        
            record = new State
              name:'record'
              onEvent: (event) -> idle if event.name is 'record'        
              onEnter: (event) => #start recording
              onExit:  (event) => #stop  recording
          ] 
      ]
 ...
 stc.process name:'connect'
 stc.active()

Author

Gilles Gerlinger. Email me if you have any questions: gilles.gerlinger@gmail.com.

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago