Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
[state] constructor adjustments for states and start, incl. tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strathausen committed Sep 28, 2012
1 parent 7c8574e commit 6eae977
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
25 changes: 24 additions & 1 deletion spec/plugins/scaleApp.state.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,33 @@ describe "stateMachine plugin", ->
transitions:
x: {from: "a", to: "b"}
y: {from: "b", to: "c"}
console.log JSON.stringify machine, null, 2
(expect machine.transitions.x).toEqual {from: "a", to: "b"}
(expect machine.transitions.y).toEqual {from: "b", to: "c"}

it "emits onEnter for start state", (done) ->
onEnter = (t, channel) ->
(expect channel).toBe 'a/enter'
(expect t).toBe undefined
done()
machine = new @scaleApp.StateMachine
start: 'a'
states:
a: {enter: onEnter}

it "registers onLeave for start state", (done) ->
onLeave = (t, channel) ->
(expect channel).toBe 'a/leave'
(expect t).toEqual {from: "a", to: "b"}
done()
machine = new @scaleApp.StateMachine
start: 'a'
states:
a: {leave: onLeave}
b: {}
transitions:
x: {from: "a", to: "b"}
machine.fire 'x'

describe "addState method", ->

it "takes a state id", ->
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/scaleApp.state.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ class StateMachine extends scaleApp.Mediator
@states = []
@transitions = {}
if opts.states?
@addState s for s in opts.states
@addState opts.states
if opts.start?
@addState opts.start
@start = opts.start
@current = opts.start
@emit enterChannel @start
if opts.transitions?
@addTransition id,t for id,t of opts.transitions

Expand Down

0 comments on commit 6eae977

Please sign in to comment.