|
| 1 | +define('simple_amd_file',[],function() { |
| 2 | + |
| 3 | + var Mult = function(a, b) { |
| 4 | + return a * b; |
| 5 | + }; |
| 6 | + |
| 7 | + return Mult; |
| 8 | + |
| 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 | + |
| 33 | +(function(root) { |
| 34 | + |
| 35 | + root.myLib = {}; |
| 36 | + |
| 37 | + root.myLib.sum = function(a, b) { |
| 38 | + return a + b; |
| 39 | + }; // END PROTYPE OF sum |
| 40 | + |
| 41 | +})(this); |
| 42 | + |
| 43 | +define("non_md_file", (function (global) { |
| 44 | + return function () { |
| 45 | + var ret, fn; |
| 46 | + return ret || global.myLib; |
| 47 | + }; |
| 48 | +}(this))); |
| 49 | + |
| 50 | +define('complex_amd_file',['non_md_file', 'simple_amd_file'], function(MyLib, mult) { |
| 51 | + |
| 52 | + var SumMulti = function(a, b) { |
| 53 | + return mult(MyLib.sum(a, b), b); |
| 54 | + }; |
| 55 | + |
| 56 | + return SumMulti; |
| 57 | + |
| 58 | +}); |
| 59 | + |
| 60 | +requirejs(['simple_amd_file', 'umd_file', 'complex_amd_file'], |
| 61 | + function(mult, UMDLib, sumMulti) { |
| 62 | + console.log('executing the COMPLEX init file'); |
| 63 | + console.log(mult(3, 5), '<= this should be 15'); |
| 64 | + UMDLib.test(); // should log 'Test Log from the UMD file' |
| 65 | + console.log(sumMulti(5, 8), '<= this should be 104'); |
| 66 | + } |
| 67 | +); |
| 68 | + |
| 69 | +define("complex_init_dir", function(){}); |
| 70 | + |
0 commit comments