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() 👌. SetIntervalJS has two methods start and clear. start method calls a function at specified intervals (in milliseconds) and clear clear the interval.
I find it to be super confusing because now instead of variables with limited scope you have a global variable that can refer to any interval you set. And once you start working with multiple instances it gets even more confusing you start to copy objects instead of just getting a new reference to a new interval. This leads to sort of unclear behaviour: what happens when you use the global variant and then create a copy with
Object.assign?Maybe I am just not getting what was wrong with the existing behaviour.
New API has been added. No variables, clear interval anywhere you want, single, multiple instances :) So simple and easy. Check it out - https://github.com/shystruk/SetIntervalJS
Yes, when you set an interval you can clear it from any place of your code (module) and it works only for one instance. Should find a way how to return a new instance for each import.
For multiple instances, Object.assign() helps you to make a copy and set another interval and do not touch a single one (original :)). And yes, for multiple instances you can not clear them anywhere, as you declare a variable.
Good points! Thanks!