-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestexperimentalBreaking changes can happen at any timeBreaking changes can happen at any time
Description
Warning: this pattern is highly experimental
<render-scope>
<link top-level href=module.js>
<template shadowrootmode=closed>
<button :=counter>0</button>
<span :: text:=set:total>0</span>
</template>
</render-scope>function increment() { this.value++ }
export function counter(element) {
element ??= this ?? <button/>
element.addEventListener("click", increment)
return element
}👣 Footgun: how do you bind variable (i.e
total)?
export let total
// total += 1
// require compiler
// (maybe compile to class
// with @bind accessor
// for the sake of performance
// 😂)
export const total = {}
// total.value += 1
// works without compiler but weirdThe reason I'm interested in named export is because of handleEvent() pattern in class1
<render-scope>
<link top-level href=module.js>
<template shadowrootmode=closed>
<button :=Counter>0</button>
</template>
</render-scope>export class Counter {
value = 0
constructor(element = <button/>) {
element.addEventListener("click", this)
return Object.setPrototypeOf(element, new.target.prototype)
}
handleEvent(event) {
switch (event.type) {
case "click":
this.increment()
break
default:
this.value = +event.currentTarget.value
}
}
increment() { this.value++ }
}use module in other area or projects
import { Counter } from "./module.js"
for (const input of document.querySelectorAll("input.counter")) {
const counter = new Counter()
input.after(counter)
input.addEventListener("change", counter)
}Footnotes
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestexperimentalBreaking changes can happen at any timeBreaking changes can happen at any time