mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user