Skip to content

Commit

Permalink
fix(cdk): share a single subscription to the underlying source observ…
Browse files Browse the repository at this point in the history
…able between multiple subscribers (#3174)
  • Loading branch information
splincode committed Dec 20, 2022
1 parent 4cf7f0b commit 29f7454
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
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(() =>
/**
* @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$),
);
}

0 comments on commit 29f7454

Please sign in to comment.