From 8695f71b06db3925574aa607d40b3da24b532a80 Mon Sep 17 00:00:00 2001 From: Niels van Hoorn Date: Mon, 3 Oct 2016 13:46:11 +0200 Subject: [PATCH] Cloning states before messing with their options Fixes https://github.com/motif/company/issues/2810 --- framer/LayerStateMachine.coffee | 2 +- test/tests/LayerStatesTest.coffee | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/framer/LayerStateMachine.coffee b/framer/LayerStateMachine.coffee index e92fb2ce7..ec138927c 100644 --- a/framer/LayerStateMachine.coffee +++ b/framer/LayerStateMachine.coffee @@ -39,7 +39,7 @@ class exports.LayerStateMachine extends BaseClass # Prep the properties and the options. The options come from the state, and can be overriden # with the function arguments here. - properties = @states[stateName] + properties = _.clone(@states[stateName]) options = _.defaults({}, options, properties.options) if properties.options stateNameA = @currentName diff --git a/test/tests/LayerStatesTest.coffee b/test/tests/LayerStatesTest.coffee index 6efa71684..3c5bd2b0a 100644 --- a/test/tests/LayerStatesTest.coffee +++ b/test/tests/LayerStatesTest.coffee @@ -543,6 +543,21 @@ describe "LayerStates", -> layer.states.current.name.should.equal "default" done() + it "should listen to animation options defined in a state", (done) -> + layer = new Layer + layer.animationOptions.time = 0.1 + layer.states.testA = {x: 200, options: curve: "spring"} + cycle = layer.stateCycle onEnd: -> + layer.states.current.name.should.equal "testA" + cycle2 = layer.stateCycle onEnd: -> + layer.states.current.name.should.equal "default" + cycle3 = layer.stateCycle onEnd: -> + layer.states.current.name.should.equal "testA" + done() + cycle3.options.curve.should.equal "spring" + cycle2.options.curve.should.equal "ease" + cycle.options.curve.should.equal "spring" + describe "Switch", -> it "should switch", ->