1.0.0 • Published 2 years ago

with-events v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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