|
| 1 | + |
| 2 | +define('simple_amd_file',[],function() { |
| 3 | + |
| 4 | + var Mult = function(a, b) { |
| 5 | + return a * b; |
| 6 | + } |
| 7 | + |
| 8 | + return Mult; |
| 9 | + |
| 10 | +}); |
| 11 | +// src for the wrapper: https://github.com/umdjs/umd/blob/master/amdWeb.js |
| 12 | +(function (root, factory) { |
| 13 | + if (typeof define === 'function' && define.amd) { |
| 14 | + // AMD. Register as an anonymous module. |
| 15 | + define('umd_file',factory); |
| 16 | + } else { |
| 17 | + // Browser globals |
| 18 | + root.amdWeb = factory(root.b); |
| 19 | + } |
| 20 | +}(this, function() { |
| 21 | + //use b in some fashion. |
| 22 | + |
| 23 | + // Just return a value to define the module export. |
| 24 | + // This example returns an object, but the module |
| 25 | + // can return a function as the exported value. |
| 26 | + return { |
| 27 | + test: function() { |
| 28 | + console.log('Test Log from the UMD file'); |
| 29 | + } |
| 30 | + }; |
| 31 | +})); |
| 32 | +(function(root) { |
| 33 | + |
| 34 | + root.myLib = {}; |
| 35 | + |
| 36 | + myLib.sum = function(a, b) { |
| 37 | + return a + b; |
| 38 | + } // END PROTYPE OF sum |
| 39 | + |
| 40 | +})(this); |
| 41 | +define("non_md_file", (function (global) { |
| 42 | + return function () { |
| 43 | + var ret, fn; |
| 44 | + return ret || global.myLib; |
| 45 | + }; |
| 46 | +}(this))); |
| 47 | + |
| 48 | +define('complex_amd_file',['non_md_file', 'simple_amd_file'], function(MyLib, Mult) { |
| 49 | + |
| 50 | + var SumMulti = function(a, b) { |
| 51 | + return Mult(MyLib.sum(a, b), b); |
| 52 | + } |
| 53 | + |
| 54 | + return SumMulti; |
| 55 | + |
| 56 | +}); |
| 57 | +requirejs.config({ |
| 58 | + baseUrl: '/fixtures/vendor', |
| 59 | + |
| 60 | + shim: { |
| 61 | + 'non_md_file': { |
| 62 | + exports: 'myLib' |
| 63 | + } |
| 64 | + } |
| 65 | +}) |
| 66 | + |
| 67 | +requirejs(['simple_amd_file', 'umd_file', 'complex_amd_file'], function(Mult, UMDLib, SumMulti) { |
| 68 | + console.log("executing the COMPLEX init file"); |
| 69 | + console.log(Mult(3, 5), '<= this should be 15'); |
| 70 | + UMDLib.test(); // should log 'Test Log from the UMD file' |
| 71 | + console.log(SumMulti(5, 8), '<= this should be 104'); |
| 72 | +}); |
| 73 | +define("../complex_init", function(){}); |
| 74 | + |
| 75 | +define("../complex_init", function(){}); |
0 commit comments