TodePond / Habitat

my javascript helpers
MIT License
45 stars 5 forks source link

`use` helper? #113

Closed TodePond closed 1 year ago

TodePond commented 1 year ago

or nah?

TodePond commented 1 year ago
const score = use(0)
const doubled = use(() => score.value * 2)
const tripled = use(() => score.value * 3, { lazy: true })

const position = use([5, 10])
const dimensions = use([20, 30], { store: false })
const bottom = use(() => position.y + dimensions.height)

const display = HTML("<div></div>")
use(() => display.textContent = score.value)

const player = use({ name: "Player" })
const card = HTML("<div></div>")
const signal = use(() => card.textContent = player.name, { lazy: true })
signal.update()

score.addEventListener("update", () => print("Score updated"))
TodePond commented 1 year ago

Done https://github.com/TodePond/Habitat/releases/tag/v1.2.2