refactor: Inline message_list.add_and_rerender.

This commit is contained in:
Steve Howell 2018-05-13 20:05:41 +00:00 committed by Tim Abbott
parent 08fd2027a1
commit 6834745feb
2 changed files with 16 additions and 20 deletions

View File

@ -20,6 +20,16 @@ set_global('feature_flags', {});
var with_overrides = global.with_overrides; // make lint happy
function accept_all_filter() {
var filter = {
predicate: () => {
return () => true;
},
};
return filter;
}
run_test('basics', () => {
var table;
var filter = {};
@ -391,22 +401,15 @@ run_test('unmuted_messages', () => {
run_test('add_remove_rerender', () => {
var table;
var filter = {};
var filter = accept_all_filter();
var list = new MessageList(table, filter);
var messages = [{id: 1}, {id: 2}, {id: 3}];
list.data.unmuted_messages = function (msgs) { return msgs; };
global.with_stub(function (stub) {
list.view.rerender_the_whole_thing = stub.f;
list.add_and_rerender(messages);
// Make sure the function has triggered a rerender
// and that all 3 items were added to the list.
assert.equal(stub.num_calls, 1);
list.add_messages(messages);
assert.equal(list.num_items(), 3);
});
global.with_stub(function (stub) {
list.rerender = stub.f;

View File

@ -33,7 +33,9 @@ exports.MessageList.prototype = {
var interior_messages = info.interior_messages;
if (interior_messages.length > 0) {
self.add_and_rerender(top_messages.concat(interior_messages).concat(bottom_messages));
var all_messages = top_messages.concat(interior_messages).concat(bottom_messages);
self.data.add(all_messages);
self.view.rerender_the_whole_thing();
return true;
}
if (top_messages.length > 0) {
@ -264,15 +266,6 @@ exports.MessageList.prototype = {
this.view.prepend(viewable_messages);
},
add_and_rerender: function MessageList_add_and_rerender(messages) {
// To add messages that might be in the interior of our
// existing messages list, we just add the new messages and
// then rerender the whole thing.
this.data.add(messages);
this.view.rerender_the_whole_thing();
},
remove_and_rerender: function MessageList_remove_and_rerender(messages) {
this.data.remove(messages);
this.rerender();