Navigation Menu

Skip to content

Commit

Permalink
Added deprecated event support on states
Browse files Browse the repository at this point in the history
Signed-off-by: Niels van Hoorn <nvh@nvh.io>
  • Loading branch information
nvh committed Sep 15, 2016
1 parent 8c0992e commit ec88f94
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions framer/LayerStates.coffee
Expand Up @@ -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) ->

Expand Down
31 changes: 31 additions & 0 deletions test/tests/LayerStatesTest.coffee
Expand Up @@ -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.