Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/icholy/ssm
simple state machine
https://github.com/icholy/ssm
Last synced: about 1 month ago
JSON representation
simple state machine
- Host: GitHub
- URL: https://github.com/icholy/ssm
- Owner: icholy
- Created: 2013-09-05T16:25:57.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-11-26T15:37:06.000Z (almost 10 years ago)
- Last Synced: 2024-10-03T15:19:34.734Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 352 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
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