Refactored header title component

This commit is contained in:
squidfunk
2020-02-17 16:25:49 +01:00
parent 7876148fbd
commit dd40bc2fcf
23 changed files with 308 additions and 126 deletions

View File

@@ -52,7 +52,7 @@ interface WatchOptions {
*
* This function returns an observables that fetches a document if the provided
* location observable emits a new value (i.e. URL). If the emitted URL points
* to the same page, the request is effectively ignored (e.g. when only the
* to the same page, the request is effectively ignored (i.e. when only the
* fragment identifier changes).
*
* @param options - Options

View File

@@ -21,14 +21,7 @@
*/
import { Observable, fromEvent, merge } from "rxjs"
import {
distinctUntilKeyChanged,
map,
shareReplay,
startWith
} from "rxjs/operators"
import { Viewport } from "../../viewport"
import { map, shareReplay, startWith } from "rxjs/operators"
/* ----------------------------------------------------------------------------
* Types
@@ -42,17 +35,6 @@ export interface ElementOffset {
y: number /* Vertical offset */
}
/* ----------------------------------------------------------------------------
* Helper types
* ------------------------------------------------------------------------- */
/**
* Watch options
*/
interface WatchOptions {
viewport$: Observable<Viewport> /* Viewport observable */
}
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
@@ -77,21 +59,16 @@ export function getElementOffset(el: HTMLElement): ElementOffset {
* Watch element offset
*
* @param el - Element
* @param options - Options
*
* @return Element offset observable
*/
export function watchElementOffset(
el: HTMLElement, { viewport$ }: WatchOptions
el: HTMLElement
): Observable<ElementOffset> {
const scroll$ = fromEvent(el, "scroll")
const size$ = viewport$
.pipe(
distinctUntilKeyChanged("size")
)
/* Merge into a single hot observable */
return merge(scroll$, size$)
return merge(
fromEvent<UIEvent>(el, "scroll"),
fromEvent<UIEvent>(window, "resize")
)
.pipe(
map(() => getElementOffset(el)),
startWith(getElementOffset(el)),

View File

@@ -36,8 +36,7 @@ export function watchLocation(): Subject<string> {
const location$ = new Subject<string>()
fromEvent<PopStateEvent>(window, "popstate")
.pipe(
map(() => location.href),
share()
map(() => location.href)
)
.subscribe(location$)

View File

@@ -85,7 +85,7 @@ export function watchViewport(): Observable<Viewport> {
*
* @return Viewport observable
*/
export function watchViewportFrom(
export function watchViewportAt(
el: HTMLElement, { header$, viewport$ }: WatchRelativeOptions
): Observable<Viewport> {
return combineLatest([viewport$, header$])