Skip to content
Permalink
Browse files

Fixes #69

State Machine now defaults to Framer.Defaults.Animation if no animationOptions are set.
  • Loading branch information...
koenbok committed May 15, 2014
1 parent bb15649 commit 30e688e09b10faf7c4ed275a62cc032650ef9786
Showing with 37 additions and 10 deletions.
  1. +9 −10 framer/LayerStates.coffee
  2. +28 −0 test/tests/LayerStatesTest.coffee
@@ -2,6 +2,7 @@

{Events} = require "./Events"
{BaseClass} = require "./BaseClass"
{Defaults} = require "./Defaults"

LayerStatesIgnoredKeys = ["ignoreEvents"]

@@ -16,8 +17,7 @@ class exports.LayerStates extends BaseClass
@_states = {}
@_orderedStates = []

@animationOptions =
curve: "spring"
@animationOptions = {}

# Always add the default state as the current
@add "default", @layer.properties
@@ -69,26 +69,25 @@ class exports.LayerStates extends BaseClass

animationOptions ?= @animationOptions
animationOptions.properties = {}

animatingKeys = @animatingKeys()

for k, v of @_states[stateName]
for propertyName, value of @_states[stateName]

# Don't animate ignored properties
if k in LayerStatesIgnoredKeys
if propertyName in LayerStatesIgnoredKeys
continue

if k not in animatingKeys
if propertyName not in animatingKeys
continue

# Allow dynamic properties as functions
v = v.call(@layer, @layer, stateName) if _.isFunction(v)
value = value.call(@layer, @layer, stateName) if _.isFunction(value)

animationOptions.properties[k] = v
animationOptions.properties[propertyName] = value

animation = @layer.animate animationOptions
@_animation = @layer.animate animationOptions

animation.on "stop", =>
@_animation.on "stop", =>
@emit Events.StateDidSwitch, _.last(@_previousStates), stateName, @

switchInstant: (stateName) ->
@@ -1,6 +1,7 @@
describe "LayerStates", ->

describe "Events", ->

beforeEach ->
@layer = new Layer()
@layer.states.add 'a', x: 100, y: 100
@@ -27,3 +28,30 @@ describe "LayerStates", ->

@layer.states.on 'didSwitch', test
@layer.states.switchInstant 'a'

describe "Defaults", ->

it "should set defaults", ->

layer = new Layer
layer.states.add "test", {x:123}
layer.states.switch "test"

layer.states._animation.options.curve.should.equal Framer.Defaults.Animation.curve

Framer.Defaults.Animation =
curve: "spring(1, 2, 3)"

layer = new Layer
layer.states.add "test", {x:456}
layer.states.switch "test"

layer.states._animation.options.curve.should.equal "spring(1, 2, 3)"

Framer.resetDefaults()



# describe "Switch", ->

# it "should switch instant", (done) ->

0 comments on commit 30e688e

Please sign in to comment.
You can’t perform that action at this time.