Reduced pressure on GC

This commit is contained in:
squidfunk 2020-02-25 00:18:36 +01:00
parent 3091883b05
commit 63d4e327e6

View File

@ -21,7 +21,7 @@
*/
import { Observable, combineLatest } from "rxjs"
import { map, shareReplay } from "rxjs/operators"
import { distinctUntilKeyChanged, map, shareReplay } from "rxjs/operators"
import { Header } from "../../../header"
import {
@ -88,12 +88,22 @@ export function watchViewport(): Observable<Viewport> {
export function watchViewportAt(
el: HTMLElement, { header$, viewport$ }: WatchRelativeOptions
): Observable<Viewport> {
return combineLatest([header$, viewport$])
const offset$ = viewport$
.pipe(
map(([{ height }, { offset, size }]) => ({
distinctUntilKeyChanged("size"),
map<Viewport, ViewportOffset>(() => ({
x: el.offsetLeft,
y: el.offsetTop
}))
)
/* Compute relative viewport, return hot observable */
return combineLatest([header$, viewport$, offset$])
.pipe(
map(([{ height }, { offset, size }, { x, y }]) => ({
offset: {
x: offset.x - el.offsetLeft,
y: offset.y - el.offsetTop + height
x: offset.x - x,
y: offset.y - y + height
},
size
})),