Skip to content

Commit

Permalink
Revise the compatibility structure
Browse files Browse the repository at this point in the history
So you can still call superView on layers but you get a warning
  • Loading branch information
koenbok committed May 11, 2014
1 parent 07fb822 commit 17fa857
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
16 changes: 10 additions & 6 deletions extras/CactusFramer/static/app.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
layer = new Layer
layerA = new Layer
width: 250
height: 300
midX: 200
clip: true

layer.on Events.MouseOver, (event, layer) ->
layer.backgroundColor = "red"

layer.on Events.MouseOut, (event, layer) ->
layer.backgroundColor = "green"
layerB = new Layer
y: layerA.maxY-20
height: 100
width: layerA.width
superLayer: layerA
24 changes: 19 additions & 5 deletions framer/Compat.coffee
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{Layer} = require "./Layer"

compatWarning = (msg) ->
console.warn msg

compatProperty = (name) ->
exportable: false
get: -> @[name]
set: (value) -> @[name] = value
get: ->
compatWarning "#{name} is a deprecated property"
@[name]
set: (value) ->
compatWarning "#{name} is a deprecated property"
@[name] = value

class CompatView extends Layer
class CompatLayer extends Layer

constructor: (options={}) ->

console.debug "CompatView.constructor: Views are now called Layers"

if options.hasOwnProperty "superView"
options.superLayer = options.superView

Expand All @@ -23,13 +28,22 @@ class CompatView extends Layer
addSubView = (layer) -> @addSubLayer layer
removeSubView = (layer) -> @removeSubLayer layer

class CompatView extends CompatLayer

constructor: (options={}) ->
compatWarning "Views are now called Layers"
super options

class CompatImageView extends CompatView

class CompatScrollView extends CompatView
constructor: ->
super
@scroll = true

window.Layer = CompatLayer
window.Framer.Layer = CompatLayer

window.View = CompatView
window.ImageView = CompatImageView
window.ScrollView = CompatScrollView
Expand Down
9 changes: 9 additions & 0 deletions test/tests/CompatTest.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ describe "Compat", ->
viewB.superView.should.equal viewA
viewB.superLayer.should.equal viewA

it "should set superview on layer", ->

layerA = new Layer
layerB = new Layer

layerB.superView = layerA
layerB.superView.should.equal layerA
layerB.superLayer.should.equal layerA

it "should set superview on create", ->

viewA = new View
Expand Down

0 comments on commit 17fa857

Please sign in to comment.