Skip to content

Commit

Permalink
chore(demo): add tuiZonefreeScheduler for DEMO_PAGE_LOADED_PROVIDER
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Aug 29, 2024
1 parent 610ce10 commit 63703c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
27 changes: 24 additions & 3 deletions projects/demo/src/modules/app/abstract.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement>,
resize$: Observable<unknown>,
): Observable<boolean> {
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({
Expand Down
25 changes: 0 additions & 25 deletions projects/demo/src/modules/app/utils/ready-to-scroll-factory.ts

This file was deleted.

0 comments on commit 63703c0

Please sign in to comment.