Chapter 7 of 9

DataTree

Presets are one JSON blob per appName — not keyed KV pushes. Native pages defer DataTree init and gate apply on a successful emit.

Native-specific rules

  1. Defer init ~600 ms (not 80 ms).
  2. Apply only when wax.didEmit() is true, or retry ~150 ms.
  3. Applying updates JS variables used by renderGraph(), then re-renders the graph — not DOM-only.
  4. Boot defaults + poke schedule run before pull/apply.

Collect / apply sketch

function collect() {
  return { schema: 1, params: { cutoffHz, q, master } };
}

function apply(raw) {
  const p = (raw && raw.params) || raw;
  if (!p) return;
  cutoffHz = p.cutoffHz ?? cutoffHz;
  q = p.q ?? q;
  master = p.master ?? master;
  syncUIFromVars();
  renderGraph();
}

async function initDataTree() {
  const helper = window.WaxWeb ? WaxWeb.create({ appName: APP_NAME }) : null;
  const dt = helper ? helper.data : window.WAX_DataTree;
  // … pull, onHydrated, push(collect()) when canPush
}

setTimeout(initDataTree, 600);

Wrong vs right

Full DataTree rules (Web + Native): WEB.md and NATIVE.md preset sections.

Example code

Snippets from this lesson — combine in your Custom Page.

Loading…