Skip to content
This repository

Added versioning example using addRules() #74

Merged
merged 1 commit into from over 2 years ago

2 participants

Fermin Simeon Jakob Heuser
Fermin Simeon
Collaborator

Added versioning example

Jakob Heuser Jakobo merged commit 6e44d1b into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 21, 2011
Fermin Simeon fsimeon added versioning using addrules 87f492c
This page is out of date. Refresh to see the latest.
5 examples/deps/math/0.0.1/multiplication.js
... ... @@ -0,0 +1,5 @@
  1 +function multiply(num) {
  2 + return num * 5;
  3 +}
  4 +
  5 +exports.multiply = multiply;
5 examples/deps/math/0.1.1/multiplication.js
... ... @@ -0,0 +1,5 @@
  1 +function multiply(num) {
  2 + return num * 10;
  3 +}
  4 +
  5 +exports.multiply = multiply;
2  examples/index.html
@@ -22,6 +22,8 @@
22 22 <dd>jQuery was loaded using a define() native jQuery 1.7</dd>
23 23 <dt><a href="addrule.html">addRule()</a>:</dt>
24 24 <dd>how to use the addRule() syntax to support supplemental libraries such as jQuery UI</dd>
  25 + <dt><a href="versioning.html">addRule() for versioning</a>:</dt>
  26 + <dd>how to use the addRule() syntax to support versioning</dd>
25 27 </dl>
26 28 </body>
27 29 </html>
55 examples/versioning.html
... ... @@ -0,0 +1,55 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <!--[if lte IE 7]>
  5 + <script src="/ie-localstorage-json-shim.js" type="text/javascript" id="ie-localstorage-shim"></script>
  6 + <![endif]-->
  7 + <script type="text/javascript" src="/inject.js"></script>
  8 + <script type="text/javascript">
  9 + require.setModuleRoot("/examples/deps");
  10 + require.addRule(/math/, {
  11 + path: function(module) {
  12 + var path = module.split('/');
  13 + if(path.length > 1){
  14 + var mod = path[1].split('@');
  15 + if ( mod.length > 1) {
  16 + return [ path[0], "/",mod[1], "/", mod[0], ".js"].join("");
  17 + }
  18 + }
  19 + return [module,".js"].join("");
  20 + }
  21 + });
  22 + </script>
  23 +
  24 +</head>
  25 +<body>
  26 +<h1>Using addRule() for versioning</h1>
  27 +<p>In this example, we're loading two versions of a multiplication library</p>
  28 +
  29 +<p><a href="index.html">Back to examples</a></p>
  30 +
  31 +<p>(version 0.0.1) 2 x 5</p>
  32 +<p id="output-foo"></p>
  33 +<p>(version 0.1.1) 2 x 10</p>
  34 +<p id="output-bar"></p>
  35 +
  36 +<button id="clearit">Clear Cache</button>
  37 +
  38 +<script type="text/javascript">
  39 +document.getElementById("clearit").onclick = function() {
  40 + require.clearCache();
  41 +};
  42 +</script>
  43 +
  44 +<script type="text/javascript">
  45 +require.ensure(["math/multiplication@0.0.1"], function() {
  46 + var app = require("math/multiplication@0.0.1");
  47 + document.getElementById("output-foo").innerHTML = app.multiply(2);
  48 +});
  49 +require.ensure(["math/multiplication@0.1.1"], function() {
  50 + var app = require("math/multiplication@0.1.1");
  51 + document.getElementById("output-bar").innerHTML = app.multiply(2);
  52 +});
  53 +</script>
  54 +</body>
  55 +</html>

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.