with-events
v1.0.0
Published
extends dispatchEvent for custom elements enabling onxxx prop and inline attribute eventhandlers
Downloads
3
Readme
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
parent
CustomElementConstructor A HTMLElement derived class
Contribute
All contributions are welcome!
License
MIT © 2022 stagas