Skip to content
Open Garphield

Events and errors

const stop = graph.on("nodeClick", ({ nodeId }) => {
detailPanel.show(nodeId);
});

Node ids are strings at the browser-driver boundary.

graph.on("stepChange", ({ index, title }) => {
chapterNav.select(index, title);
});

The event fires when the current story step changes through the host or the embedded player.

graph.on("error", ({ message }) => {
showGraphError(message);
});

Method calls reject when a project or parameter is invalid, a command is not granted, or the renderer does not reply before the timeout.

try {
await graph.setDocument(candidate);
} catch (error) {
console.error("Garphield rejected the project", error);
}

Keep the unsubscribe functions returned by on(). Call them, then call destroy() before permanently removing the iframe.