try fix change detection

This commit is contained in:
Dan Percic 2022-03-29 12:25:48 +03:00
parent aab7e8c0b1
commit 320c3d3f4a
3 changed files with 9 additions and 17 deletions

View File

@ -1,6 +1,6 @@
import { Directive, Injector, OnDestroy, TemplateRef, ViewChild } from '@angular/core';
import { combineLatest, Observable } from 'rxjs';
import { map, switchMapTo } from 'rxjs/operators';
import { map, switchMap } from 'rxjs/operators';
import { FilterService } from '../filtering';
import { SortingService } from '../sorting';
import { AutoUnsubscribe, shareDistinctLast } from '../utils';
@ -40,7 +40,10 @@ export abstract class ListingComponent<T extends IListable> extends AutoUnsubscr
private get _sortedDisplayedEntities$(): Observable<T[]> {
const sort = (entities: T[]) => this.sortingService.defaultSort(entities);
const sortedEntities$ = this.listingService.displayed$.pipe(map(sort));
return this.sortingService.sortingOption$.pipe(switchMapTo(sortedEntities$), shareDistinctLast());
return this.sortingService.sortingOption$.pipe(
switchMap(() => sortedEntities$),
shareDistinctLast(),
);
}
private get _noMatch$(): Observable<boolean> {

View File

@ -3,11 +3,11 @@
[class.no-data]="listingComponent.noContent$ | async"
[itemSize]="itemSize"
[maxBufferPx]="1500"
[minBufferPx]="300"
iqserHasScrollbar
[minBufferPx]="1000"
id="virtual-scroll"
iqserHasScrollbar
>
<ng-container *cdkVirtualFor="let entity of listingComponent.sortedDisplayedEntities$; trackBy: trackBy; templateCacheSize: 60">
<ng-container *cdkVirtualFor="let entity of listingComponent.sortedDisplayedEntities$ | async; trackBy: trackBy">
<!-- mouseenter and mouseleave triggers change detection event if itemMouse functions are undefined -->
<!-- this little hack below ensures that change detection won't be triggered if functions are undefined -->
<div

View File

@ -1,14 +1,4 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
forwardRef,
HostListener,
Inject,
Input,
OnDestroy,
ViewChild,
} from '@angular/core';
import { AfterViewInit, Component, forwardRef, HostListener, Inject, Input, OnDestroy, ViewChild } from '@angular/core';
import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling';
import { delay, tap } from 'rxjs/operators';
import { AutoUnsubscribe, trackByFactory } from '../../utils';
@ -22,7 +12,6 @@ import { HelpModeService } from '@iqser/common-ui';
selector: 'iqser-table-content',
templateUrl: './table-content.component.html',
styleUrls: ['./table-content.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TableContentComponent<T extends IListable> extends AutoUnsubscribe implements OnDestroy, AfterViewInit {
@Input() itemSize!: number;