Component

io.eezo.live.Component
trait Component[S]

A live component: server-held state, rendered to HTML, updated over patches.

The mental model is a server template that re-renders itself (design/live.md §1): an event arrives from the browser or a Topic, the state moves, render runs again, and the differ ships the difference. The three methods are the three phases, and what each receives is what that phase may do — the split is enforced by the arguments, not by documentation:

  • init runs once, at mount, and is the only place subscriptions exist: it receives the Init context, and subscribe after init returns throws. render runs on every event, so a subscription there would be a duplicate per re-render.
  • handle moves the state. It runs on the page's own thread, one event at a time, so it needs no synchronisation of its own. Database work happens here the way it does in any handler: open a scope with transact { ... } or read { ... } per event — the installed Database reaches every thread, and a connection captured across events is already a loud error (EscapedScope).
  • render is a pure function of the state and receives nothing else. Exactly one root element, in canonical form; the differ refuses anything else by naming the broken rule.

State is any immutable value the component chooses. It lives on the server, owned by one page thread; the browser only ever holds its rendering.

Attributes

Source
Component.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def handle(event: Event, state: S): S

One client event in, the next state out. Runs serialized on the page's thread.

One client event in, the next state out. Runs serialized on the page's thread.

Attributes

Source
Component.scala
def init(ctx: Init[S]): S

The initial state, computed at mount. Subscriptions to Topics are registered here and nowhere else.

The initial state, computed at mount. Subscriptions to Topics are registered here and nowhere else.

Attributes

Source
Component.scala
def render(state: S): Html

The page for this state. Pure: same state, same tree.

The page for this state. Pure: same state, same tree.

Attributes

Source
Component.scala