Created
November 1, 2019 13:18
-
-
Save FbN/59863cfb6f60ecc671ee2d3250c0528a to your computer and use it in GitHub Desktop.
xstream version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function todoList (deferred) { | |
const ping$ = xs.create({ | |
start: function (listener) { | |
setTimeout(() => { | |
;[...Array(config.iterations).keys()].forEach(i => | |
listener.next(i) | |
) | |
}, 0) | |
}, | |
stop: function () {} | |
}) | |
const todo$ = ping$.map(todo) | |
const old$ = todo$.filter(todo => todo.id % 4 === 0).startWith({}) | |
const sample$ = sampleCombine(old$)(todo$).map(([last, old]) => ({ | |
...last, | |
old | |
})) | |
const list$ = sample$.fold((list, item) => [...list, item], []) | |
const end$ = list$.filter(list => list.length === config.iterations).take(1) | |
return end$.map(res => deferred.resolve(res)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment