Last active
August 29, 2015 13:56
-
-
Save jcreamer898/8984870 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
// Before switch | |
_.each(conditions.conditions, function (condition) { | |
field = this.lastRecord[condition.field]; | |
var isVisible = false; | |
switch(condition.operator) { | |
case "+": | |
isVisible = (x == y); | |
break; | |
case "!=": | |
isVisisble = (x !== y); | |
break | |
// Lots more | |
// of this | |
// monkey | |
// business | |
} | |
}, this); | |
// After switch | |
_.each(conditions.conditions, function (condition) { | |
field = this.lastRecord[condition.field]; | |
isVisible = operators[condition.operator](field, condition.value); | |
}, this); | |
// Operators.js | |
// A separate reusable file of operators that's nicer looking IMHO | |
define({ | |
'=': function(x, y) { | |
return x == y; | |
}, | |
'!=': function(x, y) { | |
return x !== y; | |
}, | |
'>': function(x, y) { | |
return +x > +y; | |
}, | |
'<': function(x, y) { | |
return +x < +y; | |
}, | |
'defined': function(x) { | |
return x; | |
}, | |
'undefined': function(x) { | |
return !x; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment