Skip to content

Instantly share code, notes, and snippets.

@xeolabs
Created October 17, 2009 06:57
Show Gist options
  • Select an option

  • Save xeolabs/212274 to your computer and use it in GitHub Desktop.

Select an option

Save xeolabs/212274 to your computer and use it in GitHub Desktop.
var graph = SceneJs.graph(
SceneJs.node({
preVisit: function(nodeContext) {
// Parent node gets graph context from node context
// and sets something on it for child
var graphContext = nodeContext.getGraphContext();
graphContext.foo = 'Hi, child nodes!';
},
postVisit: function(nodeContext) {
// Ordinarily each node should restore the graph context
// to its original state before it was modified on pre-visit
var graphContext = nodeContext.getGraphContext();
graphContext.foo = null;
}
},
SceneJs.node({
preVisit: function(nodeContext) {
// Child node finds what parent set on graph context
var graphContext = nodeContext.getGraphContext();
alert('Message from parent: ' + graphContext.foo);
}
})
)
);
// If not supplied, a default internal graph runtime context is
// created that will not persist between traversals
graph.traverse();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment