stream_list: Convert stream_sidebar to an ES6 class StreamSidebar.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-07-22 17:44:02 -07:00 committed by Tim Abbott
parent 0ad8da139e
commit 2aae92b6e3
1 changed files with 16 additions and 19 deletions

View File

@ -24,35 +24,32 @@ exports.update_count_in_dom = function (unread_count_elem, count) {
value_span.text(count); value_span.text(count);
}; };
exports.stream_sidebar = (function () { class StreamSidebar {
const self = {}; rows = new Map(); // stream id -> row widget
self.rows = new Map(); // stream id -> row widget set_row(stream_id, widget) {
this.rows.set(stream_id, widget);
}
self.set_row = function (stream_id, widget) { get_row(stream_id) {
self.rows.set(stream_id, widget); return this.rows.get(stream_id);
}; }
self.get_row = function (stream_id) { has_row_for(stream_id) {
return self.rows.get(stream_id); return this.rows.has(stream_id);
}; }
self.has_row_for = function (stream_id) { remove_row(stream_id) {
return self.rows.has(stream_id);
};
self.remove_row = function (stream_id) {
// This only removes the row from our data structure. // This only removes the row from our data structure.
// Our caller should use build_stream_list() to re-draw // Our caller should use build_stream_list() to re-draw
// the sidebar, so that we don't have to deal with edge // the sidebar, so that we don't have to deal with edge
// cases like removing the last pinned stream (and removing // cases like removing the last pinned stream (and removing
// the divider). // the divider).
self.rows.delete(stream_id); this.rows.delete(stream_id);
}; }
}
return self; exports.stream_sidebar = new StreamSidebar();
})();
function get_search_term() { function get_search_term() {
const search_box = $(".stream-list-filter"); const search_box = $(".stream-list-filter");