From 63703c007964d7fb40ec15c17bb8051a2e8fac25 Mon Sep 17 00:00:00 2001 From: splincode Date: Thu, 29 Aug 2024 13:42:15 +0300 Subject: [PATCH] chore(demo): add `tuiZonefreeScheduler` for `DEMO_PAGE_LOADED_PROVIDER` --- projects/demo/src/modules/app/abstract.app.ts | 27 ++++++++++++++++--- .../app/utils/ready-to-scroll-factory.ts | 25 ----------------- 2 files changed, 24 insertions(+), 28 deletions(-) delete mode 100644 projects/demo/src/modules/app/utils/ready-to-scroll-factory.ts diff --git a/projects/demo/src/modules/app/abstract.app.ts b/projects/demo/src/modules/app/abstract.app.ts index 6fb36a7061b1..7836a48ddd9a 100644 --- a/projects/demo/src/modules/app/abstract.app.ts +++ b/projects/demo/src/modules/app/abstract.app.ts @@ -4,15 +4,36 @@ import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; import type {Router} from '@angular/router'; import {ResizeObserverService} from '@ng-web-apis/resize-observer'; import {TUI_DOC_PAGE_LOADED} from '@taiga-ui/addon-doc'; -import {tuiInjectElement, tuiPure} from '@taiga-ui/cdk'; +import {tuiInjectElement, tuiPure, tuiZonefreeScheduler} from '@taiga-ui/cdk'; +import {debounceTime, map, type Observable, startWith} from 'rxjs'; -import {readyToScrollFactory} from './utils/ready-to-scroll-factory'; import {TUI_SELECTED_VERSION_META} from './version-manager/version-manager.providers'; export const DEMO_PAGE_LOADED_PROVIDER = { provide: TUI_DOC_PAGE_LOADED, deps: [ElementRef, ResizeObserverService], - useFactory: readyToScrollFactory, + useFactory( + hostElement: ElementRef, + resize$: Observable, + ): Observable { + return resize$.pipe( + startWith(null), + debounceTime(0, tuiZonefreeScheduler()), // Synchronous scrollIntoView (after click) does not work https://stackoverflow.com/a/56971002 + map(() => { + const host = hostElement.nativeElement; + const exampleElements = Array.from( + host.querySelectorAll('tui-doc-example'), + ); + const codeElements = Array.from(host.querySelectorAll('tui-doc-code')); + + return ( + exampleElements.every((el) => el.querySelector('.t-example')) && + codeElements.every((el) => el.querySelector('.t-code')) + ); + }), + takeUntilDestroyed(), + ); + }, }; @Directive({ diff --git a/projects/demo/src/modules/app/utils/ready-to-scroll-factory.ts b/projects/demo/src/modules/app/utils/ready-to-scroll-factory.ts deleted file mode 100644 index 7987a3dcec29..000000000000 --- a/projects/demo/src/modules/app/utils/ready-to-scroll-factory.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type {ElementRef} from '@angular/core'; -import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; -import type {Observable} from 'rxjs'; -import {debounceTime, map, startWith} from 'rxjs'; - -export function readyToScrollFactory( - hostElement: ElementRef, - resize$: Observable, -): Observable { - return resize$.pipe( - startWith(null), - debounceTime(0), // Synchronous scrollIntoView (after click) does not work https://stackoverflow.com/a/56971002 - map(() => { - const host = hostElement.nativeElement; - const exampleElements = Array.from(host.querySelectorAll('tui-doc-example')); - const codeElements = Array.from(host.querySelectorAll('tui-doc-code')); - - return ( - exampleElements.every((el) => el.querySelector('.t-example')) && - codeElements.every((el) => el.querySelector('.t-code')) - ); - }), - takeUntilDestroyed(), - ); -}