count-slowly
Usage
const countSlowly = require('count-slowly');
const cs = countSlowly({ stepDuration: 100 });
cs.set(1);
cs.onUpdate((tempValue) => {
});
cs.update(100);
cs.hurry();
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