Sha256: e223fc90d81f99eb827d65fe244a04a3ff5a82f44e239da3d00537e6ff235927
Contents?: true
Size: 1.75 KB
Versions: 4
Compression:
Stored size: 1.75 KB
Contents
const helpers = { debounce (func, wait, immediate) { let timeout, context, args; if (immediate) { return function () { let call_now = true; context = this; args = arguments; if (timeout) { call_now = false; clearTimeout(timeout); } timeout = setTimeout(function () { timeout = null; }, wait); if (call_now) func.apply(context, args); }; } else { return function () { context = this; args = arguments; if (timeout) clearTimeout(timeout); timeout = setTimeout(function () { timeout = null; func.apply(context, args); }, wait); }; } }, throttle (callback, time, immediate) { let timeout, call_at_end, context, args; return function () { context = this; args = arguments; // throttling block if (timeout) { call_at_end = true; return; } // throttler - fire only if there was event in the mean-time let timeout_f = function () { timeout = null; if (call_at_end) { call_at_end = false; timeout = setTimeout(timeout_f, time); callback.apply(context, args); } }; call_at_end = true; if (immediate) timeout_f(); else timeout = setTimeout(timeout_f, time); }; } }; export default helpers;
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
admission-0.4.5 | visualisation/helpers.js |
admission-0.4.4 | visualisation/helpers.js |
admission-0.2.8 | visualisation/helpers.js |
admission-0.2.7 | visualisation/helpers.js |