kaiju
Version:
Virtual dom, observables and stateful components
26 lines (20 loc) • 621 B
JavaScript
import { Observable } from './observable';
export default function delay(delayValue, source) {
return Observable(function (add) {
var currentTimeouts = [];
var unsubSource = source.subscribe(function (val, name) {
var timeout = setTimeout(function () {
var index = currentTimeouts.indexOf(timeout);
currentTimeouts.splice(index, 1);
add(val, name);
}, delayValue);
currentTimeouts.push(timeout);
});
return function () {
currentTimeouts.forEach(function (timeout) {
return clearTimeout(timeout);
});
unsubSource();
};
});
}