Only re-render the streams list when the sort order has changed

(imported from commit 8122785097e2470e9e85f1f4c40bf1cd63264fa4)
This commit is contained in:
Zev Benjamin
2013-05-07 13:07:05 -04:00
committed by Tim Abbott
parent 466beef6fe
commit 02dc15f426
2 changed files with 21 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ var stream_list = (function () {
var exports = {};
var previous_sort_order;
exports.sort_narrow_list = function () {
var streams = subs.subscribed_streams();
if (streams.length === 0) {
@@ -23,6 +24,13 @@ exports.sort_narrow_list = function () {
return util.strcmp(a, b);
});
if (previous_sort_order !== undefined
&& util.array_compare(previous_sort_order, streams)) {
return;
}
previous_sort_order = streams;
var parent = $('#stream_filters');
parent.empty();

View File

@@ -227,5 +227,18 @@ exports.strcmp = (function () {
};
}());
exports.array_compare = function util_array_compare(a, b) {
if (a.length !== b.length) {
return false;
}
var i;
for (i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
};
return exports;
}());