Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added versioning example using addRules() #74

Merged
merged 1 commit into from Dec 21, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/deps/math/0.0.1/multiplication.js
@@ -0,0 +1,5 @@
function multiply(num) {
return num * 5;
}

exports.multiply = multiply;
5 changes: 5 additions & 0 deletions examples/deps/math/0.1.1/multiplication.js
@@ -0,0 +1,5 @@
function multiply(num) {
return num * 10;
}

exports.multiply = multiply;
2 changes: 2 additions & 0 deletions examples/index.html
Expand Up @@ -22,6 +22,8 @@ <h1>Examples</h1>
<dd>jQuery was loaded using a define() native jQuery 1.7</dd>
<dt><a href="addrule.html">addRule()</a>:</dt>
<dd>how to use the addRule() syntax to support supplemental libraries such as jQuery UI</dd>
<dt><a href="versioning.html">addRule() for versioning</a>:</dt>
<dd>how to use the addRule() syntax to support versioning</dd>
</dl>
</body>
</html>
55 changes: 55 additions & 0 deletions examples/versioning.html
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<!--[if lte IE 7]>
<script src="/ie-localstorage-json-shim.js" type="text/javascript" id="ie-localstorage-shim"></script>
<![endif]-->
<script type="text/javascript" src="/inject.js"></script>
<script type="text/javascript">
require.setModuleRoot("/examples/deps");
require.addRule(/math/, {
path: function(module) {
var path = module.split('/');
if(path.length > 1){
var mod = path[1].split('@');
if ( mod.length > 1) {
return [ path[0], "/",mod[1], "/", mod[0], ".js"].join("");
}
}
return [module,".js"].join("");
}
});
</script>

</head>
<body>
<h1>Using addRule() for versioning</h1>
<p>In this example, we're loading two versions of a multiplication library</p>

<p><a href="index.html">Back to examples</a></p>

<p>(version 0.0.1) 2 x 5</p>
<p id="output-foo"></p>
<p>(version 0.1.1) 2 x 10</p>
<p id="output-bar"></p>

<button id="clearit">Clear Cache</button>

<script type="text/javascript">
document.getElementById("clearit").onclick = function() {
require.clearCache();
};
</script>

<script type="text/javascript">
require.ensure(["math/multiplication@0.0.1"], function() {
var app = require("math/multiplication@0.0.1");
document.getElementById("output-foo").innerHTML = app.multiply(2);
});
require.ensure(["math/multiplication@0.1.1"], function() {
var app = require("math/multiplication@0.1.1");
document.getElementById("output-bar").innerHTML = app.multiply(2);
});
</script>
</body>
</html>