metal.js
metal.js copied to clipboard
Feature request: Support finer custom events
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 singletouch*
event -
valuechange
requireskey*
events and theonchange
event
An example from YUI, the valueChange
event.
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
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.
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.