X04
Error
State and reactivity
X04 — A derived value that changes something
A derived value is worked out whenever what it reads changes, as often as the page needs it; one that calls an action that assigns changes state each time it is read.
What the compiler said
error[X04]: `ticket` is worked out by calling `next(…)`, which assigns `count` --> src/App.wf:7:5 | 7 | derived ticket = next() | ^^^^^^^^^^^^^^^^^^^^^^^ = help: A derived value only reads; call the action from a handler, and derive from what it sets = docs: https://webfluent.monzeromer.dev/errors/X04
The fix
Broken
page P(path: "/", title: "T", description: "D") {
state count = 0
action next() -> Number {
count = count + 1
return count
}
derived ticket = next()
Heading("Ticket {ticket}").h1
}
Fixed
page P(path: "/", title: "T", description: "D") {
state count = 0
action next() -> Number {
count = count + 1
return count
}
derived ticket = count
Heading("Ticket {ticket}").h1
Button("Next") { on click { next() } }
}
Call the action from a handler; derive from the state it sets.
Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).
lints cannot lower it: it would ship a broken page.