Socket
Socket
Sign inDemoInstall

autotimer

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    autotimer

Super simple timer that resets itself when called again.


Version published
Maintainers
1
Install size
4.49 kB
Created

Readme

Source

autoTimer

Automatically debounced timer.

Even if called if called multiple times, only the last call will be executed.

Installation

npm install autotimer

Usage

// require using commonJS
const AutoTimer = require('autotimer');

// or in es6, using a module bundler like webpack
import AutoTimer from 'autotimer';

// instantiate class
const timer = new Autotimer();

// just call the function with a delay in ms
timer(delay, callback);

// like setTimeout, it returns a timer
const timerOne = timer(delay, callback);

// that you can cancel if needed
clearTimeout(timerOne);

function responsive() {
  // do things
}

function scrolled() {
  // do things
}

/**
 * will call "responsive" only once the browser has finished resizing
 * and "scrolled" when the user has finished scrolling
 */

// init timers
const respTimer = new AutoTimer();
const scrollTimer = new Autotimer();

// call them
window.addEventListener('resize', () => {
  respTimer(100, responsive);
});

window.addEventListener('scroll', () => {
  scrollTimer(200, scrolled);
});

Keywords

FAQs

Last updated on 01 Nov 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc