https://github.com/icholy/ssm
simple state machine
https://github.com/icholy/ssm
Last synced: over 1 year ago
JSON representation
simple state machine
- Host: GitHub
- URL: https://github.com/icholy/ssm
- Owner: icholy
- Created: 2013-09-05T16:25:57.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-11-26T15:37:06.000Z (over 11 years ago)
- Last Synced: 2025-01-30T03:13:11.607Z (over 1 year 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: [](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