Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cdk): share a single subscription to the underlying source observable between multiple subscribers #3174

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions projects/cdk/services/resize.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
distinctUntilChanged,
map,
mapTo,
share,
takeUntil,
throttleTime,
} from 'rxjs/operators';
Expand All @@ -34,6 +35,10 @@ export class TuiResizeService extends ResizeObserverService {

return this.pipe(
catchError(() =>
splincode marked this conversation as resolved.
Show resolved Hide resolved
/**
* @note: if not supported ResizeObserver
* remove `catchError` after supports modern browsers
*/
animationFrame$.pipe(
throttleTime(POLLING_TIME),
map(
Expand All @@ -46,6 +51,7 @@ export class TuiResizeService extends ResizeObserverService {
),
debounceTime(0),
tuiZonefree(ngZone),
share(),
takeUntil(destroy$),
);
}
Expand Down
4 changes: 2 additions & 2 deletions projects/demo/src/modules/app/abstract.app.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {Directive, ElementRef, HostBinding, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {TUI_DOC_PAGE_LOADED} from '@taiga-ui/addon-doc';
import {tuiPure, TuiResizeService} from '@taiga-ui/cdk';
import {TuiDestroyService, tuiPure, TuiResizeService} from '@taiga-ui/cdk';
import {Observable} from 'rxjs';

import {readyToScrollFactory} from './utils/ready-to-scroll-factory';
import {TuiVersionMeta} from './version-manager/versions.constants';

export const DEMO_PAGE_LOADED_PROVIDER = {
provide: TUI_DOC_PAGE_LOADED,
deps: [ElementRef, TuiResizeService],
deps: [ElementRef, TuiResizeService, TuiDestroyService],
useFactory: readyToScrollFactory,
};

Expand Down
2 changes: 1 addition & 1 deletion projects/demo/src/modules/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {TuiVersionMeta} from './version-manager/versions.constants';
templateUrl: `./app.template.html`,
styleUrls: [`./app.style.less`],
providers: [
TuiDestroyService,
TuiResizeService,
TuiDestroyService,
DEMO_PAGE_LOADED_PROVIDER,
TUI_VERSION_MANAGER_PROVIDERS,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {ElementRef} from '@angular/core';
import {Observable} from 'rxjs';
import {debounceTime, map, startWith} from 'rxjs/operators';
import {debounceTime, map, startWith, takeUntil} from 'rxjs/operators';

export function readyToScrollFactory(
hostElement: ElementRef<HTMLElement>,
resize$: Observable<unknown>,
destroy$: Observable<unknown>,
): Observable<boolean> {
return resize$.pipe(
startWith(null),
Expand All @@ -19,5 +20,6 @@ export function readyToScrollFactory(
codeElements.every(el => el.querySelector(`.t-code`))
);
}),
takeUntil(destroy$),
);
}