Socket
Socket
Sign inDemoInstall

@yaireo/do-in

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @yaireo/do-in

A task runner which runs code repeatedly for for fix duration - calling a `step` method with the progress so far (between 0 and 1)


Version published
Maintainers
1
Install size
4.32 kB
Created

Readme

Source

Do-In

Run a task repeatedly in a fixed duration

A task runner which runs code repeatedly for X seconds and in a given duration of time and calling a step method with the progress so far. Most basic example is counting to to a number.

Basic usage


// This function will be called repeatedly until the duration has reached
var step = function(t, elapsed){
    // easing
    t = t*t*t;

    // calculate new value
    var value = 300 * t; // will count from 0 to 300

    // limit value ("t" might be higher than "1")
    if( t > 0.999 )
        value = 300;

    // print value (converts it to an integer)
    someElement.innerHTML = value|0;
}

// This function will be called once, when the task has finished
var done = function(){
    console.log('done counting!');
}

// Define the task's specific settings
var settings = {
    step     : step,  // callback function for every "frame" of the task
    duration : 3,     // in seconds
    done     : done,  // callback function when the task is done
    fps      : 60
}

// create a new "Do-in" task
var task = new Doin(settings)

task.start()

Run task.pause() to pause at any moment.

Run task.start() to continue (un-pause)

Usage for DOM updates

When using Do-in for DOM updates, like the in the example or for animation purposes, I would recommend not to set an fps option for the Do-in instance, but let it run at full-speed and only apply an fps mechanisn within your step method. This will ensure smooth consistant frame-rate, and will not drop frames, because Do-in uses requestAnimationFrame internally.

Demo page

Keywords

FAQs

Last updated on 14 Jan 2021

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