mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Reduced pressure on GC
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Observable, combineLatest } from "rxjs"
|
import { Observable, combineLatest } from "rxjs"
|
||||||
import { map, shareReplay } from "rxjs/operators"
|
import { distinctUntilKeyChanged, map, shareReplay } from "rxjs/operators"
|
||||||
|
|
||||||
import { Header } from "../../../header"
|
import { Header } from "../../../header"
|
||||||
import {
|
import {
|
||||||
@@ -88,12 +88,22 @@ export function watchViewport(): Observable<Viewport> {
|
|||||||
export function watchViewportAt(
|
export function watchViewportAt(
|
||||||
el: HTMLElement, { header$, viewport$ }: WatchRelativeOptions
|
el: HTMLElement, { header$, viewport$ }: WatchRelativeOptions
|
||||||
): Observable<Viewport> {
|
): Observable<Viewport> {
|
||||||
return combineLatest([header$, viewport$])
|
const offset$ = viewport$
|
||||||
.pipe(
|
.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: {
|
offset: {
|
||||||
x: offset.x - el.offsetLeft,
|
x: offset.x - x,
|
||||||
y: offset.y - el.offsetTop + height
|
y: offset.y - y + height
|
||||||
},
|
},
|
||||||
size
|
size
|
||||||
})),
|
})),
|
||||||
|
|||||||
Reference in New Issue
Block a user