Rook
РусскийRU

One state. Two updates.

Change a value and follow the pulse through its dependency graph. Only the DOM nodes that read it update; the independent label stays still.

Ready · count = 0

Rook source

comp Counter() {
    state count = 0
    return <main>
        <button onClick={count++}>{count}</button>
        <p>{count * 2}</p>
        <small>{"always here"}</small>
    </main>
}
document.body.append(<Counter />)

Dependency graph

statecount = 0
button text0
paragraph0

Live DOM preview

updated nodes flash

0

always here

Markup

Markup is an ordinary expression: <a href="/"> creates a real HTMLAnchorElement, with no virtual DOM. The syntax is that of JSX, but attribute names are the HTML ones: class, not className. Types are checked as well: <input> is an HTMLInputElement, and checked={1} is an error.

on* attributes hold code that runs on the event: onClick={save()} calls save on a click, not when the element is created. The variable event is available inside.

class also takes a list, which leaves out nulls: class={["tab", active ? "active" : null]}. A bool in aria-* becomes "true" or "false", as ARIA expects: aria-selected={active}.

// Markup is an expression that creates a real DOM element
const name = "Rook"
const link = <a href="#markup">Hello, {name}!</a>

// on* holds code that runs on the event, not when the element is created
let clicks = 0
const counter = <b>0</b>
const button = <button onClick={clicks++; counter.textContent = String(clicks)}>Click</button>

document.body.append(link, <p>{button} Clicks: {counter}</p>)

This is the first frame of our task board: a heading, a form for a new task and an empty list. We will make the rows components and connect them to task data next.

Inside {...} you can write ordinary if, forand switch: the elements in their blocks become the content.

const fruits = ["guava", "papaya", "lychee", "passion fruit"]

// if, for and switch inside {...}: the elements in their blocks become the content
document.body.append(<ul>
    {for i, fruit in fruits {
        if fruit.length > 5 {
            <li>{i + 1}. {fruit}</li>
        } else {
            <li><s>{fruit}</s>: a short name</li>
        }
    }}
</ul>)