npm.io
1.0.0 • Published 4 years ago

with-events

Licence
MIT
Version
1.0.0
Deps
0
Size
84 kB
Vulns
0
Weekly
0

with-events

extends dispatchEvent for custom elements enabling onxxx prop and inline attribute eventhandlers

Install · Example · API docs · Releases · Contribute · Help


Install

$ npm i with-events

API

Table of Contents
withEvents

src/index.ts:33-53

Constructs a base factory with modified dispatchEvent that will invoke inline onxxx handlers as usual with HTML.

class Foo extends withEvents<{
  foo: CustomEvent<{ bar: string }>
}>(HTMLElement) {
  // your component here
}
customElements.define('x-foo', Foo)
const foo = new Foo()

// this is now typed properly
foo.onfoo = ({ detail }) => console.log(detail.bar)
foo.dispatchEvent(new CustomEvent('foo', { detail: { bar: 'hello' } }))
// console => 'hello'
Parameters
  • parent CustomElementConstructor A HTMLElement derived class

Contribute

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT 2022 stagas

Keywords