Permalink
Browse files

Clone the animation options before modifying them

  • Loading branch information...
nvh committed Dec 15, 2016
1 parent d8c976d commit cc7f6c85acc8a5859cd4babf23e946f7e1e4cf50
Showing with 15 additions and 0 deletions.
  1. +1 −0 framer/LayerStateMachine.coffee
  2. +14 −0 test/tests/LayerStatesTest.coffee
@@ -42,6 +42,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 = _.clone(@states[stateName])
+ options = _.clone(options)
options = _.defaults({}, options, properties.animationOptions) if properties.animationOptions
delete properties.animationOptions
@@ -510,6 +510,20 @@ describe "LayerStates", ->
layer.states.current.name.should.equal "test"
done()
+ it "should not touch the options object", (done) ->
+ layer = new Layer
+ layer.states.test = {x: 200}
+ options = {time: 0.1}
+ layer.stateCycle(options)
+ layer.once Events.StateDidSwitch, ->
+ layer.x.should.equal 200
+ layer.states.current.name.should.equal "test"
+ layer.stateCycle(options)
+ layer.once Events.StateDidSwitch, ->
+ layer.x.should.equal 0
+ layer.states.current.name.should.equal "default"
+ done()
+
it "should cycle three with options", (done) ->
layer = new Layer
layer.animationOptions.time = 0.1

0 comments on commit cc7f6c8

Please sign in to comment.