UNPKG

suomifi-ui-components

Version:
49 lines (46 loc) 1.24 kB
import { __extends } from 'tslib'; import { Component } from 'react'; var Debounce = function (_super) { __extends(Debounce, _super); function Debounce() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.timeout = null; _this.debouncer = function (callback, value) { if (!callback) { return; } if (!_this.props.waitFor) { callback(value); return; } _this.cancelTimeout(); var waitFor = _this.props.waitFor; _this.timeout = setTimeout(function () { callback(value); }, waitFor); }; _this.cancelDebounce = function () { _this.cancelTimeout(); }; return _this; } Debounce.prototype.componentWillUnmount = function () { this.cancelTimeout(); }; Debounce.prototype.cancelTimeout = function () { if (this.timeout !== null) { clearTimeout(this.timeout); this.timeout = null; } }; Debounce.prototype.render = function () { var children = this.props.children; if (!!children) { return children(this.debouncer, this.cancelDebounce); } return null; }; return Debounce; }(Component); export { Debounce }; //# sourceMappingURL=Debounce.js.map