Last active
December 11, 2015 10:58
-
-
Save piercus/4590077 to your computer and use it in GitHub Desktop.
Script to use sand.define's modules with requirejs
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
if (typeof(define) === "undefined"){ | |
console.log("[ERROR] require.js is not defined"); | |
} | |
if (typeof(sand) !== "undefined"){ | |
console.log("[ERROR] sand is already defined"); | |
} | |
var sand; | |
(function(){ | |
Array.prototype.last = String.prototype.last = function() { | |
return this[this.length - 1]; | |
}; | |
var parse = function(name){return name.split('/').last()}; | |
sand = { | |
define : function(name, requires, fn, options){ | |
if (typeof(requires) === 'function') { | |
fn = requires; | |
requires = []; | |
} else if (typeof(requires) === 'undefined') requires = []; | |
var amdFn = function(){ | |
var r = {}; | |
for (var i = 0; i < arguments.length; i++){ | |
var alias = requires[i].split("->")[1] || parse(requires[i]); | |
r[alias] = arguments[i]; | |
} | |
return fn(r); | |
} | |
define(name, requires, amdFn); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment