weft
ir 2.6.0 · warp 1.8.0
Part three · Step 12 of 19

Signals, and what the client adopts

Client-owned state in the template, and adoption that binds what is already painted instead of rendering it again.

Goal

Add a quantity control that updates in place, and read what the client attached to do it — one binding per value that moves, and no component code at all.

Some state never needs the server. A quantity stepper beside each row is the reader’s, until they commit it. That is a signal: a value the template declares, the client owns, and the server renders an initial value for.

1 · Declare the signal

sketch — not compiled
// app/fragments/qty.tsx
import { fragment, signal } from '@weftjs/core'

export default fragment(({ sku }: { sku: string }) => {
  const qty = signal(1)
  return (
    <span class="qty">
      <button on:click={() => qty.set(qty() - 1)}>−</button>
      <input value={qty} />
      <button on:click={() => qty.set(qty() + 1)}>+</button>
    </span>
  )
})

2 · Read what adoption cost

There is no hydration here, and the word is avoided on purpose: nothing re-renders to find out what is already on the page. The client walks the wiring the compiler emitted and attaches one binding per value that moves.

3bindings attached — two events and one value
0components executed on the client
0.045 msto adopt a 50-row region in Chromium

The cost is the number of bindings, not the number of components — which is why a page of mostly static markup with three live values pays for three.

Adoption, signals, and what ships has the wiring format and what a signal may and may not be.