https://github.com/icholy/statemachine
TypeScript version of SSM (with less magic).
https://github.com/icholy/statemachine
Last synced: over 1 year ago
JSON representation
TypeScript version of SSM (with less magic).
- Host: GitHub
- URL: https://github.com/icholy/statemachine
- Owner: icholy
- Created: 2015-03-13T15:54:17.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-03-13T20:04:01.000Z (over 11 years ago)
- Last Synced: 2025-01-30T03:13:10.491Z (over 1 year ago)
- Language: JavaScript
- Size: 227 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# StateMachine: [](https://travis-ci.org/icholy/StateMachine)
> State Machine
**Usage:**
``` js
// create instance
var machine = new StateMachine.StateMachine({
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.init("state1");
// invoke events
machine.emit("event1");
machine.emit("event2", "foo", "bar", "baz");
//get current state name
console.log(machine.current.name);
```