Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SimpleTableMediator<F, O>

A simple implementation of MatTableMediator that takes the fetch function as an constructor argument. Any calls to the fetch method of this class, will be forwarded to the specified function from the constructor.

Type parameters

  • F

    type of the trigger payload to be used in the underlying fetch function, for example a form output

  • O

    type of the output data for the table. This must match MatTable's generic type

Hierarchy

Implements

  • OnDestroy

Index

Constructors

constructor

Properties

Protected _data$

_data$: Subject<O[]> = new Subject<Array<O>>()

The data from the MediatorData object. It only contains the received entities and will be fed into the table.

Protected _destroy$

_destroy$: Subject<void> = new Subject<void>()

A subject for cleanups. Will be called and completed by the ngOnDestroy method.

see

ngOnDestroy

Protected _error$

_error$: Subject<Error> = new Subject<Error>()

The subject that receives any error from the fetching process.

see

[[handleError

Protected _loading$

_loading$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false)

The BehaviorSubject indicating the loading status.

Protected _mediatorData$

_mediatorData$: Observable<MediatorData<O>>

The raw MediatorData observable, resulting from the createDataFetch method.

see

createDataFetch

see

_data$

Protected _totalResults$

_totalResults$: Subject<number> = new Subject<number>()

The total result count, taken from the MediatorData object.

Protected config

config: MediatorConfig<O>

A frozen MediatorConfig, put together in the constructor. By default the MatTableMediator.DEFAULT_CONFIG values will be used.

see

MatTableMediator.DEFAULT_CONFIG

Protected fetchFn

fetchFn: FetchFunction<F, O>

onPageReset$

onPageReset$: Observable<[EventEmitter<Sort>, F] | any>

An observable that emits, whenever the page is reset. To change the behaviour overwrite the createOnPageReset method.

see

createOnPageReset

Protected Optional paginator

paginator: MatPaginator

Reference to the MatPaginator

Protected Optional sort

sort: MatSort

Reference to the MatSort

Protected table

table: MatTable<O>

Reference to the MatTable

Protected trigger$

trigger$: TriggerPayload<F>

Accessors

data$

  • get data$(): Observable<Array<O>>
  • An observable of the data, which gets fed into the table. The mediator takes care of feeding the table. You can use this property for additional actions.

    Returns Observable<Array<O>>

error$

  • get error$(): Observable<Error>

isLoading$

  • get isLoading$(): Observable<boolean>
  • An observable which indicates loading. by default loading starts when the fetch function gets triggered and ends when data was received and just before the table and paginator gets fed.

    Returns Observable<boolean>

onFetchBegin$

  • get onFetchBegin$(): Observable<void>

onNoResultsFound$

  • get onNoResultsFound$(): Observable<void>

onResultsFound$

  • get onResultsFound$(): Observable<number>

Protected page$

  • get page$(): EventEmitter<PageEvent | undefined>
  • safely returns this.paginator.page.pipe(startWith({})) or of(undefined), if MatPaginator object wasn't provided

    Returns EventEmitter<PageEvent | undefined>

Protected pageIndex

  • get pageIndex(): number | undefined

Protected pageSize

  • get pageSize(): number | undefined

Protected sortActive

  • get sortActive(): Column<O> | undefined

Protected sortChange$

  • get sortChange$(): EventEmitter<Sort>

Protected sortDirection

  • get sortDirection(): SortDirection | undefined

totalResults$

  • get totalResults$(): Observable<number>
  • An observable which emits the total count of results that are available on the server. The mediator takes care of feeding the paginator. You can use this property for additional actions.

    Returns Observable<number>

Methods

Protected createDataFetch

Protected createOnPageReset

  • createOnPageReset(): Observable<[EventEmitter<Sort>, F]> | Observable<any>

fetch

  • fetch(payload?: F, sortBy?: Column<O>, sortDirection?: SortDirection, pageIndex?: number, pageSize?: number): Observable<MediatorData<O>>

Protected handleError

  • This function handles any errors that occur while fetching the data. You can either safely handle the error and return replacement data or rethrow the error. Throwing an error will complete the observable and would have to be started again by calling #initDataFetch

    Parameters

    • error: Error

      The thrown error

    Returns Observable<MediatorData<O>>

    The replacement data as an observable (e.g. return of({ total: -1, data: [] });)

Protected handlePageReset

  • handlePageReset(value: [EventEmitter<Sort>, F] | any): void

Protected handleResult

  • This function gets called every time new data was fetched. It's responsible for feeding the data into the table and paginator. It also controls the subjects for the properties like data$, resultsLength$ and isLoading$

    Parameters

    • result: MediatorData<O>

      the result of the fetchFn, already mapped to MediatorData

    Returns void

ngOnDestroy

  • ngOnDestroy(): void

start

  • start(): void
  • This function initialises the page reset and the fetch function, effectively starting the mediator. It won't be called automatically. You may want to call it at the end of your subclass' constructor.

    this.onPageReset$ = this.createOnPageReset();
    this.onPageReset$.subscribe(value => this.handlePageReset(value));
    // within this method any errors will be forwarded to `handleError`
    this._mediatorData$ = this.createDataFetch();
    this._mediatorData$.subscribe(result => this.handleResult(result));

    Returns void

Object literals

Static DEFAULT_CONFIG

DEFAULT_CONFIG: object

The default config for mediators.

{
  trackByFn: index => index, // track by index
  attempts: 0,               // do not retry
  debounceLoading: 150       // debounce loading indicator by 150ms
}
see

MediatorConfig

attempts

attempts: number = 0

debounceLoading

debounceLoading: number = 150

trackByFn

  • trackByFn(index: number): number

Generated using TypeDoc