Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-loading-spinner

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-loading-spinner

Advanced handling of loaders/spinners based on one or multiple Promises

  • 3.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
348
increased by8.75%
Maintainers
1
Weekly downloads
 
Created
Source

NPM version Downloads star this repo fork this repo CI Coverage Status

promise-loading-spinner

Advanced handling of loaders/spinners based on one or multiple Promises.

Why?

  • Show a spinner using a promise Spinner will disappear when promise is resolved
  • No Spinner for short operations Spinner won't show up for short operations so operation doesn't feel lazy
  • Support of multiple promises Spinner will disappear when the last unresolved promise is resolved
  • Operations in a sequence If there are multiple operations in a sequence the spinner will disappear when the last operation is finished

See this Codepen.

Install

$ yarn add promise-loading-spinner

Usage

This shows loading spinners based on promises.

import PromiseLoadingSpinner from 'promise-loading-spinner'

const loader = new PromiseLoadingSpinner({
  // options
})

// ...

const myPromise = new Promise((resolve) => {
  setTimeout(() => {
    resolve('done')
  }, 5000)
})

loader.loader(myPromise)

You can also use a wrapper function for a function that returns a promise or uses await:

const myFunction = loader.wrapFunction(async (url) => {
  const response = await fetch(url)
  const result = await response.json()
  return result
})

myFunction(someUrl)

It also exports a method decorator:

const loaderDecorator = loader.decorator.bind(loader)

class MyClass {
  @loaderDecorator()
  async foo() {
    // ...
  }
}

All ways to add a promise can also take a configuration object as an optional parameter.

OptionDescriptionType
skipDelaysSkip all delays (initDelay, delay)boolean

Examples:


// loader
loader(promise, { skipDelays: true })

// wrapFunction:
wrapFunction(fnc, { skipDelays: true })

// decorator:
class MyClass {
  @loaderDecorator({ skipDelays: true })
  async foo() {
    // ...
  }
}

Options

OptionDescriptionTypeDefault
delayTime (ms) until spinner will show up to handle short operations without a spinnerNumber300
closeDelayTime (ms) to wait until last promise is resolved to enable multiple operations in a sequence without a "flickering" spinnerNumber10
initDelayDelay (ms) after loader initialization to suppress spinners on page loadNumber1000
loaderElementthe element which represents the spinnerstring (selector) or HTMLElementjs-page-loader
classActiveclass name used to show the spinnerstringis-active

License

MIT © 2023 Jens Simon

Keywords

FAQs

Package last updated on 29 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc