Last active
January 1, 2016 22:39
-
-
Save guybedford/8211375 to your computer and use it in GitHub Desktop.
Steal Modularity Example for SystemJS
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
// 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