add Private.stub for replacing already created deps

This commit is contained in:
Spencer Alger 2014-08-25 12:23:52 -07:00
parent ed92eab2d8
commit 486b879e5f

View file

@ -25,15 +25,19 @@ define(function (require) {
// one cache per instance of the Private service
var cache = {};
function Private(fn) {
function indent(fn) {
if (typeof fn !== 'function') {
throw new TypeError('Expected private module "' + fn + '" to be a function');
}
var id = fn.$$id;
if (id && cache[id]) return cache[id];
if (fn.$$id) return fn.$$id;
else return (fn.$$id = nextId());
}
if (!id) id = fn.$$id = nextId();
function Private(fn) {
var id = indent(fn);
if (cache[id]) return cache[id];
else if (~privPath.indexOf(id)) {
throw new Error(
'Circluar refrence to "' + name(fn) + '"' +
@ -54,6 +58,10 @@ define(function (require) {
return instance;
}
Private.stub = function (fn, val) {
cache[indent(fn)] = val;
};
return Private;
});
});