Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Cleaned up docs & comments

  • Loading branch information...
commit 5108b9b85e3746d035f580e74c74f16bbd823ea3 1 parent f975ab3
Ryan Munro authored
Showing with 27 additions and 28 deletions.
  1. +25 −21 README.md
  2. +2 −2 stategraph.js
  3. +0 −5 tests.js
46 README.md
View
@@ -1,9 +1,14 @@
-# Stategraphevented data structure for untangling state! [![Build Status](https://secure.travis-ci.org/munro/stategraph.png?branch=master)](http://travis-ci.org/munro/stategraph)
+# Stategraphevented data structure for untangling state! [![Build Status](https://secure.travis-ci.org/munro/stategraph.png?branch=master)](http://travis-ci.org/munro/stategraph)
Stategraphs are a great tool for managing state, it can be used to simplify
things such as game logic, or UI flow. This library provides evented states,
and nested graphing! Woah!
+Couple this library with [Slots](https://github.com/munro/slots) for a
+path of destruction! Allowing you to easily clean up bound events when leaving
+a state. Try using [`emitter.removeListener(event, listener)`](http://nodejs.org/api/events.html#events_emitter_removelistener_event_listener)
+if you don't believe me! :)
+
## Documentation
### Constructing
@@ -83,21 +88,20 @@ You can also create & bind your own custom events.
### Nested state
-To nest state, simply define your first state by calling
-`.state(String name, Function callback)` on your `State` object, and a
-`StateGraph` will be lazily mixed into your state! Giving you access to all
-the methods in the `StateGraph` prototype.
+To nest state, simply call the `state` method with a list of states you would
+like to define. Sub‑states will be entered with the entire list of state
+objects at the head of the arguments, so you can access any parent state.
graph.state('lobby', function (lobby) {
- lobby.state('host', function (host) {
- // host can kick
- });
+ // players can chat
+ });
- lobby.state('player', function (player) {
- // can't do much
- });
+ graph.state('lobby', 'host', function (lobby, host) {
+ // host can kick
+ });
- // players can chat
+ graph.state('lobby', 'player', function (lobby, player) {
+ // can't do anything other than chat
});
To move about nested graphs, you can use the `.go(String name)` method to go to
@@ -116,15 +120,15 @@ be used when moving to parent states.
## API
* `StateGraph`
- * `state(String name..., Function callback) -> State` — Define a state with a callback
- to be called when entered. Remember the `State` context is the first
- argument of the callback! This function returns the newly created `State`
- object.
- * `state(String name...) -> State` — Return the `State`, or sub‑`State`
+ * `state(String name..., Function callback) State` — Define a state with a
+ callback to be called when entered. Remember the `State` context is the
+ first argument of the callback! This function returns the newly created
+ `State` object.
+ * `state(String name...) State` — Return the `State`, or sub‑`State`
object by name
- * `state() -> State` — Return the current state.
- * `go(String name[, args...]) -> State` — Switch states, passing any args to the state
- callback. Returns the newly entered state.
+ * `state() State` — Return the current state.
+ * `go(String name[, args...]) State` — Switch states, passing any args to
+ the state callback. Returns the newly entered state.
* `end()` — Leave the current state, ending the graph. The graph can be
reentered at any time!
@@ -133,7 +137,7 @@ be used when moving to parent states.
* Lazily inherits `StateGraph` when the `state` method is called.
* `jump([args...])` — Jump to this state with a list of arguments,
recursively moving to the correct state for the parent graphs.
- * Events
+ * Events
* `enter` — Triggered when the graph enters this state, any arguments
used to move to this state are avaliable after the list of states.
* `leave` — Triggered when the graph leaves this state. The head of
4 stategraph.js
View
@@ -204,8 +204,8 @@ var StateGraph = (function (_, EventEmitter, StateGraph, State, State_prototype)
State.prototype = _.extend(Object.create(EventEmitter.prototype), State_prototype = {
/**
- * Placeholder method for lazily mixing in a sub-StateGraph.
- * @return {State} Newly created sub-state
+ * Placeholder method for lazily mixing in a subStateGraph.
+ * @return {State} Newly created substate
*/
state: function () {
// Lazy mixin a sub StateGraph
5 tests.js
View
@@ -198,8 +198,3 @@ test('test substates', function (t) {
t.end();
});
-
-
-test('test substates#2', function (t) {
- t.end();
-});
Please sign in to comment.
Something went wrong with that request. Please try again.