项目作者: shystruk

项目描述 :
⏰ start and clear interval without setting a variable, clear interval anywhere you want
高级语言: JavaScript
项目地址: git://github.com/shystruk/SetIntervalJS.git
创建时间: 2017-11-29T14:51:33Z
项目社区:https://github.com/shystruk/SetIntervalJS

开源协议:MIT License

下载


SetIntervalJS Twitter URL%20%F0%9F%91%8C%F0%9F%98%80&tw_p=tweetbutton&url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fset-interval&via=shystrukk)

MIT Licence Build Status npm version Known Vulnerabilities

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👌.

Getting SetIntervalJS

npm

npm install --save set-interval

yarn

yarn add set-interval --save

Examples

  1. SetInterval.start(function, milliseconds, key_string)

Basic example

  1. import SetInterval from 'set-interval'
  2. SetInterval.start(callback, 1000, 'test')
  3. SetInterval.clear('test')

Multiple instances

  1. // -> ./start.js
  2. import SetInterval from 'set-interval'
  3. SetInterval.start(callback, 1000, 'test')
  4. SetInterval.start(callback_2, 1000, 'test_2')
  5. SetInterval.start(callback_3, 1000, 'test_3')
  6. // -> ./clear.js
  7. import SetInterval from 'set-interval'
  8. SetInterval.clear('test')
  9. SetInterval.clear('test_2')
  10. 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