list_render: Clean up initialization.

For some widgets we now avoid duplicate redraw
events from this old pattern:

    widget = list_render.create(..., {
    }).init();
    widget.sort(...);

The above code was wasteful and possibly
flicker-y due to the fact that `init` and
`sort` both render.

Now we do this:

    widget = list_render.create(..., {
        init_sort: [...],
    });

For other widgets we just clean up the need
to call `init()` right after `create()`.

We also allow widgets to pass in `sort_fields`
during initialization (since you may want to
have `init_sort` use a custom sort before the
first render.)
This commit is contained in:
Steve Howell
2020-04-11 14:23:29 +00:00
committed by Tim Abbott
parent ef749dba31
commit 0681e4ba36
12 changed files with 84 additions and 100 deletions

View File

@@ -106,8 +106,7 @@ run_test('scrolling', () => {
};
container.html = (html) => { assert.equal(html, ''); };
const widget = list_render.create(container, items, opts);
widget.init();
list_render.create(container, items, opts);
assert.deepEqual(
container.appended_data.html(),
@@ -154,7 +153,6 @@ run_test('filtering', () => {
container.html = (html) => { assert.equal(html, ''); };
let widget = list_render.create(container, list, opts);
widget.init();
let expected_html =
'<div>apple</div>' +
@@ -186,7 +184,7 @@ run_test('filtering', () => {
];
widget.data(new_data);
widget.init();
widget.redraw();
expected_html =
'<div>greta</div>' +
'<div>gary</div>' +