mirror of https://github.com/zulip/zulip.git
list_render: Add replace_list_data().
The data() function was used in only one place, and it can be replaced now with two simple lines of code.
This commit is contained in:
parent
d406df75b3
commit
cf741e9a11
|
@ -185,8 +185,7 @@ run_test('filtering', () => {
|
|||
'fox',
|
||||
];
|
||||
|
||||
widget.data(new_data);
|
||||
widget.clean_redraw();
|
||||
widget.replace_list_data(new_data);
|
||||
expected_html =
|
||||
'<div>greta</div>' +
|
||||
'<div>gary</div>' +
|
||||
|
|
|
@ -128,32 +128,6 @@ exports.create = function ($container, list, opts) {
|
|||
meta.offset += load_count;
|
||||
};
|
||||
|
||||
// reset the data associated with a list. This is so that instead of
|
||||
// initializing a new progressive list render instance, you can just
|
||||
// update the data of an existing one.
|
||||
widget.data = function (...args) {
|
||||
// if no args are provided then just return the existing data.
|
||||
// this interface is similar to how many jQuery functions operate,
|
||||
// where a call to the method without data returns the existing data.
|
||||
if (args.length === 0) {
|
||||
return meta.list;
|
||||
}
|
||||
const [data] = args;
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
meta.list = data;
|
||||
meta.filtered_list = data;
|
||||
|
||||
widget.filter_and_sort();
|
||||
widget.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
blueslip.warn("The data object provided to the progressive" +
|
||||
" list render is invalid");
|
||||
};
|
||||
|
||||
widget.clear = function () {
|
||||
$container.html("");
|
||||
meta.offset = 0;
|
||||
|
@ -245,6 +219,16 @@ exports.create = function ($container, list, opts) {
|
|||
}
|
||||
};
|
||||
|
||||
widget.replace_list_data = function (list) {
|
||||
/*
|
||||
We mostly use this widget for lists where you are
|
||||
not adding or removing rows, so when you do modify
|
||||
the list, we have a brute force solution.
|
||||
*/
|
||||
meta.list = list;
|
||||
widget.hard_redraw();
|
||||
};
|
||||
|
||||
// add built-in generic sort functions.
|
||||
widget.add_generic_sort_function("alphabetic", function (prop) {
|
||||
return function (a, b) {
|
||||
|
|
|
@ -188,8 +188,7 @@ exports.update_subscribers_list = function (sub) {
|
|||
// stream is open.
|
||||
if (subscribers_list) {
|
||||
stream_edit.sort_but_pin_current_user_on_top(users);
|
||||
subscribers_list.data(users);
|
||||
subscribers_list.clean_redraw();
|
||||
subscribers_list.replace_list_data(users);
|
||||
}
|
||||
$(".subscriber_list_settings_container").show();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue