Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for multiple event types to View#delegate. #206

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2012
  1. @paulmillr
Commits on Oct 1, 2012
  1. @molily

    Add a test

    molily authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 4 deletions.
  1. +4 −3 src/chaplin/views/view.coffee
  2. +13 −1 test/spec/view_spec.coffee
View
7 src/chaplin/views/view.coffee
@@ -142,17 +142,18 @@ define [
'handler argument must be function'
# Add an event namespace
- eventType += ".delegate#{@cid}"
+ list = ("#{event}.delegate#{@cid}" for event in eventType.split(' '))
+ events = list.join(' ')
# Bind the handler to the view
handler = _(handler).bind(this)
if selector
# Register handler
- @$el.on eventType, selector, handler
+ @$el.on events, selector, handler
else
# Register handler
- @$el.on eventType, handler
+ @$el.on events, handler
# Return the bound handler
handler
View
14 test/spec/view_spec.coffee
@@ -121,7 +121,7 @@ define [
view.render()
expect(spy).was.called()
- it 'should register user input events', ->
+ it 'should register and remove user input event handlers', ->
expect(view.delegate).to.be.a 'function'
expect(view.undelegate).to.be.a 'function'
@@ -148,6 +148,18 @@ define [
p.trigger 'click'
expect(spy.callCount).to.be 1
+ it 'should register and remove multiple user input event handlers', ->
+ spy = sinon.spy()
+ handler = view.delegate 'click keypress', spy
+ $(view.el).trigger 'click'
+ $(view.el).trigger 'keypress'
+ expect(spy).was.calledTwice()
+
+ view.undelegate()
+ $(view.el).trigger 'click'
+ $(view.el).trigger 'keypress'
+ expect(spy).was.calledTwice()
+
it 'should check delegate parameters', ->
expect(-> view.delegate()).to.throwError()
expect(-> view.delegate(1, 2, 3)).to.throwError()
Something went wrong with that request. Please try again.