Implemented a javascript code style
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
preventLoop = function(inputFunction){
|
||||
if(!_.isFunction(inputFunction)) throw new Meteor.Error("Not a function",
|
||||
"preventLoop can only take a function as an argument");
|
||||
if (!_.isFunction(inputFunction)){
|
||||
throw new Meteor.Error(
|
||||
"Not a function",
|
||||
"preventLoop can only take a function as an argument"
|
||||
);
|
||||
}
|
||||
//store a private array of arguments we have been given without returning
|
||||
//if we try to visit the same argument twice before resolving its value
|
||||
//we are in a dependency loop and need to GTFO
|
||||
@@ -8,20 +12,20 @@ preventLoop = function(inputFunction){
|
||||
return function(argument){
|
||||
var value;
|
||||
//we're still evaluating this attribute, must be in a loop
|
||||
if(_.contains(visitedArgs, argument)) {
|
||||
if (_.contains(visitedArgs, argument)) {
|
||||
console.warn("dependency loop detected");
|
||||
return NaN;
|
||||
} else{
|
||||
} else {
|
||||
//push this skill to the list of visited skills
|
||||
//we can't visit it again unless it returns first
|
||||
visitedArgs.push(argument);
|
||||
}
|
||||
try{
|
||||
try {
|
||||
value = inputFunction.call(this, argument);
|
||||
} finally{
|
||||
//this argument returns or fails, pull it from the array
|
||||
visitedArgs = _.without(visitedArgs, argument);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user