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.

Support for handleEvent DOM interface

See original GitHub issue

Reproduction

class Foo {
  click(e) {
	this.setState({ clicked: true })
  }

  handleEvent(e) {
    // nicety: `this` is the component
    this[e.type](e)
  }
  render() {
    return <button onClick={this} />
  }
}

Steps to reproduce

Click the button.

Expected Behavior

handleEvent is used and doesn’t throw an error.

Actual Behavior

this.l[e.type](P.event ? P.event(e) : e) throws an error, as this.l[e.type] is this.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
marvinhagemeistercommented, Mar 2, 2020

That’s interesting! First time I’ve heard of it. If you can’t wait, you can patch that into Preact via an option hook:

import { options } from "preact";

let oldVNode = options.vnode;
options.vnode = vnode => {
  const { type, props } = vnode;

  // Only check DOM nodes
  if (typeof type === "string") {
    for (const name in props) {
      const value = props[name];
      if (value && typeof value.handleEvent === "function") {
        props[name] = value.handleEvent;
      }
    }
  }
  if (oldVNode) oldVNode(vnode);
};
1reaction
developitcommented, Mar 2, 2020

Definitely! I can throw a PR together that should at least show the rough outline of what we are proposing here, then we can go from there?

Read more comments on GitHub >

github_iconTop Results From Across the Web

DOM handleEvent: a cross-platform standard since year 2000
The handleEvent ABC is that any object that implements such method will be invoked as obj.handleEvent(event) once the event happens. The method can...
Read more >
EventTarget.addEventListener() - Web APIs | MDN
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered ...
Read more >
1. Document Object Model Events
The User Interface event module is composed of events listed in HTML 4.0 and additional events which are supported in DOM Level 0...
Read more >
Support handleEvent / DOM method names · Issue #31 - GitHub
Support handleEvent / DOM method names #31. Open. bcomnes opened this issue on May 12, ... for some reasons why this is an...
Read more >
EventListener (Java Platform SE 7 ) - Oracle Help Center
The EventListener interface is the primary method for handling events. Users implement the EventListener interface and register their listener on an ...
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 Hashnode Post

No results found