count-slowly

1.0.0 • Public • Published

count-slowly

Usage

const countSlowly = require('count-slowly');

const cs = countSlowly({ stepDuration: 100 });

// Set the initial value
cs.set(1);
// Handle values between your final value
cs.onUpdate((tempValue) => {
  // Handle the temp value
});

// Update value when needed
cs.update(100);

// Skip directly to the new value. Calls onUpdate callback with final value then stops.
cs.hurry();

// Stops the onUpdate callbacks without skipping to new value.
cs.stop();

factory function

Rely on the .update() method to determine the values.

const cs = countSlowly();

Set the starting value straight-away.

const cs = countSlowly({}, 50);

Set a default duration to stay on each step

const cs = countSlowly({ stepDuration: 100 });

Set the default length of time to arrive at the new count

const cs = countSlowly({ totalDuration: 2000 });

.set()

Set an initial integer value. This will call the .onUpdate() callback once if it has been set.

cs.set(1);

.onUpdate()

Set the callback from each integer between the old value and the new value.

cs.onUpdate((tempValue) => {
  console.log(`Called with ${tempValue}`);
});

.update()

Set a new value. This will call the .onUpdate() callback for each integer between the old integer and the new integer according to either the factory function's stepDuration or totalDuration value.

cs.update(100);

Set a new value, calling the .onUpdate() callback every 50ms regardless of the factory function's stepDuration or totalDuration value.

cs.update(100, {
  overrideStepDuration: 50,
});

Set a new value, calling the .onUpdate() callback as often as needed in order to invoke the callback with 100 after 1200ms regardless of the factory function's stepDuration or totalDuration value.

cs.update(100, {
  overrideTotalDuration: 1200,
});

.hurry()

Skip directly to the new value. Calls the .onUpdate() callback with final value then stops.

cs.hurry();

.stop()

Stop the .onUpdate() callbacks without skipping to the new value.

cs.stop();

Examples

Readme

Keywords

none

Package Sidebar

Install

npm i count-slowly

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

15.5 kB

Total Files

10

Last publish

Collaborators

  • wilderbeest