Skip to content
Permalink
Browse files

Add context functions

rootLayer, layerForId, layerForElement
  • Loading branch information...
koenbok committed Apr 30, 2016
1 parent 4cf5611 commit 645653b4c95aa97f8f3150cf0e682bd67e577144
Showing with 58 additions and 0 deletions.
  1. +10 −0 framer/Context.coffee
  2. +48 −0 test/tests/ContextTest.coffee
@@ -79,6 +79,7 @@ class exports.Context extends BaseClass
# Layers
@define "layers", get: -> _.clone(@_layers)
@define "layerCounter", get: -> @_layerCounter
@define "rootLayers", get: -> _.filter @_layers, (layer) -> layer.parent is null

addLayer: (layer) ->
return if layer in @_layers
@@ -93,6 +94,15 @@ class exports.Context extends BaseClass
@_layers = []
@_layerCounter = 0

layerForElement: (element) ->
for layer in @_layers
return layer if layer._element is element
return null

layerForId: (layerId) ->
for layer in @_layers
return layer if layer.id is layerId
return null

# Animations
@define "animations", get: -> _.clone(@_animations)
@@ -160,6 +160,54 @@ describe "Context", ->
context.timers.should.eql []


describe "Layers", ->

it "should add and remove layers", ->

context = new Framer.Context(name:"Test")

context.run ->

layerA = new Layer
layerB = new Layer
layerC = new Layer
layerD = new Layer

context.layers.should.eql [layerA, layerB, layerC, layerD]
_.invoke(context.layers, "destroy")
context.layers.should.eql []

it "should list root layers", ->

context = new Framer.Context(name:"Test")

context.run ->

layerA = new Layer
layerB = new Layer parent:layerA

context.rootLayers.should.eql [layerA]
layerB.parent = null
context.rootLayers.should.eql [layerA, layerB]

it "should get layers by id", ->

context = new Framer.Context(name:"Test")

context.run ->
layerA = new Layer
context.layerForId(layerA.id).should.equal layerA

it "should get layers by element", ->

context = new Framer.Context(name:"Test")

context.run ->
layerA = new Layer
context.layerForElement(layerA._element).should.equal layerA



describe "Events", ->

it "should emit reset", (callback) ->

0 comments on commit 645653b

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