Permalink
Browse files

Added deprecated event support on states

Signed-off-by: Niels van Hoorn <nvh@nvh.io>
  • Loading branch information...
nvh committed Sep 14, 2016
1 parent 8c0992e commit ec88f94e787745e8043a17d9aae9aa77f9bb8e05
Showing with 34 additions and 0 deletions.
  1. +3 −0 framer/LayerStates.coffee
  2. +31 −0 test/tests/LayerStatesTest.coffee
@@ -77,6 +77,9 @@ class exports.LayerStates
for name, state of layer.states
keys = _.union(keys, _.keys(state))
keys
deprecatedProperty @, "on", "layer.on", stateMachine, (layer) ->
(name, handler) ->
layer.on(name, handler)
@filterStateProperties: (properties) ->
@@ -507,3 +507,34 @@ describe "LayerStates", ->
layerB.states.next(instant: true)
assert.equal layerB.y, 300
assert.equal layerB.x, 400
describe "Events", ->
beforeEach ->
@layer = new Layer()
@layer.states.add("a", {x:100, y:100})
@layer.states.add("b", {x:200, y:200})
it "should emit willSwitch when switching", (done) ->
test = (previous, current, states) =>
previous.should.equal 'initial'
current.should.equal 'a'
@layer.states.state.should.equal 'initial'
done()
@layer.states.on 'willSwitch', test
@layer.states.switchInstant 'a'
it "should emit didSwitch when switching", (done) ->
test = (previous, current, states) =>
previous.should.equal 'initial'
current.should.equal 'a'
@layer.states.state.should.equal 'a'
done()
@layer.states.on 'didSwitch', test
@layer.states.switchInstant 'a'

0 comments on commit ec88f94

Please sign in to comment.