From ec88f94e787745e8043a17d9aae9aa77f9bb8e05 Mon Sep 17 00:00:00 2001 From: Niels van Hoorn Date: Wed, 14 Sep 2016 17:23:21 +0200 Subject: [PATCH] Added deprecated event support on states Signed-off-by: Niels van Hoorn --- framer/LayerStates.coffee | 3 +++ test/tests/LayerStatesTest.coffee | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) 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' + +