Skip to content

Commit

Permalink
refactor(isHydrated): use scan() operator instead of a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Apr 9, 2016
1 parent 1f720ae commit f6fea13
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main.js
Expand Up @@ -20,13 +20,12 @@ e.xhr = (fetch, request, observer) => Rx.Observable.merge(
)

e.isHydrated = events => {
var hydrationCount = 0
const mount = events.filter(x => x.event === 'WILL_MOUNT').map(1)
const unmount = events.filter(x => x.event === 'WILL_UNMOUNT').map(-1)
return Rx.Observable
.merge(mount, unmount).startWith(0)
.tap(x => hydrationCount += x)
.map(() => hydrationCount > 0)
.scan((m, x) => x + m, 0)
.map(x => x > 0)
.distinctUntilChanged()
}

Expand Down

0 comments on commit f6fea13

Please sign in to comment.