Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/icholy/ssm

simple state machine
https://github.com/icholy/ssm

Last synced: about 1 month ago
JSON representation

simple state machine

Awesome Lists containing this project

README

        

# SSM: [![Build Status](https://travis-ci.org/icholy/SSM.png?branch=master)](https://travis-ci.org/icholy/SSM)

> Simple State Machine

**Usage:**

``` js

// create instance
var machine = new SSM({ verbose: true, name: "MyStateMachine" });

// define states
machine.state("state1")

.on("event1", function () {
// do something
this.go("state2");
})

.on("event2", function (x, y, z) {
// do something
console.log("x:", x, "y:", y, "z:", z);
})

.on("enter", function () {
// special event that gets run when the state is entered
});

machine.state("state2")

.on("event2", function () {
// do something else
this.go("state1");
})

.on("exit", function () {
// special event that gets run when the state is exited
});

// set initial state
machine.initialize("state1");

// invoke events
machine.event1();
machine.event2("foo", "bar", "baz");

//get current state name
var name = machine.current();
console.log(name);
```

**Note:** the api is completely chainable