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

idley

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idley

Helper functions for implementing the idle-until-urgent pattern

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Idley

Helper functions for implementing the idle-until-urgent pattern. For detailed explanation of this pattern, see this article from Philip Walton.

Installation

// with yarn
yarn add idley

// with npm
npm install idley

Usage

// ES2015+ and TS
import { computed, throttled, debounced } from 'idley'

// CommonJS
var idley = require('idley')

Functions

Computed

computed(fn: function): function

Creates a function that returns the result of executing the passed fn when the browser is idle. If the result is requested and it has not been computed yet, the function will be executed immediately.

const { computed } from 'idely'

const heavyTask = () => 5

const foo = computed(heavyTask)

console.log(foo()) // 5

Throttled

throttled(fn: function): function

Creates a throttled function that only invokes the passed fn at most once when the browser is idle.

const { throttled } from 'idely'

const heavyTask = (n) => console.log(n)

const foo = throttled(heavyTask)

foo(1)
foo(2)

// 2

Debounced

debounced(fn: function): function

Creates a debounced function that delays invoking the passed fn until the browser is idle.

const { debounced } from 'idely'

const heavyTask = (n) => console.log(n)

const foo = debounced(heavyTask)

foo(1)
foo(2)

// 1
// 2

This library relies on requestIdleCallback. It will degrade to requestAnimationFrame, or setTimeout in this order

Published under MIT Licence

(c) Yosbel Marin 2018

Keywords

FAQs

Package last updated on 21 Sep 2018

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