Skip to content

Commit

Permalink
Possible solution for Olical#19.
Browse files Browse the repository at this point in the history
I'm not sure this is the best solution. It does appear to work,
but this solution may have some unintended consequences.
  • Loading branch information
futuraprime committed Nov 3, 2015
1 parent 0e89619 commit 0e43147
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ Element.prototype.toReact = function (index) {
var props = clone(this.props)
props.style = clone(props.style)

var data = this.__data__

function uniqueKey () {
return 'faux-dom-' + index
}
Expand All @@ -257,7 +259,7 @@ Element.prototype.toReact = function (index) {
}

mapValues(listeners, function (listener) {
listener(event)
listener.call({ '__data__': data }, event)
})
}
}))
Expand Down
16 changes: 16 additions & 0 deletions test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,19 @@ test('removing listeners', function (t) {
t.plan(1)
t.equal(eventListeners.onClick.length, 0)
})

test('event listeners on children', function (t) {
var el = mk()
var datum = { property: 'value' }
var clickValue = 'initial'
var join = el.selectAll('.foo')
.data([datum])
join.enter().append('svg:rect').classed('foo', true)
.attr('id', 'foo')
join.on('click', function (d) {
clickValue = d
})
el.node().getElementById('foo').toReact().props.onClick()
t.plan(1)
t.equal(clickValue, datum)
})

0 comments on commit 0e43147

Please sign in to comment.