Use operator/operand inside the Filter instance methods.

Avoid tuples in the methods inside Filter.prototype.

(imported from commit beed799e767d9645735a2bd4eefb5d431c04f17f)
This commit is contained in:
Steve Howell 2014-01-30 12:12:45 -05:00
parent b18307b667
commit 53027b71a4
1 changed files with 9 additions and 9 deletions

View File

@ -200,29 +200,29 @@ Filter.prototype = {
public_operators: function Filter_public_operators() { public_operators: function Filter_public_operators() {
var safe_to_return = _.filter(this._operators, function (value) { var safe_to_return = _.filter(this._operators, function (value) {
// Filter out the "in" keyword and the embedded narrow (if any). // Filter out the "in" keyword and the embedded narrow (if any).
return value[0] !== 'in' && !(page_params.narrow_stream !== undefined && return value.operator !== 'in' && !(page_params.narrow_stream !== undefined &&
value[0] === "stream" && value.operator === "stream" &&
value[1].toLowerCase() === page_params.narrow_stream.toLowerCase()); value.operand.toLowerCase() === page_params.narrow_stream.toLowerCase());
}); });
return safe_to_return; return safe_to_return;
}, },
operands: function Filter_get_operands(operator) { operands: function Filter_get_operands(operator) {
return _.chain(this._operators) return _.chain(this._operators)
.filter(function (elem) { return elem[0] === operator; }) .filter(function (elem) { return elem.operator === operator; })
.map(function (elem) { return elem[1]; }) .map(function (elem) { return elem.operand; })
.value(); .value();
}, },
has_operand: function Filter_has_operand(operator, operand) { has_operand: function Filter_has_operand(operator, operand) {
return _.any(this._operators, function (elem) { return _.any(this._operators, function (elem) {
return elem[0] === operator && elem[1] === operand; return elem.operator === operator && elem.operand === operand;
}); });
}, },
has_operator: function Filter_has_operator(operator) { has_operator: function Filter_has_operator(operator) {
return _.any(this._operators, function (elem) { return _.any(this._operators, function (elem) {
return elem[0] === operator; return elem.operator === operator;
}); });
}, },
@ -259,8 +259,8 @@ Filter.prototype = {
// * "return false" if the value does not match // * "return false" if the value does not match
// * "break" if there is a match // * "break" if there is a match
// If you "return true", you circumvent all future operators // If you "return true", you circumvent all future operators
operand = operators[i][1]; operand = operators[i].operand;
switch (operators[i][0]) { switch (operators[i].operator) {
case 'is': case 'is':
if (operand === 'private') { if (operand === 'private') {
if (message.type !== 'private') { if (message.type !== 'private') {