How the live demo is embedded

Technical notes explaining how the Pathwrite engine was run inline on the gh-pages homepage and how the live demo works.

Summary

The homepage contains a small, embedded Pathwrite example that runs the core engine directly in the browser (no iframe). It imports @daltonr/pathwrite-core as an ES module from a CDN and creates a PathEngine instance which is driven by a tiny path definition and a rendering loop that updates the DOM from snapshots.

How it runs

  1. Import the engine as an ES module, for example using esm.sh:
    import { PathEngine } from 'https://esm.sh/@daltonr/pathwrite-core@0.6.3';
  2. Define a small path (steps array) and optionally a sub-path. Steps can include guards (canMoveNext) and conditional skipping (shouldSkip).
  3. Create the engine and start it: const engine = new PathEngine(); engine.start(mainPath, {});
  4. Subscribe to engine events and call a render() function on state changes. In render we call engine.snapshot() and update the stepper, step label and step content from that snapshot.
  5. Wire the UI controls to the engine API: engine.next(), engine.previous(), engine.startSubPath(), engine.cancel(), and engine.setData() for interactive inputs.

Key concepts demonstrated

Rendering loop

The demo uses a simple declarative render loop:

engine.subscribe(() => render());
function render(){
  const snap = engine.snapshot();
  // build stepper from snap.steps
  // set the body content for current step
  // enable/disable buttons from snap.canMoveNext / snap.isFirstStep
}

This keeps UI logic isolated: the engine manages flow, the page renders snapshots.

Wiring controls

Example bindings:

nextButton.addEventListener('click', () => engine.next());
prevButton.addEventListener('click', () => engine.previous());
chip.addEventListener('click', () => engine.setData('framework','vue'));

Notes & considerations

← Back to homepage