Skip to content

Instantly share code, notes, and snippets.

@guybedford
Last active January 1, 2016 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guybedford/8211375 to your computer and use it in GitHub Desktop.
Save guybedford/8211375 to your computer and use it in GitHub Desktop.
Steal Modularity Example for SystemJS
// add the steal format as the first priority check
System.formats.unshift('steal');
// create the steal format detection
var stealRegEx = /(?:^\s*|[}{\(\);,\n\?\&]\s*)steal\s*\(\s*((?:"[^"]+"\s*,|'[^']+'\s*,\s*)*)/;
System.format.steal = {
detect: function(source, load) {
var match = source.match(stealRegEx);
if (match)
return match[1] ? eval(match[1].substr(0, match[1].lastIndexOf(','))) : [];
},
execute: function(load, depMap, global, execute) {
var output;
global.steal = function() {
var dependencies = [], factory;
for (var i = 0; i < arguments.length; i++) {
if (typeof arguments[i] == 'string')
dependencies.push(depMap[arguments[i]]);
else
factory = arguments[i];
}
output = factory.apply(global, dependencies);
}
execute();
return output;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment