refactor: Move operators_to_hash to hash_utils.

This breaks some unnecessary dependencies on
hashchange.js, in favor of hash_util, which
has fewer dependencies.
This commit is contained in:
Steve Howell
2018-08-04 14:33:28 +00:00
committed by Tim Abbott
parent ab26e27fef
commit 9accc2a3b6
7 changed files with 34 additions and 36 deletions

View File

@@ -64,6 +64,28 @@ exports.by_stream_subject_uri = function (stream, subject) {
"/subject/" + exports.encodeHashComponent(subject);
};
// Encodes an operator list into the
// corresponding hash: the # component
// of the narrow URL
exports.operators_to_hash = function (operators) {
var hash = '#';
if (operators !== undefined) {
hash = '#narrow';
_.each(operators, function (elem) {
// Support legacy tuples.
var operator = elem.operator;
var operand = elem.operand;
var sign = elem.negated ? '-' : '';
hash += '/' + sign + exports.encodeHashComponent(operator)
+ '/' + exports.encode_operand(operator, operand);
});
}
return hash;
};
return exports;