list_widget: Allow instance to change load_count as per state.

Add a function which is called before every render to
get the number of items it can render. This can be used by
instance to load custom number of items as per its state.
This commit is contained in:
Aman Agrawal
2021-05-06 17:07:03 +00:00
committed by Tim Abbott
parent 7d6b65e8f4
commit d2e3dbeb50
2 changed files with 12 additions and 1 deletions

View File

@@ -199,6 +199,12 @@ run_test("not_scrolling", () => {
post_scroll__pre_render_callback_called = true;
};
let get_min_load_count_called = false;
const get_min_load_count = (offset, load_count) => {
get_min_load_count_called = true;
return load_count;
};
for (let i = 0; i < 200; i += 1) {
items.push("item " + i);
}
@@ -208,6 +214,7 @@ run_test("not_scrolling", () => {
simplebar_container: scroll_container,
is_scroll_position_for_render: () => false,
post_scroll__pre_render_callback,
get_min_load_count,
};
container.html = (html) => {
@@ -229,6 +236,7 @@ run_test("not_scrolling", () => {
// appended_data remains the same.
assert.deepEqual(container.appended_data.html(), items.slice(0, 80).join(""));
assert.equal(post_scroll__pre_render_callback_called, true);
assert.equal(get_min_load_count_called, true);
});
run_test("filtering", () => {

View File

@@ -194,7 +194,10 @@ export function create($container, list, opts) {
// and renders the next block of messages automatically
// into the specified container.
widget.render = function (how_many) {
const load_count = how_many || DEFAULTS.LOAD_COUNT;
let load_count = how_many || DEFAULTS.LOAD_COUNT;
if (opts.get_min_load_count) {
load_count = opts.get_min_load_count(meta.offset, load_count);
}
// Stop once the offset reaches the length of the original list.
if (meta.offset >= meta.filtered_list.length) {