Skip to content

Instantly share code, notes, and snippets.

@Sawtaytoes
Last active March 20, 2019 09:14
Show Gist options
  • Save Sawtaytoes/4a140cb5fca6ed0014d4d026bd042595 to your computer and use it in GitHub Desktop.
Save Sawtaytoes/4a140cb5fca6ed0014d4d026bd042595 to your computer and use it in GitHub Desktop.
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