stream_list: Convert build_stream_sidebar_row to an ES6 class.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-07-22 17:47:43 -07:00
committed by Tim Abbott
parent 2aae92b6e3
commit e47fd521e3

View File

@@ -230,34 +230,37 @@ function build_stream_sidebar_li(sub) {
return list_item; return list_item;
} }
function build_stream_sidebar_row(sub) { class StreamSidebarRow {
const self = {}; constructor(sub) {
const list_item = build_stream_sidebar_li(sub); this.sub = sub;
this.list_item = build_stream_sidebar_li(sub);
this.update_unread_count();
}
self.update_whether_active = function () { update_whether_active() {
if (stream_data.is_active(sub) || sub.pin_to_top === true) { if (stream_data.is_active(this.sub) || this.sub.pin_to_top === true) {
list_item.removeClass("inactive_stream"); this.list_item.removeClass("inactive_stream");
} else { } else {
list_item.addClass("inactive_stream"); this.list_item.addClass("inactive_stream");
} }
}; }
self.get_li = function () { get_li() {
return list_item; return this.list_item;
}; }
self.remove = function () { remove() {
list_item.remove(); this.list_item.remove();
}; }
self.update_unread_count = function () { update_unread_count() {
const count = unread.num_unread_for_stream(sub.stream_id); const count = unread.num_unread_for_stream(this.sub.stream_id);
exports.update_count_in_dom(list_item, count); exports.update_count_in_dom(this.list_item, count);
}; }
}
self.update_unread_count(); function build_stream_sidebar_row(sub) {
exports.stream_sidebar.set_row(sub.stream_id, new StreamSidebarRow(sub));
exports.stream_sidebar.set_row(sub.stream_id, self);
} }
exports.create_sidebar_row = function (sub) { exports.create_sidebar_row = function (sub) {