Reactive setter callbacks automatically
rerun when local state changes.
In this example:
setState().
const counter =
document
.createElement("button")
// ===============================
// LOCAL STATE
// ===============================
.setState({
count: 0
})
// ===============================
// REACTIVE TEXT
// ===============================
.setText(({ state }) => {
return (
`Count: ${state.count}`
);
})
// ===============================
// REACTIVE STYLES
// ===============================
.setStyles(({ state }) => ({
background:
state.count % 2 === 0
? "black"
: "tomato",
transform:
`scale(${1 + state.count * 0.02})`
}))
// ===============================
// REACTIVE ATTRIBUTES
// ===============================
.setAttributes(({ state }) => ({
class:
"counter",
title:
`Current count: ${state.count}`
}))
// ===============================
// EVENTS
// ===============================
.setEvents(({ state, setState }) => ({
click() {
setState({
count:
state.count + 1
});
}
}));
app
.setChildren(
counter
);
setState()