Improved rendering performance by omitting unnecessary emits for hero and tabs

This commit is contained in:
squidfunk
2020-03-29 14:41:52 +02:00
parent 155ce0a268
commit e5f20b540d
7 changed files with 18 additions and 10 deletions

View File

@@ -21,7 +21,11 @@
*/
import { Observable, OperatorFunction, pipe } from "rxjs"
import { distinctUntilChanged, map, switchMap } from "rxjs/operators"
import {
distinctUntilKeyChanged,
map,
switchMap
} from "rxjs/operators"
import { Viewport, watchViewportAt } from "browser"
@@ -69,7 +73,7 @@ export function mountHero(
switchMap(el => watchViewportAt(el, { header$, viewport$ })
.pipe(
map(({ offset: { y } }) => ({ hidden: y >= 20 })),
distinctUntilChanged(),
distinctUntilKeyChanged("hidden"),
applyHero(el)
)
)

View File

@@ -21,7 +21,11 @@
*/
import { Observable, OperatorFunction, of, pipe } from "rxjs"
import { distinctUntilChanged, map, switchMap } from "rxjs/operators"
import {
distinctUntilKeyChanged,
map,
switchMap
} from "rxjs/operators"
import { Viewport, watchViewportAt } from "browser"
@@ -76,7 +80,7 @@ export function mountTabs(
return watchViewportAt(el, { header$, viewport$ })
.pipe(
map(({ offset: { y } }) => ({ hidden: y >= 10 })),
distinctUntilChanged(),
distinctUntilKeyChanged("hidden"),
applyTabs(el)
)