mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 20:49:20 +03:00
35 lines
972 B
JavaScript
35 lines
972 B
JavaScript
ko['extenders'] = {
|
|
'debounce': (target, timeout) => target.limit(callback => debounce(callback, timeout)),
|
|
|
|
'rateLimit': (target, timeout) => target.limit(callback => throttle(callback, timeout)),
|
|
|
|
'notify': (target, notifyWhen) => {
|
|
target.equalityComparer = notifyWhen == "always" ?
|
|
null : // null equalityComparer means to always notify
|
|
valuesArePrimitiveAndEqual;
|
|
}
|
|
};
|
|
|
|
function valuesArePrimitiveAndEqual(a, b) {
|
|
return a === b && a !== Object(a);
|
|
}
|
|
|
|
function throttle(callback, timeout) {
|
|
var timeoutInstance;
|
|
return () => {
|
|
if (!timeoutInstance) {
|
|
timeoutInstance = setTimeout(() => {
|
|
timeoutInstance = 0;
|
|
callback();
|
|
}, timeout);
|
|
}
|
|
};
|
|
}
|
|
|
|
function debounce(callback, timeout) {
|
|
var timeoutInstance;
|
|
return () => {
|
|
clearTimeout(timeoutInstance);
|
|
timeoutInstance = setTimeout(callback, timeout);
|
|
};
|
|
}
|