A variable the page watches: change it, and every spot that shows it updates.In the glossary
graph is a map, written at compile time, of which
Anything that produces a result, like guests.length. Written inside { }.In the glossary
each spot on the page reads.
import { computed, state } from '@markless/core';constSONGSconst SONGS: string[] = ['Harbour Lights', 'Slow Train', 'Northbound'];export default functionPlayerfunction Player(): Element() @{@{ · Statement containerHolds instructions: setup lines, then the element to show. letplayinglet playing: string=statestate · Watched valueDeclares a variable the page watches. You read and assign it like any other variable, and the page keeps up.('Harbour Lights'); letlikedlet liked: Set<string>=statestate · Watched valueDeclares a variable the page watches. You read and assign it like any other variable, and the page keeps up.(newSetvar Set: SetConstructor new <string>(iterable?: Iterable<string> | null | undefined) => Set<string> (+1 overload)<string>()); letvolumelet volume: number=statestate · Watched valueDeclares a variable the page watches. You read and assign it like any other variable, and the page keeps up.(6); constisLikedconst isLiked: boolean =computedcomputed · Derived valueDeclares a value worked out from other values by a recipe, worked out again whenever one of them changes. Give it an async recipe and read it inside @try.(() => liked.has(method) Set<string>.has(value: string): boolean(playing)); consttitleconst title: string =computedcomputed · Derived valueDeclares a value worked out from other values by a recipe, worked out again whenever one of them changes. Give it an async recipe and read it inside @try.(() => playing.toUpperCase(method) String.toUpperCase(): stringConverts all the alphabetic characters in a string to uppercase.()); constcoverconst cover: string =computedcomputed · Derived valueDeclares a value worked out from other values by a recipe, worked out again whenever one of them changes. Give it an async recipe and read it inside @try.(() => '/covers/' +playinglet playing: string+ '.jpg'); <section<section> · HTML elementA section of a page, usually with its own heading.> <h2<h2> · HTML elementA second-level heading.>{title}</h2<h2> · HTML elementA second-level heading.> <button<button> · HTML elementA button a person can press.class(property) class?: string | undefined={isLiked ? 'heart on' : 'heart'}onClickonClick · Event handlerRuns when this element gets the DOM event named after on, with the browser's own event object.={() => (liked = newSetvar Set: SetConstructor new <string>(iterable?: Iterable<string> | null | undefined) => Set<string> (+1 overload)([...liked, playing]))} > ♥ </button<button> · HTML elementA button a person can press.> <ul<ul> · HTML elementA list whose order does not matter.>@for@for · ListShows its block once per item. It needs a key. (constsongconst song: stringofSONGSconst SONGS: string[]; key song) { <li<li> · HTML elementOne item in a list.class(property) class?: string | undefined={song ===playinglet playing: string? 'row on' : 'row'}onClickonClick · Event handlerRuns when this element gets the DOM event named after on, with the browser's own event object.={() => (playing = song)} > {song} </li<li> · HTML elementOne item in a list.> } </ul<ul> · HTML elementA list whose order does not matter.> <img<img> · HTML elementAn image.src(property) src?: string | undefined={cover} alt(property) alt?: string | undefined="" /> <label<label> · HTML elementThe name of a form field.> Volume {volume} <input<input> · HTML elementA field a person types in or picks a value with.type(property) type?: string | undefined="range"max(property) max?: string | number | undefined="10"onInputonInput · Event handlerRuns when this element gets the DOM event named after on, with the browser's own event object.={(e(parameter) e: EventWithCurrentTarget<Event, HTMLInputElement>) => (volume =Numbervar Number: NumberConstructor (value?: any) => numberAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.(e.target.value))} /> </label<label> · HTML elementThe name of a form field.> </section<section> · HTML elementA section of a page, usually with its own heading.>}
playing, liked and volume are values the page watches. isLiked reads two of them, and title and cover read one. Each spot in the markup that reads a value gets an edge from it, so one value can feed many spots, and one spot can depend on many values.
You build the graph by building the page
The compiler turns each state() and computed() into a node, and each spot that reads one into a subscription, drawn as an edge. Drag pieces onto the page, then pick a song, like it, or turn the volume:
Drag a piece onto the page, then pick a song.
A pen-and-ink drawing of a music page that starts with only a song list, a tray of pieces below it, and a state graph beside it, laid out left to right: states, computed values, and the spots on the page that read them. The graph starts with three states, playing, liked and volume, and one edge from playing to the song list's row class. Drag the Now playing header, the heart, the album cover or the volume knob onto the page, or press it in the tray, or press 1 to 4: its computed value and its reader ink themselves in. The heart brings isLiked, which reads both liked and playing. The My playlist heading, key 5, reads nothing and draws no node. Pick a song: only playing's branch pulses. Press the heart, or L: only liked, isLiked and the heart pulse. Press the knob, or V: only volume and its text pulse. Drag a piece back to the tray and its edges are erased. Escape starts again.
A music page with just a song list, and its state graph: three states, and playing read by the list. Drag pieces onto the page.
Each piece brings its computed value and its spot, with edges from every value they read. The heart brings isLiked, which reads both liked and playing.
The heading reads nothing, so it never gets a node.
A write travels only its own branch: liking a song never touches the header or the cover. Drag a reader off again and a song pick reaches fewer spots.
A write runs only its own path
When playing changes, @markless/runtime:
marks state:playing changed, and any computed that reads it stale,
waits for the current code to finish, then runs one flush,
runs only the subscriptions on that path and applies the page changes they return.
PlaygroundType @ or < for suggestions · F1 explains a wordRestored your edit·
import { state } from '@markless/core';const NAMES = ['Rocket', 'X', 'Xtreme', 'Ex'];export default function Rocket() @{ let name = state(0); let up = state(false); const rename = () => (name = (name + 1) % 4); <sectionclass="launchpad"> <imgsrc="/examples/ink/melon.svg" alt="" /> <h2>Melon calls it {NAMES[name]}</h2> <pclass={up ? 'ship up' : 'ship'}> {NAMES[name]} </p> <buttononClick={rename}>Rename</button> <buttononClick={() => (up = !up)}> {up ? 'Land' : 'Launch'} </button> </section>}