Want to render a large list of items in paginated groups, but Ember's DOM teardowns and setups are reducing performance, and "canonical" smoke-and-mirrors patterns (e.g. ember-collection) is causing memory-leak crashes?
This addon is for you.
ember install ember-large-list
It's also up to you to provide the compute
template helper.
This repo just sorta assumes you have it. (see how to implement)
note: you can also use
offset
andlimit
instead ofstartIndex
andperPage
; they are aliased
Very simple, instead of using each
, we use n.times
. Consider the following pseudo-code in ruby:
paged_list = items.slice(start_index).take(per_page)
per_page.times do |i|
yield paged_list[i]
end
We can translate this idea over to hbs and javascript like so:
large-list/component.js
Component.extend({
startIndex: 0,
perPage: 5,
items: [
{ name: 'God of War', icon: 'images/god-of-war.png' },
// ...
]
});
large-list/template.hbs
And that's it! Instead of depending on each
to iterate through out array, we use generic helpers let
, take
, and n-times
and suddenly, we guarantee ourselves the following:
- only
perPage=5
elements are ever rendered to dom - no custom manipulation of DOM (e.g.
this.element
) happens - no weird
registerChild
anti-pattern
Not really, given how simple the actual solution to performant rendering is, all you need is the take
helper and the n-times
component
However, this addon does provide the helpful following
- scroll support
- action support
git clone <repository-url>
cd ember-large-list
npm install
npm run lint:hbs
npm run lint:js
npm run lint:js -- --fix
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versions
ember serve
- Visit the dummy application at http://localhost:4200.
For more information on using ember-cli, visit https://ember-cli.com/.
This project is licensed under the MIT License.