Created
January 14, 2014 21:15
-
-
Save juandopazo/8425869 to your computer and use it in GitHub Desktop.
AMD loading in YUI 3.15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUI.add('require', function (Y) { | |
return function (name) { | |
return Y.Env._exported[name]; | |
} | |
}, '@VERSION@', { | |
es: true | |
}); | |
define(name, dependencies, factory) { | |
var defDeps = ['require', 'exports', 'module'], | |
actualDeps = [], i; | |
if (arguments.length === 1) { | |
name = '@NAME@'; | |
dependencies = defDeps; | |
} else if (arguments.length === 2) { | |
if (typeof name === 'string') { | |
factory = dependencies; | |
dependencies = defDeps; | |
} else { | |
dependencies = name; | |
name = '@NAME@'; | |
} | |
} | |
for (i = 0; i < dependencies.length; i++) { | |
if (dependencies[i] !== 'exports' && dependencies[i] !== 'module') { | |
actualDeps.push(dependencies[i]); | |
} | |
} | |
YUI.add(name, function (Y, NAME, __imports__, __exports__) { | |
var __module__ = { | |
exports: __exports__ | |
}, | |
imports = [], | |
i; | |
for (i = 0; i < dependencies.length; i++) { | |
if (dependencies[i] === 'module') { | |
imports[i] = __module__; | |
} else if (dependencies[i] === 'exports') { | |
imports[i] = __exports__; | |
} else { | |
imports[i] = __imports__[imports[i]]; | |
} | |
} | |
return factory.apply(undefined, imports); | |
}, '@VERSION@', { | |
es: true, | |
requires: actualDeps | |
}); | |
} | |
define.amd = true; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment