

start and clear interval without setting a variable, clear interval anywhere
source link: https://www.tuicool.com/articles/hit/ymQ7ZvZ
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

SetIntervalJS
SetIntervalJS is a constructor which hide inside reference to setInterval() for cleaner usage. It helps to make your code cleaner and there is no need to have more variables for clearInterval() and you can clear interval anywhere you want :ok_hand: .
Getting SetIntervalJS
npm
npm install --save set-interval
yarn
yarn add set-interval --save
Examples
SetInterval.start(function, milliseconds, key_string)
Basic example
import SetInterval from 'set-interval' SetInterval.start(callback, 1000, 'test') SetInterval.clear('test')
Multiple instances
// -> ./start.js import SetInterval from 'set-interval' SetInterval.start(callback, 1000, 'test') SetInterval.start(callback_2, 1000, 'test_2') SetInterval.start(callback_3, 1000, 'test_3') // -> ./clear.js import SetInterval from 'set-interval' SetInterval.clear('test') SetInterval.clear('test_2') SetInterval.clear('test_3')
API
SetInterval.start(callback, milliseconds, key_string)
callback
Type: function
Function that gets called in each milliseconds interval
milliseconds
Type: number
Interval time in which callback function gets called
key_string
Type: string
Key name for which interval will be referenced
SetInterval.clear(key_string)
key_string
Type: string
Key name which was passed to .start method
Contributing
Any contributions you make are greatly appreciated .
Please read the Contributions Guidelines before submitting a PR.
License
MIT © Vasyl Stokolosa
Recommend
-
47
Today, we’d like to share some of our recent work on Sherlock that allowed a pretty significant speedup when listing files in directories with a lot of entries. Unlike our usual announcements, this post is more o...
-
53
To set correct system variable values is the essential step to get the correct server behavior against the workload. In MySQL, we have...
-
3
How to have a conversation on my park bench — or anywhere on the internet Let’s do a little e...
-
5
-
6
George Colony. Drawing by Chris Morris, Boston Globe. Forrester Research CEO George Colony...
-
5
LiveDocsBring live data from anywhere into your docs, without code
-
8
eSIM explained: Keep your iPhone connected anywhere without a physical SIM card
-
4
Clear the icon cache on a Mac when you start seeing generic icons in Finder or the Dock ...
-
9
Can i clear my data usage without root? ...
-
10
Apple Is the One Big Tech Company Without a Clear ChatGPT Strategy b...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK