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
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
parentCustomElementConstructor A HTMLElement derived class
Contribute
All contributions are welcome!
License
MIT 2022 stagas