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

no-flicker-loading

v1.0.3

Published

:no_entry_sign::zap::hourglass_flowing_sand: Show loading without the dreaded flickering (or flashing) effect.

Downloads

10

Readme

no-flicker-loading

:no_entry_sign::zap::hourglass_flowing_sand: Show loading without the dreaded flickering (or flashing) effect.

CircleCI codecov

TLDR

Installation:

npm i no-flicker-loading

Usage example:

import noFlickerLoading from 'no-flicker-loading'

// Your loading function
const setLoading = isLoading => {
  console.log(isLoading ? 'Loading...' : 'Done.')
}

// Your async call
const fetchMyData = async () => {
  return 'Hello world'
}

const main = async () => {
  const data = await noFlickerLoading(
    async () => {
      /* This is your "long" async call */
      return await fetchMyData()
    },
    () => {
      /* This function called only when loading should be displayed */
      setLoading(true)
    }
  )

  setLoading(false)
}

main()

You can find a fully fledged working example in ./example:

cd ./example
npm i
npm start
# Go to http://localhost:1234

API

AsyncFunction: noFlickerLoading(
  main: AsyncFunction,       // <- Your main async function
  onLoading: Function,       // <- Called when you need to display loading
  {
    initDelay = 300: Number, // <- The initial delay before calling onLoading (in millisecond)
    minWait = 300: Number    // <- The minimum duration of the loading (in millisecond)
  }
) // <- Returns the result from main, or throws if main throws

Rationale behind no-flicker-loading

When using apps, users usually don't notice loading delays below a couple hundred of milliseconds. On the other hand, they perceive the wait to be much longer if they are briefly shown a loading screen.

The idea behind this project is to call an auxiliary "loading function" only if the main "async call" takes more than 300ms (this is the default value, which you can override). If the loading function is called, then we make sure that the loading phase lasts at least 300ms (again, this is a default value).

To avoid the flickering effect, no-flicker-loading applies the following strategy:

  • if main() takes less than 300ms (initDelay), then onLoading is never called,
  • if main() takes more than 300ms (initDelay), then onLoading is called and noFlickerLoading() lasts at least 300ms (minWait),
  • the result from main() is passed down and returned by noFlickerLoading(),
  • any error thrown by main() is thrown by noFlickerLoading().

License

ISC