Skip to content

Instantly share code, notes, and snippets.

@FireNeslo
Last active August 29, 2015 14:05
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 FireNeslo/283a4224f395abd5d785 to your computer and use it in GitHub Desktop.
Save FireNeslo/283a4224f395abd5d785 to your computer and use it in GitHub Desktop.
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['injector'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('./injector'));
} else {
root.namespace = factory(root.Injector);
}
}(this, function (Injector) {
var spaces = {};
return function Namespace(name, ns) {'use strict';
if(spaces[name]) { return spaces[name]; }
if(!this) return new Namespace(name, ns);
Injector.call(this, ns && ns.map(function(ns) {
return spaces[ns];
}));
var modules = [], promise;
this.module = function(name, deps) {
return modules.push(this.define(name, deps, deps.pop())), this;
};
this.then = function(s,e) {
return (promise ||(promise = Promise.all(modules))).then(s,e);
};
this.success = this.then;
this.catch = this.then.bind(this, null);
spaces[name] = this;
};
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment