"use strict"; var Subscribable = require("./subscribable"); var StateMachine = Subscribable.inherit({ className: "StateMachine", constructor: function (initialState, graph) { Subscribable.fn.constructor.call(this); this._state = initialState; this._graph = graph; }, manipulation: function (name) { var newState = this._graph[this._state][name]; if (newState) { var oldState = this._state; this._state = newState; this.trigger("stateChanged", { newState: newState, manipulation: name, oldState: oldState }); } else { this.trigger("stateMissed"); } }, state: function () { return this._state; } }); module.exports = StateMachine;