Permalink
Browse files

If we’re changing to the current state, but will change values, perfo…

…rm the transition
  • Loading branch information...
nvh committed Aug 1, 2016
1 parent e6df5eb commit f9d6ef337b914f8b6232919560a30247f36c05e0
Showing with 17 additions and 4 deletions.
  1. +7 −4 framer/Layer.coffee
  2. +10 −0 test/tests/LayerStatesTest.coffee
View
@@ -894,17 +894,20 @@ class exports.Layer extends BaseClass
animateToState: (stateName, options={}) ->
properties = @_stateMachine.switchTo stateName
if @_stateMachine.previousName is @_stateMachine.currentName
shouldChange = false
for property,value of properties
if @[property] != value
shouldChange = true
break
if not shouldChange
return null
finished = options.completion
options.completion = =>
# If we changed the state, we send the event that we did
if @_stateMachine.previousName isnt stateName
@_stateMachine.emit(Events.StateDidSwitch, @_stateMachine.previousName, @_stateMachine.currentName, @)
@_stateMachine.emit(Events.StateDidSwitch, @_stateMachine.previousName, @_stateMachine.currentName, @)
finished?()
@animateTo properties, options
animateTo: (properties,options={}) ->
if typeof properties == 'string'
stateName = properties
return @animateToState stateName, options
@@ -144,6 +144,16 @@ describe "LayerStates", ->
animation = layer.animateTo 'stateA', time: 0.05
assert.equal(animation,null)
it "should change to a state when the properties defined are not the current", (done) ->
layer = new Layer
layer.states.stateA = {x: 100}
layer.switchTo 'stateA'
layer.x = 150
layer.onStateDidSwitch ->
layer.x.should.equal 100
done()
animation = layer.animateTo 'stateA', time: 0.05
describe "Properties", ->
it "should bring back the 'initial' state values when using 'animateToNext'", (done) ->

0 comments on commit f9d6ef3

Please sign in to comment.