question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event management and arrow function (v6)

See original GitHub issue

d3 version 6 has made significant changes to event management. It is no longer possible to use arrow function like this:

selection.on("mouseenter", (d, i, nodes) => {
    d3.select(nodes[i]);
});

This technique was used to replicate this:

selection.on("mouseenter", function() {
    d3.select(this);
});

D3 6.0 migration guide made no mention of how to use arrow function for event management when this is required.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
t3db0tcommented, Jan 6, 2021

Ah—thank you. Now I’m seeing that currentTarget works for start, but NOT for drag, but toElement does work for drag. Are any of these documented somewhere?

0reactions
mbostockcommented, Jan 6, 2021

@t3db0t For custom events such as d3-drag you’ll need event.sourceEvent.currentTarget.

Read more comments on GitHub >

github_iconTop Results From Across the Web

d3.js - Select element in drag event using arrow functions in v6
Is there a way to select the svg element within the arrow function to get a handle on the item within the drag...
Read more >
Arrow function expressions - JavaScript - MDN Web Docs
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate ...
Read more >
D3 6.0 migration guide - Observable
Note that event.currentTarget gives access to the element to which the listener is bound and can replace this in arrow functions:
Read more >
React Component - Docs - FullCalendar
It provides a component that exactly matches the functionality of FullCalendar's ... (arg) => { // bind with an arrow function alert(arg.
Read more >
Mongoose v6.8.2: Schemas
Do not declare methods using ES6 arrow functions ( => ). ... Mongoose will emit an index event on the model when indexes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found