From babbca7360a443780a2f2cdb8e66f30935d7b4a2 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 15 Aug 2013 10:16:12 -0400 Subject: [PATCH] Use d.each() for iterating Dict instances. (imported from commit 8cfe2c9a61aa1179454a6ab986fa23d04de09525) --- static/js/stream_list.js | 16 ++++------------ static/js/unread.js | 12 +++--------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/static/js/stream_list.js b/static/js/stream_list.js index 2c3947a315..76754552a3 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -228,27 +228,19 @@ exports.update_dom_with_unread_counts = function (counts) { // Our job is to update some DOM elements. // counts.stream_count maps streams to counts - _.each(counts.stream_count.items(), function (item) { - var stream = item[0]; - var count = item[1]; + counts.stream_count.each(function (count, stream) { exports.set_count("stream", stream, count); }); // counts.subject_count maps streams to hashes of subjects to counts - _.each(counts.subject_count.items(), function (item) { - var stream = item[0]; - var subject_hash = item[1]; - _.each(subject_hash.items(), function (item) { - var subject = item[0]; - var count = item[1]; + counts.subject_count.each(function (subject_hash, stream) { + subject_hash.each(function (count, subject) { exports.set_subject_count(stream, subject, count); }); }); // counts.pm_count maps people to counts - _.each(counts.pm_count.items(), function (item) { - var person = item[0]; - var count = item[1]; + counts.pm_count.each(function (count, person) { exports.set_count("private", person, count); }); diff --git a/static/js/unread.js b/static/js/unread.js index 37bf386c17..2151fb2807 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -130,9 +130,7 @@ exports.get_counts = function () { }); } - _.each(unread_counts.stream.items(), function (item) { - var stream = item[0]; - var msgs = item[1]; + unread_counts.stream.each(function (msgs, stream) { if (! subs.is_subscribed(stream)) { return true; } @@ -146,9 +144,7 @@ exports.get_counts = function () { if (unread_subjects.has(stream)) { res.subject_count.set(stream, new Dict()); - _.each(unread_subjects.get(stream).items(), function (item) { - var subject = item[0]; - var msgs = item[1]; + unread_subjects.get(stream).each(function (msgs, subject) { res.subject_count.get(stream).set(subject, Object.keys(msgs).length); }); } @@ -156,9 +152,7 @@ exports.get_counts = function () { }); var pm_count = 0; - _.each(unread_counts["private"].items(), function (item) { - var index = item[0]; - var obj = item[1]; + unread_counts["private"].each(function (obj, index) { var count = Object.keys(obj).length; res.pm_count.set(index, count); pm_count += count;