Permalink
Browse files

Fixes #169

  • Loading branch information...
koenbok committed Feb 2, 2015
1 parent f6abac2 commit 5f361891ac39845d25911f3e708f65b1d17fdcef
Showing with 27 additions and 2 deletions.
  1. +13 −2 framer/Layer.coffee
  2. +14 −0 test/tests/LayerTest.coffee
@@ -755,15 +755,15 @@ class exports.Layer extends BaseClass
eventNames = [eventNames] if typeof eventNames == 'string'
# # Listen to dom events on the element
# Listen to dom events on the element
for eventName in eventNames
do (eventName) =>
super eventName, listener
@_context.eventManager.wrap(@_element).addEventListener(eventName, listener)
@_eventListeners ?= {}
@_eventListeners[eventName] ?= []
@_eventListeners[eventName].push listener
@_eventListeners[eventName].push(listener)
# We want to make sure we listen to these events, but we can safely
# ignore it for change events
@@ -788,6 +788,17 @@ class exports.Layer extends BaseClass
if @_eventListeners
@_eventListeners[eventName] = _.without @_eventListeners[eventName], listener
once: (eventName, listener) ->
originalListener = listener
listener = (args...) =>
originalListener(args...)
@removeListener(eventName, listener)
@addListener(eventName, listener)
removeAllListeners: ->
return if not @_eventListeners
@@ -424,6 +424,20 @@ describe "Layer", ->
clickCount.should.equal 1
it "should only run an event once", ->
layerA = new Layer
count = 0
layerA.once "hello", (layer) ->
count++
layerA.should.equal layer
for i in [0..10]
layerA.emit("hello")
count.should.equal 1
describe "Hierarchy", ->

0 comments on commit 5f36189

Please sign in to comment.