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:
Steve Howell
2016-10-17 10:34:58 -07:00
committed by Tim Abbott
parent d26942e72d
commit 7fd74c45d7
3 changed files with 45 additions and 45 deletions

View File

@@ -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;