npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-large-list

v1.0.0

Published

Alternative and simpler approach to ember-collections for rendering large arrays to dom

Downloads

11

Readme

ember-large-list

Build Status

see demo here

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.

Installation

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)

Usage

<ul>
  {{#large-list items=data startIndex=0 perPage=5 as |item globalIndex localIndex|}}
    {{my-row-presentation data=item}}
    {{!-- globalIndex goes from 0 to (data.length - 1) --}}
    {{!-- localIndex goes from 0 to (perPage - 1) --}}
  {{/large-list}}
</ul>

note: you can also use offset and limit instead of startIndex and perPage; they are aliased

How does it work?

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

{{#let (take items startIndex perPage) as |smallArray|}}
  {{#n-times perPage do |index|}}
    {{my-row-presentation data=(get smallArray index)}}
  {{/n-times}}
{{/let}}

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

Do I Even Need This Addon?

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

Contributing

Installation

  • git clone <repository-url>
  • cd ember-large-list
  • npm install

Linting

  • npm run lint:hbs
  • npm run lint:js
  • npm run lint:js -- --fix

Running tests

  • ember test – Runs the test suite on the current Ember version
  • ember test --server – Runs the test suite in "watch mode"
  • ember try:each – Runs the test suite against multiple Ember versions

Running the dummy application

For more information on using ember-cli, visit https://ember-cli.com/.

License

This project is licensed under the MIT License.