Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace events.js to be more interop #104

Open
tunnckoCore opened this issue Jun 22, 2018 · 4 comments
Open

Replace events.js to be more interop #104

tunnckoCore opened this issue Jun 22, 2018 · 4 comments

Comments

@tunnckoCore
Copy link

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
Copy link
Author

Haha, actually they are 98. ;d

@JRJurman
Copy link

JRJurman commented Jun 24, 2018

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 Tram-One#1, Tram-One/nanohtml#10

@tunnckoCore
Copy link
Author

Hm yea, this sounds like a good idea too.

@JRJurman
Copy link

JRJurman commented Jun 24, 2018

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants