metal.js icon indicating copy to clipboard operation
metal.js copied to clipboard

Feature request: Support finer custom events

Open yuchi opened this issue 7 years ago • 4 comments

Currently with registerCustomEvent you can define a rich alias for a “base event” (originalEvent).

A finer API should be added so that an attach and a detach methods should be passed in order for more complex events to be polyfilled. (This is just an idea, could be considered a bad practice and brittle API).

Examples are:

  • swipe requires more than a single touch* event
  • valuechange requires key* events and the onchange event

yuchi avatar Dec 12 '16 21:12 yuchi

An example from YUI, the valueChange event.

yuchi avatar Dec 13 '16 10:12 yuchi

As you can see the configuration is split in:

  • on, called when attaching the event directly on an element,
  • delegate, called when attaching an event as a delegate,
  • detach, called when detaching an event attached to an element,
  • detachDelegate, called when detaching a delegated event.

The full docs are here: http://yuilibrary.com/yui/docs/event/synths.html

yuchi avatar Dec 13 '16 10:12 yuchi

Let me state this more clearly: I’m not asking for such a feature. No other modern framework supports those AFAIK because it brings imperative stuff in a purely declarative context, which is a really bad thing!

For example, let’s say that in a valueChange synthetic event I need to add an attribute to an element. If in JSX i do <input on-valuechange={..} /> that menas that there’s something else modifying the DOM, which goes in contrast with assertions made by vdom and icd.

yuchi avatar Dec 13 '16 10:12 yuchi

Also such events should be quickly detached and reattached when using arrows:

class DropArea extends JSXComponent {
  render() {
    return (
      <input
        on-valueChange={ e => this.value = e.target.value }
        value={ this.value }
      />
    );
}

That means that the attach/detach methods should be guaranteed to be performant. Something we shouldn’t ask authors.

yuchi avatar Dec 13 '16 10:12 yuchi