Last active
August 29, 2015 14:05
-
-
Save FireNeslo/283a4224f395abd5d785 to your computer and use it in GitHub Desktop.
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 (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