Unified components and observable structure

This commit is contained in:
squidfunk
2020-03-05 17:17:15 +01:00
parent 6e6868b8cd
commit 9738c12cc9
149 changed files with 11475 additions and 1095 deletions

View File

@@ -35,11 +35,13 @@ import {
Viewport,
getElement,
watchViewportAt
} from "observables"
} from "browser"
import { useComponent } from "../../_"
import { paintHeaderType } from "../paint"
import { watchHeader } from "../watch"
import {
applyHeaderType,
watchHeader
} from "../react"
/* ----------------------------------------------------------------------------
* Types
@@ -104,7 +106,7 @@ export function mountHeader(
return y >= hx.offsetHeight ? "page" : "site"
}),
distinctUntilChanged(),
paintHeaderType(title)
applyHeaderType(title)
)
),
startWith<HeaderType>("site")

View File

@@ -21,6 +21,5 @@
*/
export * from "./_"
export * from "./apply"
export * from "./paint"
export * from "./watch"
export * from "./react"
export * from "./set"

View File

@@ -1,63 +0,0 @@
/*
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
import {
MonoTypeOperatorFunction,
animationFrameScheduler,
pipe
} from "rxjs"
import { finalize, observeOn, tap } from "rxjs/operators"
import { HeaderType } from "../_"
import {
resetHeaderTitleActive,
setHeaderTitleActive
} from "../apply"
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Paint header title type
*
* @param el - Header title element
*
* @return Operator function
*/
export function paintHeaderType(
el: HTMLElement
): MonoTypeOperatorFunction<HeaderType> {
return pipe(
/* Defer repaint to next animation frame */
observeOn(animationFrameScheduler),
tap(type => {
setHeaderTitleActive(el, type === "page")
}),
/* Reset on complete or error */
finalize(() => {
resetHeaderTitleActive(el)
})
)
}

View File

@@ -20,12 +20,28 @@
* IN THE SOFTWARE.
*/
import { Observable, of } from "rxjs"
import { distinctUntilKeyChanged, switchMap } from "rxjs/operators"
import {
MonoTypeOperatorFunction,
Observable,
animationFrameScheduler,
of,
pipe
} from "rxjs"
import {
distinctUntilKeyChanged,
finalize,
observeOn,
switchMap,
tap
} from "rxjs/operators"
import { Viewport } from "observables"
import { Viewport } from "browser"
import { Header } from "../_"
import { Header, HeaderType } from "../_"
import {
resetHeaderTitleActive,
setHeaderTitleActive
} from "../set"
/* ----------------------------------------------------------------------------
* Helper types
@@ -72,3 +88,30 @@ export function watchHeader(
})
)
}
/* ------------------------------------------------------------------------- */
/**
* Apply header title type
*
* @param el - Header title element
*
* @return Operator function
*/
export function applyHeaderType(
el: HTMLElement
): MonoTypeOperatorFunction<HeaderType> {
return pipe(
/* Defer repaint to next animation frame */
observeOn(animationFrameScheduler),
tap(type => {
setHeaderTitleActive(el, type === "page")
}),
/* Reset on complete or error */
finalize(() => {
resetHeaderTitleActive(el)
})
)
}