mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
add Private.stub for replacing already created deps
This commit is contained in:
parent
ed92eab2d8
commit
486b879e5f
1 changed files with 12 additions and 4 deletions
|
@ -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;
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue