mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
Clean up startup code for streams.
The startup code in subs.js used to intermingle data
stuff and UI stuff in a loop inside a called function,
which made the code hard to reason about.
Now there is a clear separation of concerns, with these methods
being called in succession:
stream_data.initialize_from_page_params();
stream_list.create_initial_sidebar_rows();
The first method was mostly extracted from subs.js, but I simplified
some things, like not needing to make a copy of the hashes
we were passed in, plus I now garbage collect email_dict. Also,
the code path that initialize_from_page_params() mostly replaces
used to call create_sub(), which fired a trigger, but now it
just does data stuff.
Once the data structure is built up, it's a very simple matter
to build the initial sidebar rows, and that's what the second
method does.
This commit is contained in:
@@ -46,7 +46,22 @@ function filter_streams_by_search(streams) {
|
||||
return filtered_streams;
|
||||
}
|
||||
|
||||
exports.create_initial_sidebar_rows = function () {
|
||||
// This code is slightly opaque, but it ends up building
|
||||
// up list items and attaching them to the "sub" data
|
||||
// structures that are kept in stream_data.js.
|
||||
var subs = stream_data.subscribed_subs();
|
||||
|
||||
_.each(subs, function (sub) {
|
||||
exports.create_sidebar_row(sub);
|
||||
});
|
||||
};
|
||||
|
||||
exports.build_stream_list = function () {
|
||||
// This function assumes we have already created the individual
|
||||
// sidebar rows. Our job here is to build the bigger widget,
|
||||
// which largely is a matter of arranging the individual rows in
|
||||
// the right order.
|
||||
var streams = stream_data.subscribed_streams();
|
||||
if (streams.length === 0) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user