Skip to content

Commit

Permalink
should not spread event arguments, and should set index
Browse files Browse the repository at this point in the history
  • Loading branch information
pemrouz committed Mar 5, 2016
1 parent cbb0a39 commit 0e2deb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function once(nodes, enter, exit) {
: [nodes]

var p = n.length
while (p-- > 0) if (!n[p].evented) event(n[p])
while (p-- > 0) if (!n[p].evented) event(n[p], p)

c.node = function() { return n[0] }
c.enter = function() { return once(enter) }
Expand Down Expand Up @@ -191,7 +191,7 @@ function once(nodes, enter, exit) {

}

function event(node) {
function event(node, index) {
if (!node.on) emitterify(node)
var on = node.on
, emit = node.emit
Expand All @@ -214,7 +214,7 @@ function event(node) {
window.event = event || window.event
if ('object' === typeof window.d3) window.d3.event = event
var isCustom = event.constructor.name === 'CustomEvent' || ~(event.toString().indexOf('CustomEvent'))
emit(event.type, (isCustom && event.detail) || this.__data__)
emit(event.type, [(isCustom && event.detail) || this.__data__, index])
}
}

Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,17 @@ describe('once', function() {
})

el.emit('foo', 'bar')
})

it('should not spread event arguments, and should set index', function(){
var el = once(node)('li', [1, 2, 3])

el.on('foo', function(d, i){
expect(d).to.be.eql(['a', 'b', 'c'])
expect(i).to.be.eql(1)
})

el.nodes[1].emit('foo', ['a', 'b', 'c'])
})

})
Expand Down

0 comments on commit 0e2deb5

Please sign in to comment.