Permalink
Browse files

Merge branch 'master' of github.com:koenbok/framer

  • Loading branch information...
koenbok committed Sep 21, 2016
2 parents 5b3372d + 56f69e7 commit 8d9f4eaa90002bef5b3b5c3bd4421ee54e5b71d0
Showing with 39 additions and 46 deletions.
  1. +4 −19 framer/BaseClass.coffee
  2. +11 −3 framer/Layer.coffee
  3. +1 −1 package.json
  4. +18 −18 test/tests/BaseClassTest.coffee
  5. +3 −3 test/tests/ContextTest.coffee
  6. +2 −2 test/tests/LayerTest.coffee
View
@@ -9,9 +9,6 @@ DefinedPropertiesKey = "_DefinedPropertiesKey"
DefinedPropertiesValuesKey = "_DefinedPropertiesValuesKey"
DefinedPropertiesOrderKey = "_DefinedPropertiesOrderKey"
capitalizeFirstLetter = (string) ->
string.charAt(0).toUpperCase() + string.slice(1)
class exports.BaseClass extends EventEmitter
#################################################################
@@ -23,23 +20,11 @@ class exports.BaseClass extends EventEmitter
if @ isnt BaseClass
@_addDescriptor(propertyName, descriptor)
# Set the getter/setter as setProperty on this object so we can access and override it easily
getName = "get#{capitalizeFirstLetter(propertyName)}"
@::[getName] = descriptor.get
descriptor.get = @::[getName]
if descriptor.set
setName = "set#{capitalizeFirstLetter(propertyName)}"
@::[setName] = descriptor.set
descriptor.set = @::[setName]
# Better readonly errors for debugging
# else
# descriptor.set = (value) ->
# throw Error("#{@constructor.name}.#{propertyName} is readonly")
if not descriptor.set?
descriptor.set = (value) ->
throw Error("#{@constructor.name}.#{propertyName} is readonly")
# Define the property
# Define the property on the prototype
Object.defineProperty(@prototype, propertyName, descriptor)
@_addDescriptor: (propertyName, descriptor) ->
View
@@ -50,6 +50,11 @@ layerProperty = (obj, name, cssProperty, fallback, validator, transformer, optio
@_element.style[cssProperty] = LayerStyle[cssProperty](@)
set?(@, value)
# We try to not send any events while we run the constructor, it just
# doesn't make sense, because no one can listen to use yet.
return if @__constructor
@emit("change:#{name}", value)
@emit("change:point", value) if name in ["x", "y"]
@emit("change:size", value) if name in ["width", "height"]
@@ -79,8 +84,9 @@ class exports.Layer extends BaseClass
constructor: (options={}) ->
# Make sure we never call the constructor twice
throw Error("Layer.constructor #{@toInspect()} called twice") if @__constructed
@__constructed = true
throw Error("Layer.constructor #{@toInspect()} called twice") if @__constructorCalled
@__constructorCalled = true
@__constructor = true
# Set needed private variables
@_properties = {}
@@ -136,6 +142,8 @@ class exports.Layer extends BaseClass
@_stateMachine = new LayerStateMachine(@)
@_context.emit("layer:create", @)
delete @__constructor
##############################################################
# Properties
@@ -777,7 +785,7 @@ class exports.Layer extends BaseClass
# If there is no parent we need to walk through the root
if @parent is null
return _.filter @_context.getLayers(), (layer) =>
return _.filter @_context.layers, (layer) =>
layer isnt @ and layer.parent is null
return _.without @parent.children, @
View
@@ -24,7 +24,7 @@
"coverage-capture": "./test/coverage-capture",
"eventemitter3": "^1.1.1",
"gulp": "^3.8.11",
"gulp-mocha-phantomjs": "^0.10.1",
"gulp-mocha-phantomjs": "^0.11.0",
"gulp-plumber": "^1.0.1",
"gulp-rename": "^1.2.2",
"gulp-template": "^4.0.0",
@@ -107,29 +107,29 @@ describe "BaseClass", ->
testClass = new TestClass3()
testClass.keys().should.eql ["testA", "testB"]
it "should create getters/setters", ->
# it "should create getters/setters", ->
class TestClass4 extends Framer.BaseClass
@define "testA", @simpleProperty "testA", 100
# class TestClass4 extends Framer.BaseClass
# @define "testA", @simpleProperty "testA", 100
testClass = new TestClass4()
testClass.setTestA(500)
testClass.getTestA().should.equal 500
testClass.testA.should.equal 500
# testClass = new TestClass4()
# testClass.setTestA(500)
# testClass.getTestA().should.equal 500
# testClass.testA.should.equal 500
it "should override getters/setters", ->
# it "should override getters/setters", ->
class TestClass5 extends Framer.BaseClass
@define "testA", @simpleProperty "testA", 100
# class TestClass5 extends Framer.BaseClass
# @define "testA", @simpleProperty "testA", 100
class TestClass6 extends TestClass5
setTestA: (value) ->
super value * 10
# class TestClass6 extends TestClass5
# setTestA: (value) ->
# super value * 10
testClass = new TestClass6()
testClass.setTestA(500)
testClass.getTestA().should.equal 5000
testClass.testA.should.equal 5000
# testClass = new TestClass6()
# testClass.setTestA(500)
# testClass.getTestA().should.equal 5000
# testClass.testA.should.equal 5000
it "should work with proxyProperties", ->
@@ -186,7 +186,7 @@ describe "BaseClass", ->
get: () -> "value"
instance = new TestClass()
(-> instance.testProp = "foo").should.throw "setting a property that has only a getter"
(-> instance.testProp = "foo").should.throw "TestClass.testProp is readonly"
it "should not set read-only prop via props setter", ->
@@ -219,7 +219,7 @@ describe "Context", ->
context = new Framer.Context(name:"Test")
context.on "layer:create", ->
context.getLayers().length.should.equal 1
context.layers.length.should.equal 1
callback()
context.run ->
@@ -231,10 +231,10 @@ describe "Context", ->
context = new Framer.Context(name:"Test")
context.on "layer:create", ->
context.getLayers().length.should.equal 1
context.layers.length.should.equal 1
context.on "layer:destroy", ->
context.getLayers().length.should.equal 0
context.layers.length.should.equal 0
callback()
context.run ->
@@ -525,7 +525,7 @@ describe "Layer", ->
layer.shadowBlur.should.equal 10
layer.shadowSpread.should.equal 10
layer.style.boxShadow.should.equal "rgba(123, 123, 123, 0.496094) 10px 10px 10px 10px"
layer.style.boxShadow.should.equal "rgba(123, 123, 123, 0.498039) 10px 10px 10px 10px"
# Only after we set a color a shadow should be drawn
layer.shadowColor = "red"
@@ -982,7 +982,7 @@ describe "Layer", ->
layer = new Layer
layer.destroy()
(layer in Framer.CurrentContext.getLayers()).should.be.false
(layer in Framer.CurrentContext.layers).should.be.false
assert.equal layer._element.parentNode, null
it "should set text", ->

0 comments on commit 8d9f4ea

Please sign in to comment.