nanomorph icon indicating copy to clipboard operation
nanomorph copied to clipboard

Replace events.js to be more interop

Open tunnckoCore opened this issue 7 years ago • 4 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.

tunnckoCore avatar Jun 22 '18 16:06 tunnckoCore

Haha, actually they are 98. ;d

tunnckoCore avatar Jun 23 '18 02:06 tunnckoCore

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)

See https://github.com/Tram-One/tatermorph/pull/1/, https://github.com/Tram-One/belit/pull/10

JRJurman avatar Jun 24 '18 04:06 JRJurman

Hm yea, this sounds like a good idea too.

tunnckoCore avatar Jun 24 '18 11:06 tunnckoCore

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)

JRJurman avatar Jun 24 '18 21:06 JRJurman