From 89ea079dcee95d4ce8d1ea860fbb61359f27b32c Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 3 Feb 2014 13:20:50 -0500 Subject: [PATCH] Allow Filter to accept non-tuple-based terms. We make this happen inside of canonicalize_term. (imported from commit 0571f6cac8ffdc806af56423cc98134c7493139e) --- static/js/filter.js | 7 ++++--- zerver/tests/frontend/node/filter.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/static/js/filter.js b/static/js/filter.js index 318dd66ee8..aa47e22a4f 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -145,9 +145,10 @@ Filter.canonicalize_operator = function (operator) { } }; -Filter.canonicalize_term = function (tuple) { - var operator = tuple[0]; - var operand = tuple[1]; +Filter.canonicalize_term = function (opts) { + // Legacy code may still call use with a tuple of [operator, operand]. + var operator = opts.operator || opts[0]; + var operand = opts.operand || opts[1]; operator = Filter.canonicalize_operator(operator); diff --git a/zerver/tests/frontend/node/filter.js b/zerver/tests/frontend/node/filter.js index 80281a9c2f..1cf491c5f7 100644 --- a/zerver/tests/frontend/node/filter.js +++ b/zerver/tests/frontend/node/filter.js @@ -42,6 +42,17 @@ function assert_result_matches_legacy_terms(result, terms) { assert(! filter.can_apply_locally()); }()); +(function test_new_style_operators() { + var term = { + operator: 'stream', + operand: 'foo' + }; + var operators = [term]; + var filter = new Filter(operators); + + assert.deepEqual(filter.operands('stream'), ['foo']); +}()); + (function test_public_operators() { var operators = [['stream', 'foo'], ['topic', 'bar']]; var filter = new Filter(operators);