mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4745] memory leak fixes (#4931)
* fix app-layout component * fix card-view component * fix cloud-layout service * code fixes * code fixes * even more fixes * even more fixes * lint fixes * test fixes * fix code * remove useless pipes * fix code owners * enable spellcheck for cloud components * update test * update test
This commit is contained in:
committed by
Eugenio Romano
parent
e2311ab045
commit
1abb9bfc89
@@ -24,12 +24,13 @@ import {
|
||||
} from '@angular/core';
|
||||
|
||||
import { PaginatedComponent } from './paginated-component.interface';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { Subject } from 'rxjs';
|
||||
import { PaginationComponentInterface } from './pagination-component.interface';
|
||||
import { PaginationModel } from '../models/pagination.model';
|
||||
import { RequestPaginationModel } from '../models/request-pagination.model';
|
||||
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
|
||||
import { Pagination } from '@alfresco/js-api';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-infinite-pagination',
|
||||
@@ -48,22 +49,25 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
|
||||
});
|
||||
|
||||
_target: PaginatedComponent;
|
||||
private onDestroy$ = new Subject<boolean>();
|
||||
|
||||
/** Component that provides custom pagination support. */
|
||||
@Input()
|
||||
set target(target: PaginatedComponent) {
|
||||
if (target) {
|
||||
this._target = target;
|
||||
this.paginationSubscription = target.pagination.subscribe((pagination: PaginationModel) => {
|
||||
this.isLoading = false;
|
||||
this.pagination = pagination;
|
||||
target.pagination
|
||||
.pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe(pagination => {
|
||||
this.isLoading = false;
|
||||
this.pagination = pagination;
|
||||
|
||||
if (!this.pagination.hasMoreItems) {
|
||||
this.pagination.hasMoreItems = false;
|
||||
}
|
||||
if (!this.pagination.hasMoreItems) {
|
||||
this.pagination.hasMoreItems = false;
|
||||
}
|
||||
|
||||
this.cdr.detectChanges();
|
||||
});
|
||||
this.cdr.detectChanges();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,17 +94,18 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
|
||||
merge: true
|
||||
};
|
||||
|
||||
private paginationSubscription: Subscription;
|
||||
|
||||
constructor(private cdr: ChangeDetectorRef,
|
||||
private userPreferencesService: UserPreferencesService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.userPreferencesService.select(UserPreferenceValues.PaginationSize).subscribe((pageSize: number) => {
|
||||
this.pageSize = this.pageSize || pageSize;
|
||||
this.requestPaginationModel.maxItems = this.pageSize;
|
||||
});
|
||||
this.userPreferencesService
|
||||
.select(UserPreferenceValues.PaginationSize)
|
||||
.pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe((pageSize: number) => {
|
||||
this.pageSize = this.pageSize || pageSize;
|
||||
this.requestPaginationModel.maxItems = this.pageSize;
|
||||
});
|
||||
}
|
||||
|
||||
onLoadMore() {
|
||||
@@ -127,8 +132,7 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.paginationSubscription) {
|
||||
this.paginationSubscription.unsubscribe();
|
||||
}
|
||||
this.onDestroy$.next(true);
|
||||
this.onDestroy$.complete();
|
||||
}
|
||||
}
|
||||
|
@@ -23,9 +23,10 @@ import {
|
||||
import { Pagination } from '@alfresco/js-api';
|
||||
import { PaginatedComponent } from './paginated-component.interface';
|
||||
import { PaginationComponentInterface } from './pagination-component.interface';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { Subject } from 'rxjs';
|
||||
import { PaginationModel } from '../models/pagination.model';
|
||||
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-pagination',
|
||||
@@ -82,29 +83,32 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
|
||||
@Output()
|
||||
prevPage: EventEmitter<PaginationModel> = new EventEmitter<PaginationModel>();
|
||||
|
||||
private paginationSubscription: Subscription;
|
||||
private onDestroy$ = new Subject<boolean>();
|
||||
|
||||
constructor(private cdr: ChangeDetectorRef, private userPreferencesService: UserPreferencesService) {
|
||||
this.userPreferencesService.select(UserPreferenceValues.PaginationSize).subscribe((pagSize) => {
|
||||
this.pagination.maxItems = pagSize;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.userPreferencesService
|
||||
.select(UserPreferenceValues.PaginationSize)
|
||||
.pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe(pagSize => this.pagination.maxItems = pagSize);
|
||||
|
||||
if (!this.supportedPageSizes) {
|
||||
this.supportedPageSizes = this.userPreferencesService.supportedPageSizes;
|
||||
}
|
||||
|
||||
if (this.target) {
|
||||
this.paginationSubscription = this.target.pagination.subscribe((pagination: PaginationModel) => {
|
||||
this.target.pagination
|
||||
.pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe(pagination => {
|
||||
if (pagination.count === 0 && !this.isFirstPage) {
|
||||
this.goPrevious();
|
||||
}
|
||||
|
||||
if (pagination.count === 0 && !this.isFirstPage) {
|
||||
this.goPrevious();
|
||||
}
|
||||
|
||||
this.pagination = pagination;
|
||||
this.cdr.detectChanges();
|
||||
});
|
||||
this.pagination = pagination;
|
||||
this.cdr.detectChanges();
|
||||
});
|
||||
}
|
||||
|
||||
if (!this.pagination) {
|
||||
@@ -217,6 +221,11 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.onDestroy$.next(true);
|
||||
this.onDestroy$.complete();
|
||||
}
|
||||
|
||||
handlePaginationEvent(action: string, params: PaginationModel) {
|
||||
const {
|
||||
NEXT_PAGE,
|
||||
@@ -258,10 +267,4 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
|
||||
this.target.updatePagination(params);
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.paginationSubscription) {
|
||||
this.paginationSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user