Documentation
¶
Overview ¶
Package viz bundles the scenes of the nodes (spec 10) and checks their traces.
A scene is viz/scene.ts. It imports only "@algo/viz". Build bundles it with esbuild into a script that registers the scene in window.AlgoScenes. The player of the site runs it in the browser.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build bundles the scene file into a browser script. The script sets window.AlgoScenes[slug] to the scene, and window.AlgoViz to the runtime.
func Probe ¶ added in v0.1.10
Probe turns each "// @line" marker of a TypeScript reference into a probe call, and compiles the result to a CommonJS script (rule V06). The probe is the global function __probe(id), which returns true.
The probe goes where the line runs:
- On an if, an else if or a while, the probe is the first part of the condition, so it runs each time the condition is tested, also the last time.
- On a for loop with three clauses, the probe is the first part of the test, so it also runs each time the test runs. On a for of loop, the probe is the first statement of the body.
- On an else, the probe is the first statement of the block.
- On any other line, the probe is a statement before the code of the line.
A line with code that continues the line before it, such as the second line of a long call, cannot carry a marker.
Types ¶
type Report ¶
type Report struct {
Slug string `json:"slug"`
Fails []string `json:"fails"`
Lines []string `json:"lines"` // the line ids that the presets reach
Steps []int `json:"steps"` // the number of steps of each preset
Skipped string `json:"skipped,omitempty"`
}
Report is the result of checking one scene.
func Check ¶
Check runs the bundled scene in Node on each preset (rules V01, V02, V04, V05, V06, V10, and the state vocabulary of V09). It also checks that each event names a view of its kind. When the scene has a reference, it runs the reference on each preset and compares the lines (V06). Without Node, the check is skipped and says so.
type Scene ¶ added in v0.1.10
type Scene struct {
Slug string
Bundle []byte // the output of Build
Presets []Preset // the presets of viz/presets.yaml
IDs []string // the line ids of the main pseudocode block of the page
// Ref is the TypeScript reference after Probe, or nil when the node has none. RefErr is the error of Probe, which V06 reports.
Ref []byte
RefErr error
}
Scene is what Check needs to check one scene.