feat: use standard event handler props
This commit is contained in:
parent
956424cbaf
commit
7bf37d75db
3 changed files with 5 additions and 13 deletions
|
@ -6,8 +6,8 @@ export class Counter extends WebComponent {
|
|||
};
|
||||
get template() {
|
||||
return html`
|
||||
<button on:click=${() => this.props.count = 'hey'}>
|
||||
${this.props.count}
|
||||
<button onclick=${() => ++this.props.count} style="background-color: black; color: white;">
|
||||
<span>${this.props.count}</span>
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "web-component-base",
|
||||
"version": "2.0.0-beta.12",
|
||||
"version": "2.0.0-beta.13",
|
||||
"description": "A zero-dependency, ~600 Bytes (minified & gzipped), JS base class for creating reactive custom elements easily",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
|
|
|
@ -7,16 +7,8 @@ export function createElement(tree) {
|
|||
return document.createTextNode(tree);
|
||||
} else {
|
||||
const el = document.createElement(tree.type);
|
||||
const eventAttrs = tree.props
|
||||
? Object.keys(tree.props)
|
||||
.filter((key) => key.startsWith("on:"))
|
||||
.map((key) => ({ key, cb: tree.props[key] }))
|
||||
: [];
|
||||
eventAttrs.forEach((onEvent) => {
|
||||
const { key, cb } = onEvent;
|
||||
const eventId = key.replace("on:", "");
|
||||
el.addEventListener(eventId, cb);
|
||||
});
|
||||
if (tree.props)
|
||||
Object.keys(tree.props).forEach(prop => el[prop] = tree.props[prop])
|
||||
tree.children?.forEach((child) => {
|
||||
const childEl = createElement(child);
|
||||
if (childEl) {
|
||||
|
|
Loading…
Reference in a new issue