Skip to content
Permalink
Browse files

Cleanup LayerStates with just a few special properties

  • Loading branch information
nvh committed Jul 26, 2016
1 parent 2d8e0d3 commit 6c25ab8d8fb55f6c9dd6f45247b47e4b01ee9a1a
Showing with 17 additions and 37 deletions.
  1. +17 −37 framer/LayerStates.coffee
@@ -6,43 +6,23 @@

LayerStatesIgnoredKeys = ["ignoreEvents"]

class exports.LayerStates extends BaseClass


constructor: (layer,initial, states={}) ->
@_previousStates = []
for stateName,value of states
@[stateName] = value
@_layer = layer
initial ?= layer.props
@_currentName = 'initial'
@_initial = LayerStates.filterStateProperties(initial)
super

@define "initial",
enumerable: false
exportable: false
importable: false
get: -> @_initial

@define "current",
enumerable: false
exportable: false
importable: false
get: -> @[@_currentName]

@define "currentName",
enumerable: false
exportable: false
importable: false
get: -> @_currentName

emit: (args...) ->
super
# Also emit this to the layer with self as argument
@_layer.emit args...

@filterStateProperties = (properties) ->
readOnlyProperty = (object, name, enumerable, getter) ->
Object.defineProperty object, name,
configurable: true
enumerable: enumerable
get: getter
set: ->
throw new Error "You can't override special state '#{name}'"

class exports.LayerStates
constructor: (stateMachine) ->
readOnlyProperty @, "initial", true, -> stateMachine.initial
readOnlyProperty @, "previous", false, -> stateMachine.previous
readOnlyProperty @, "current", false, -> stateMachine.current
readOnlyProperty @, "previousName", false, -> stateMachine.previousName
readOnlyProperty @, "currentName", false, -> stateMachine.currentName

@filterStateProperties: (properties) ->

stateProperties = {}

0 comments on commit 6c25ab8

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