fcronjs
Package for manage function call timetable.
WARNING:
Since version 2.0.1 the contract for debounce and throttle methods has been changed. New contract is compatible for old throttle's contract but incompatible for debounce's contract in previous versions.
Content
GitHub.
Install.
npm install fcronjs --save
Usage.
Import fcronjs
form package:
;
or add script fcron.js from web/fcron.js in branch master and add itinto your HTML:
and use:
debounce
;
or
var debounce = fcronjsdebounce;
Method debounce creates Hi Ordered Function which sets minimal period between calls. It has two arguments:
-
{Function} func - original function.
-
{Object|number} [secondArgument] - in case Object - configurin object, in other case - [config#delay = 100].
Configuring object has 3 parameters:
- {number} [config#delay = 100] - minimal number of milliseconds to be waited between calls.
- {boolean} [config#immediate = false] - when immediate = true function calls immediatly if it is possible, in other case it cals after delay ms.
- {Object} [config#context] - context object of function. If context was set it can not be changed or removed.
For examlpe:
; const f = ; const timeouts = 0 10 100 1000 1010 2000 3000 3500 3550 4200; timeouts;
In output very likely will be 0
, 1010
, 3000
, and 4200
. And 10
, 100
, 1000
, 2000
, 3500
likely to be ignored.
throttle
;
or
var throttle = fcronjsthrottle;
Method throttle creates Hi Ordered Function which sets minimal period between calls and execute last call every time at the end.
-
{Function} func - original function.
-
{Object|number} [secondArgument] - in case Object - configurin object, in other case - [config#delay = 100].
Configuring object has 3 parameters:
- {number} [config#delay = 100] - minimal number of milliseconds to be waited between calls.
- {boolean} [config#immediate = false] - when immediate = true function calls immediatly if it is possible, in other case it cals after delay ms.
For examlpe:
; const f = ; const timeouts = 0 10 100 1000 1010 2000 3000 3500 3550 10000 10001; timeouts;
In output very likely will be 0
, 1000
, 1010
(as a last), 2000
, 3000
, and 3550
(as a last), 10000
, and 10001
(as a last). And 10
, 100
, 3500
likely to be ignored.
waiter
;
or
var waiter = fcronjswaiter;
Method waiter creates Hi Ordered Function which at call waits some time befor call original function, and in case of second call before function called, it stops waiting without calling function.
- {Function} func - original function.
- {number} [delay = 100] - number of milliseconds must be waited before original function call.
For examlpe:
; const DELAY = 1000; const f = ; ; // will be executed after 1 second ;
Support.
Supported browsers IE9+.
License
MIT Copyright (c) 2017 Kuznetsov Leonid.