@tko/computed
Version:
TKO Computed Observables
22 lines (21 loc) • 511 B
JavaScript
// @tko/computed 🥊 4.0.0-beta1.3 ESM
import {
extenders
} from "@tko/observable";
import {
computed
} from "./computed";
export function throttleExtender(target, timeout) {
target.throttleEvaluation = timeout;
var writeTimeoutInstance = null;
return computed({
read: target,
write: function(value) {
clearTimeout(writeTimeoutInstance);
writeTimeoutInstance = setTimeout(function() {
target(value);
}, timeout);
}
});
}
extenders.throttle = throttleExtender;