Replace events.js to be more interop
tunnckoCore opened this issue · comments
Something like this
let events = []
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
// eslint-disable-next-line
for (const key in document) {
const isEvent = document[key] == null || typeof document[key] === 'function'
if (key.startsWith('on') && isEvent) {
events.push(key)
}
}
} else {
events = [
'onreadystatechange',
'onpointerlockchange',
'onpointerlockerror',
'onbeforecopy',
'onbeforecut',
'onbeforepaste',
'oncopy',
'oncut',
'onpaste',
'onsearch',
'onselectionchange',
'onselectstart',
'onvisibilitychange',
'onabort',
'onblur',
'oncancel',
'oncanplay',
'oncanplaythrough',
'onchange',
'onclick',
'onclose',
'oncontextmenu',
'oncuechange',
'ondblclick',
'ondrag',
'ondragend',
'ondragenter',
'ondragleave',
'ondragover',
'ondragstart',
'ondrop',
'ondurationchange',
'onemptied',
'onended',
'onerror',
'onfocus',
'oninput',
'oninvalid',
'onkeydown',
'onkeypress',
'onkeyup',
'onload',
'onloadeddata',
'onloadedmetadata',
'onloadstart',
'onmousedown',
'onmouseenter',
'onmouseleave',
'onmousemove',
'onmouseout',
'onmouseover',
'onmouseup',
'onmousewheel',
'onpause',
'onplay',
'onplaying',
'onprogress',
'onratechange',
'onreset',
'onresize',
'onscroll',
'onseeked',
'onseeking',
'onselect',
'onstalled',
'onsubmit',
'onsuspend',
'ontimeupdate',
'ontoggle',
'onvolumechange',
'onwaiting',
'onwheel',
'onauxclick',
'ongotpointercapture',
'onlostpointercapture',
'onpointerdown',
'onpointermove',
'onpointerup',
'onpointercancel',
'onpointerover',
'onpointerout',
'onpointerenter',
'onpointerleave',
'onwebkitfullscreenchange',
'onwebkitfullscreenerror',
'onsecuritypolicyviolation',
'onformdata',
'onfullscreenchange',
'onfullscreenerror',
'onfreeze',
'onresume'
]
}
module.exports = events
Also, currently, there are only 45 event names, but as of today it seems they are 95. As, probably no so common or used, but why not. Also it will decrease the bundle sizes, and will use this list only on server.
Haha, actually they are 98. ;d
Something Tram-One does in it's fork of nanomorph is take in a function which should supply a list of events. This allows frameworks to keep track of their own list of events, or apps to provide which events should be kept track of.
At worse, most apps provide a hard-coded list of events, which should have the same performance as the current implementation, but allows consumers to append new events.
At best, frameworks can keep track of events, in the same way jQuery does (with it's own event attachers) or Tram-One does (using belit
to attach a .events
to each DOM element)
Hm yea, this sounds like a good idea too.
I'd be willing to make a PR for these changes against nanomorph if people were interested. It wouldn't even have to be breaking (we could have a default list that might be tree shaken out, depending on how the final bundling works)