diff --git a/framer/LayerStates.coffee b/framer/LayerStates.coffee index 2dc55e186..5cc6a5eeb 100644 --- a/framer/LayerStates.coffee +++ b/framer/LayerStates.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) -> diff --git a/test/tests/LayerStatesTest.coffee b/test/tests/LayerStatesTest.coffee index 881914510..d2aff81c0 100644 --- a/test/tests/LayerStatesTest.coffee +++ b/test/tests/LayerStatesTest.coffee @@ -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' + +