Skip to content

Instantly share code, notes, and snippets.

@briancavalier
Created June 26, 2012 11:30
Show Gist options
  • Save briancavalier/2995278 to your computer and use it in GitHub Desktop.
Save briancavalier/2995278 to your computer and use it in GitHub Desktop.
Using the root context to supply nodes to child contexts
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
(function(g) {
// Declare the contents of the root spec. These will be
// visible to all ancestors.
// IMPORTANT: This must be declared *before* wire executes
// for the first time.
g.wire = {
// Grab the actual nodes we care about
rootNode: { $ref: 'dom!my-container' },
anotherNode: { $ref: 'dom!my-other-container' },
// Be sure to include wire/dom for the dom! ref resolver
plugins: [
{ module: 'wire/dom' }
]
};
})(window);
</script>
<script type="text/javascript" src="path/to/curl.js"></script>
<script type="text/javascript">
// Kick off wiring
// main-spec will be a descendent of the root spec above, so will
// be able to see rootNode and anotherNode.
// For example, you can $ref them.
curl(['wire!main-spec']);
</script>
</head>
<body>
...
<div id="my-container">
...
</div>
...
<div id="my-other-container">
...
</div>
...
</body>
</html>
define({
myView: {
create: { /* ... */ },
properties: {
// Since rootNode is in the root context, we can simply $ref it.
node: { $ref: 'rootNode' }
// ...
}
// ...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment