### File

`src/lib/table-filter/table-filter.service.ts`

### Index

###### Properties
Public Readonly change Public current Public Readonly reset$
###### Methods
Public remove Public reset Public set Public setMap

### Constructor

`constructor()`
Defined in src/lib/table-filter/table-filter.service.ts:34

### Methods

Public remove
`remove(key: string)`
Defined in src/lib/table-filter/table-filter.service.ts:60
Parameters :
Name | Type | Optional
key | `string` | No
Returns : `void`

Public reset
`reset()`
Defined in src/lib/table-filter/table-filter.service.ts:40
Returns : `void`

Public set
`set(key: string, value: any)`
Defined in src/lib/table-filter/table-filter.service.ts:54
Parameters :
Name | Type | Optional
key | `string` | No
value | `any` | No
Returns : `void`

Public setMap
`setMap(map: Record)`
Defined in src/lib/table-filter/table-filter.service.ts:44
Parameters :
Name | Type | Optional
map | `Record<string | any>` | No
Returns : `void`

### Properties

Public Readonly change
Default value : `new ReplaySubject<Record<string, any>>(1)`
Defined in src/lib/table-filter/table-filter.service.ts:20

Public current
Type : `Record<string | any>`
Default value : `{}`
Defined in src/lib/table-filter/table-filter.service.ts:22

Public Readonly reset$
Default value : `new Subject<void>()`
Defined in src/lib/table-filter/table-filter.service.ts:26

    import {
      Injectable,
      OnDestroy,
    } from '@angular/core';
    import { FilterLike } from '@rxap/data-source/table';
    import {
      clone,
      DeleteEmptyProperties,
      equals,
    } from '@rxap/utilities';
    import {
      ReplaySubject,
      Subject,
      Subscription,
    } from 'rxjs';

    @Injectable()
    export class TableFilterService implements FilterLike, OnDestroy {

      public readonly change = new ReplaySubject<Record<string, any>>(1);

      public current: Record<string, any> = {};

      private _subscription: Subscription;

      public readonly reset$ = new Subject<void>();

      /**
       * a flag to indicate whether any value was already send to the change subject
       * true - a value was send
       * false - no value was send
       * @private
       */
      private _init = false;

      constructor() {
        this._subscription = this.change.subscribe(current => this.current = current);
      }

      public reset() {
        this.reset$.next();
      }

      public setMap(map: Record<string, any>): void {
        const current = this.current;
        const copy = clone(this.current);
        const next = DeleteEmptyProperties(Object.assign(current, map));
        if (!this._init || !equals(copy, next)) {
          this._init = true;
          this.change.next(next);
        }
      }

      public set(key: string, value: any): void {
        const current = this.current;
        current[key] = value;
        this.change.next(current);
      }

      public remove(key: string): void {
        const current = this.current;
        // eslint-disable-next-line no-prototype-builtins
        if (current.hasOwnProperty(key)) {
          delete current[key];
        }
        this.change.next(current);
      }

      public ngOnDestroy() {
        this._subscription.unsubscribe();
      }

    }

# results matching ""

# No results matching ""