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.

Remove `.call()` in EventDispatcher

See original GitHub issue

Context

EventDispatcher currently use the .call() to execute their callbacks, this causes some problems because the this is being replaced in the callback context with the Event’s target as this

image

image

Proposal

  1. Replace these 2 sections of code with a simple callback to even
this._handlers[eventName][i].call(target, event);
// to
this._handlers[eventName][i](event);

and

handler.call(ev.target, ev);
// to
handler(ev);
  1. New unit tests required to ensure the “handlers” this is as expected in both paths

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
nidblecommented, Oct 12, 2021

Hi @eonarheim, yep why not!?

1reaction
eonarheimcommented, Oct 10, 2021

Hi @nidble, good point this does introduce a breaking change, which will be okay for the v0.26 release. This change should be added it to the breaking changes section of the changelog.

Let me know if you are still open to working this issue, since the scope has increased from what we originally thought. This will require some refactoring of tests and possibly other engine code that is relying on the previous behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

removeListener | EventDispatcher.php | Drupal 8.2.x
public function EventDispatcher::removeListener ... Removes an event listener from the specified events. ... 1 call to EventDispatcher::removeListener().
Read more >
The EventDispatcher Component (Symfony Docs)
The Symfony EventDispatcher component implements the Mediator and Observer ... A call to the dispatcher's addListener() method associates any valid PHP ...
Read more >
EventDispatcher - OpenTok.js | Vonage Video API Developer
(When you use the on() method to add an event handler, the handler is not removed when it is called.) The once() method...
Read more >
openfl.events.IEventDispatcher - API Reference
When you no longer need an event listener, remove it by calling EventDispatcher.removeEventListener() ; otherwise, memory problems might result.
Read more >
Cannot call method from the event dispatcher thread [duplicate]
I'm writing a program that records user mouse movement and clicks, and the plays them using the Robot class. I am running into...
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