Resuming

2 min·Assumes: state, events

Markless works the page out ahead of time, so the browser can
mid-game on your first press instead of running your components again.
import { state } from '@markless/core';

export default function Like() @{
	let liked = state(false);

	<button onClick={() => (liked = !liked)}>
		{liked ? 'Liked' : 'Like'}
	</button>
}

liked arrives with the page as data, and onClick arrives as a name, not as code. The first press loads just that handler and runs it. Like() itself never runs again.

The page arrives mid-game

Play any move, then press Next move:

white to move
A pen-and-ink drawing of a chess board on a desk, left mid-game with ten pieces, beside a score sheet that starts at move 9. In pencil at the foot of the sheet, "set up again from 1. e4?" is crossed out. Drag any piece of the side to move: ink dots mark its legal squares, a legal move is played and written on the sheet, and an illegal one slides back. Press Next move, or the board, and the side to move replies from the position as it stands: its first capture, otherwise a knight or bishop stepping toward the centre. Nothing ever replays from move one. Escape sets the board back.

A chess game left mid-game. Drag a piece to a dotted square, or press Next move and the side to move replies from where the game stands.

  • The position was worked out ahead of time, so the next move is the only work.
  • The reply comes from the board as it stands, whatever you played. Nothing is set up again from move one.
  • An illegal move slides back, the way a handler only does what its code says.

Three ways in

Who hears the first press depends on how the page was made:

  • Browser, direct module

    The compiled module builds the elements, each element with an event listens for itself, and the first click starts only that click's symbol.

  • Browser, general path

    Markless builds the elements from the compiled output, the container holds one listener per event name, and the first click starts its symbols, the state graph and the full runtime.

  • Server-rendered page

    The server builds the elements, the inline resumer listens on the container, and the first click starts the resume module, then only what it needs.

On a server-rendered page

  • Each element with a handler carries an m:on attribute. A tiny inline script reads it off the pressed element.
  • The press loads the page's resume module. If the compiler specialized the page's events and text updates, the full runtime never starts.
  • A press during loading is replayed in order, and a pointer or focus landing on a handler loads its code early.
PlaygroundRestored your edit

Ram Altman

Lend me $7 trillion and the robots are a few thousand days away.

Try this
  1. To do: Press Like. That first press loads its handler, and the heart fills.
  2. To do: Make the post arrive already liked: start liked at true. The heart is full before any code runs.

The state graph shows how one write finds the spots that read it.