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
- Defer init ~600 ms (not 80 ms).
- Apply only when
wax.didEmit()is true, or retry ~150 ms. - Applying updates JS variables used by
renderGraph(), then re-renders the graph — not DOM-only. - 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
- Wrong:
push("cutoff", 1200)— Right:push({ schema: 1, params: { cutoffHz: 1200 } }) - Wrong: JS envelope →
wax.constamp — Right:midinotein+adsr
Full DataTree rules (Web + Native): WEB.md and NATIVE.md preset sections.
Example code
Snippets from this lesson — combine in your Custom Page.
Loading…