1.0.4 • Published 4 years ago

xevents v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

xevents

Use DOM events everywhere.

Why

So you can write programs with event handling code that will work in node and the browser.

How

Use Event, CustomEvent and EventTarget globals if defined, otherwise fall back to local implementations.

Note on use in the browser: sure, it's wasteful to send unnecessary shims, but it's also cool if node code Just Works without requiring a build step... if a build step is used, optimizing this should be straightforward.

Example

import {
  Event,
  CustomEvent,
  EventTarget
} from 'xevent/index.js'

var emitter = new EventTarget()
emitter.addEventListener('custom-event', e => {
  console.log(e.type, e.detail, e instanceof Event, e)
})
var evt = new CustomEvent('custom-event', { detail: 42 })
emitter.dispatchEvent(evt)

Prior art

basicHTML, ungap.

License

MIT

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago