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-sloth

v0.1.3

Published

Synchronous lazy loader to load big list any or kind of that! In Ember Land

Downloads

6

Readme

ember-sloth

Sloth will help you to load a huge list lazily. You can lazy load your data using either of the below technique

Perfectly lightweight - 130B Min + GZip. Play around with the demo

Why Sloth?

Sloth is meant for his slowness. Is that the reason? No, the reason is, we are going to make him a lot faster 😉

Usage

Sloth will give you a property dataForCurrentView to loop over the passed data. Since Ember 🐹 will do the heavy weight-lifting for us by efficiently loading the list using each helper, you can relax and sit back!

Additionally, you can pass loadCount and initialDataCount to customize the initial load.

  • initialDataCount : How many items should Sloth render on initial load. Defaults to 20
  • loadCount : How many items should the Sloth load on reaching the threshold (2/3 of the current list length). Defaults to 10

On Scroll into the list

Since Sloth will watch the scroll event on a list container to lazy load the data, make sure you create a container manually with the id attribute as slothScroll (or anything of your choice) and specify the definite height. If your container has the id other than slothScroll, then pass the name of the id attribute (to bind action) as an argument, scrollContainer:

{{!-- template.hbs --}}
{{#sloth-loader 
  data=thatBigListofPosts 
  initialDataCount=50 
  loadCount=20 
  scrollContainer="postContainer"
  as |sloth|
}}

  <div id="postContainer" class="post-container"> {{!-- container --}}
    {{#each sloth.dataForCurrentView as |post|}}
      {{pretty-post post=post}}
    {{/each}}
  </div>

{{/sloth-loader}}
/* app.css */
.post-container {
  height: 75vh;
}

NOTE: If your data should be load highly on demand (on scroll) like a facebook feed. This option will be the apt one. If you don't have a specific use case and the only requirement is to defer the loading of a bulk list to avoid janky pages, you should definitely try the background task method as it won't need any extra work from the host application side.

Background Tasks

This would be the most appropriate choice in most cases since it won't require any additional containers to create nor any style manipulations. The list will be loaded lazily on the window's requestIdleCallback. The event will be fired when the browser gets an idle relaxing time. It would be an appropriate time to load the remaining items onto the list. If the browser doesn't support requestIdleCallback then the data will be loaded using setTimeout with an interval time.

To use this method, we need to pass two arguments:

  • enableBackgroundLoad : Defaults to false
  • loadInterval : Denoted in ms and defaults to 200 (200ms). This serves two purposes:
    1. When the browser supports requestIdleCallback, then loadInterval will be used as a threshold time. If the event is not fired within the given time, data loading will be triggered forcefully.
    2. When the browser doesn't support requestIdleCallback and fell back to setTimeout, then this time will be used as a timeout for setTimeout.
{{!-- template.hbs --}}

{{#sloth-loader 
  data=thatBigListofPosts 
  initialDataCount=50 
  loadCount=20 
  enableBackgroundLoad=true
  loadInterval=500
  as |sloth|
}}

  {{#each sloth.dataForCurrentView as |post|}}
    {{pretty-post post=post}}
  {{/each}}

{{/sloth-loader}}

Haaalp

Let's work together to make Sloth awesome:

  • Sloth has zero test. Need help in writing sophisticated tests.
  • Exploring Intersection Observer API for data load