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',
|
'fox',
|
||||||
];
|
];
|
||||||
|
|
||||||
widget.data(new_data);
|
widget.replace_list_data(new_data);
|
||||||
widget.clean_redraw();
|
|
||||||
expected_html =
|
expected_html =
|
||||||
'<div>greta</div>' +
|
'<div>greta</div>' +
|
||||||
'<div>gary</div>' +
|
'<div>gary</div>' +
|
||||||
|
|
|
@ -128,32 +128,6 @@ exports.create = function ($container, list, opts) {
|
||||||
meta.offset += load_count;
|
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 () {
|
widget.clear = function () {
|
||||||
$container.html("");
|
$container.html("");
|
||||||
meta.offset = 0;
|
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.
|
// add built-in generic sort functions.
|
||||||
widget.add_generic_sort_function("alphabetic", function (prop) {
|
widget.add_generic_sort_function("alphabetic", function (prop) {
|
||||||
return function (a, b) {
|
return function (a, b) {
|
||||||
|
|
|
@ -188,8 +188,7 @@ exports.update_subscribers_list = function (sub) {
|
||||||
// stream is open.
|
// stream is open.
|
||||||
if (subscribers_list) {
|
if (subscribers_list) {
|
||||||
stream_edit.sort_but_pin_current_user_on_top(users);
|
stream_edit.sort_but_pin_current_user_on_top(users);
|
||||||
subscribers_list.data(users);
|
subscribers_list.replace_list_data(users);
|
||||||
subscribers_list.clean_redraw();
|
|
||||||
}
|
}
|
||||||
$(".subscriber_list_settings_container").show();
|
$(".subscriber_list_settings_container").show();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue