Last active
March 20, 2019 09:14
-
-
Save Sawtaytoes/4a140cb5fca6ed0014d4d026bd042595 to your computer and use it in GitHub Desktop.
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
const render$ = new Subject() | |
const nodesEpic = ( | |
action$, | |
state$, | |
) => ( | |
action$ | |
.pipe( | |
ofType(START_PROCESSING), | |
delay(0), | |
switchMap(() => ( | |
of(state$.value) | |
.pipe( | |
mergeMap(({ | |
nodes, | |
}) => ( | |
nodes | |
)), | |
mergeMap(({ | |
id, | |
}) => ( | |
render$ | |
.pipe( | |
filter(({ | |
id: updatedNodeId, | |
}) => ( | |
updatedNodeId === id | |
)), | |
startWith(0), | |
delay(getRandomTimeout()), | |
) | |
.pipe( | |
mapTo(id), | |
) | |
)), | |
bufferTime(40), | |
filter(( | |
ids, | |
) => ( | |
ids | |
.length > 0 | |
)), | |
mergeAll(), | |
tap(( | |
id, | |
) => { | |
const node = ( | |
document | |
.getElementById(`node-${id}`) | |
) | |
node.innerHTML = getRandomValue() | |
node.style.color = getRandomColor() | |
render$ | |
.next({ id }) | |
}), | |
) | |
)), | |
ignoreElements(), | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment