Skip to content

Commit

Permalink
fix(core): add complete subscriptions on destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
N1XUS committed Jul 22, 2022
1 parent 4588fe7 commit 3874f78
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
38 changes: 22 additions & 16 deletions libs/core/src/lib/overflow-layout/overflow-layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,28 @@ export class OverflowLayoutComponent implements AfterViewInit, OnDestroy, Overfl

/** @hidden */
ngAfterViewInit(): void {
this._overflowLayoutService.detectChanges.subscribe(() => {
this._cdr.detectChanges();
});

this._overflowLayoutService.onResult.subscribe((result) => {
this._hiddenItems = result.hiddenItems;
this._showMore = result.showMore;
this.hiddenItemsCount.emit(result.hiddenItems.length);
this.visibleItemsCount.emit(this._allItems.filter((i) => !i.hidden).length);
this._cdr.detectChanges();
});

this._items.changes.subscribe(() => {
this._allItems = this._items.toArray();
this._cdr.detectChanges();
});
this._subscription.add(
this._overflowLayoutService.detectChanges.subscribe(() => {
this._cdr.detectChanges();
})
);

this._subscription.add(
this._overflowLayoutService.onResult.subscribe((result) => {
this._hiddenItems = result.hiddenItems;
this._showMore = result.showMore;
this.hiddenItemsCount.emit(result.hiddenItems.length);
this.visibleItemsCount.emit(this._allItems.filter((i) => !i.hidden).length);
this._cdr.detectChanges();
})
);

this._subscription.add(
this._items.changes.subscribe(() => {
this._allItems = this._items.toArray();
this._cdr.detectChanges();
})
);

this._allItems = this._items.toArray();
this._cdr.detectChanges();
Expand Down
21 changes: 13 additions & 8 deletions libs/core/src/lib/overflow-layout/overflow-layout.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FocusKeyManager } from '@angular/cdk/a11y';
import { ElementRef, Injectable, Optional, QueryList } from '@angular/core';
import { ElementRef, Injectable, OnDestroy, Optional, QueryList } from '@angular/core';
import { resizeObservable, RtlService } from '@fundamental-ngx/core/utils';
import { debounceTime, distinctUntilChanged, filter, Observable, skip, Subject, Subscription } from 'rxjs';
import { OverflowLayoutItemContainerDirective } from './directives/overflow-layout-item-container.directive';
Expand All @@ -26,7 +26,7 @@ export class OverflowLayoutListeningResult {
}

@Injectable()
export class OverflowLayoutService {
export class OverflowLayoutService implements OnDestroy {
/**
* Overflow Layout config.
*/
Expand Down Expand Up @@ -81,6 +81,11 @@ export class OverflowLayoutService {
/** @hidden */
constructor(private _elRef: ElementRef<HTMLElement>, @Optional() private _rtlService: RtlService | null) {}

/** @hidden */
ngOnDestroy(): void {
this._subscription.unsubscribe();
}

startListening(config: OverflowLayoutConfig): void {
this.setConfig(config);
this.fitVisibleItems();
Expand Down Expand Up @@ -283,13 +288,13 @@ export class OverflowLayoutService {
return;
}

const rtlSub = this._rtlService.rtl.subscribe((isRtl) => {
this._dir = isRtl ? 'rtl' : 'ltr';

this._keyboardEventsManager = this._keyboardEventsManager.withHorizontalOrientation(this._dir);
});
this._subscription.add(
this._rtlService.rtl.subscribe((isRtl) => {
this._dir = isRtl ? 'rtl' : 'ltr';

this._subscription.add(rtlSub);
this._keyboardEventsManager = this._keyboardEventsManager.withHorizontalOrientation(this._dir);
})
);
}

/** @hidden */
Expand Down

0 comments on commit 3874f78

Please sign in to comment.