Last active
March 17, 2018 01:54
-
-
Save brainysmurf/52590f7f9d68ab5568bf9b84d611aaaf to your computer and use it in GitHub Desktop.
Package Wrapper
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
(function Package_ (global) { | |
global.Import = function (lib, options) { | |
options = options || {}; | |
options.namespace = options.namespace || false; | |
options.base = options.base || false; | |
if (options.namespace) { | |
var p = global, g = global, last; | |
options.namespace.split('.').forEach(function (namespace) { | |
g[namespace] = g[namespace] || {}; | |
p = g | |
g = g[namespace]; | |
last = namespace; | |
}); | |
p[last] = global.Import._import(lib); | |
} | |
if (options.base) { | |
if (options.base === 'global') options.base = global; | |
options.attr = options.attr || lib; | |
options.base[options.attr] = global.Import._import(lib); | |
} | |
return global.Import._import(lib); | |
}; | |
global.Import.register = function (uniqueId, func) { | |
global.Import[uniqueId] = func; | |
}; | |
global.Import._import = function (uniqueId) { | |
return global.Import[uniqueId]; | |
}; | |
global.Import.module = true; | |
})(this); |
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
(function(global,name,Package,helpers){var ref=function wrapper(args){var wrapped=function(){return Package.apply(global.Import&&Import.module?Import._import(name):global[name],arguments)};for(i in args){wrapped[i]=args[i]}return wrapped}(helpers);if(global.Import&&Import.module){Import.register(name,ref)}else{Object.defineProperty(global,name,{value:ref});global.Import=global.Import||function(lib){return global[lib]};Import.module=false}})(this, | |
"Name", | |
{ /* helpers */ } | |
); |
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
(function (global, name, Package, helpers) { | |
var ref = function wrapper (args) { | |
var wrapped = function () { return Package.apply(global.Import && Import.module ? Import._import(name) : global[name], arguments); }; | |
for (i in args) { wrapped[i] = args[i]; } | |
return wrapped; | |
}(helpers); | |
if (global.Import && Import.module) { | |
Import.register(name, ref); | |
} else { | |
Object.defineProperty(global, name, {value: ref}); | |
global.Import = global.Import || function (lib) { return global[lib]; } | |
Import.module = false; | |
} | |
})(this, | |
"Name", | |
{ /* helpers */ } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment