File

projects/i-components/src/lib/services/view-boxes-state.service.ts

Description

This service is used to store the state of the view boxes when are inside a data grid.

Index

Properties
Methods

Methods

clear
clear()

It clears the view boxes array and resets the view boxes completed counter

Returns : void
getObserver
getObserver()

It returns an observable that can be subscribed to

Returns : Observable<any>

An observable

getTotalViewBoxes
getTotalViewBoxes()

This function returns the number of view boxes in the view box array.

Returns : number

The number of view boxes in the view box array.

registerViewBox
registerViewBox(viewBox: any)

This function takes a ViewBoxComponent as an argument and pushes it into the _viewBoxes array.

Parameters :
Name Type Optional Description
viewBox any No

ViewBoxComponent - this is the viewBox that is being registered.

Returns : void
viewBoxReady
viewBoxReady()

When the viewBoxReady() function is called, the _viewBoxesCompleted variable is incremented by one

Returns : void

Properties

Private _viewBoxes
Type : any[]
Default value : []

keeps track of the view boxes completed

Private _viewBoxesCompleted
Type : number
Default value : 0

This is the number of view boxes that have been completed.

Private subject
Default value : new Subject<any>()

This is the subject that is used to notify the view boxes that they are ready.

import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';

/**
 * This service is used to store the state of the view boxes when are inside a data grid.
 *
 * @export
 * @class ViewBoxesStateService
 */
@Injectable()
export class ViewBoxesStateService {
  /**
   * keeps track of the view boxes completed
   *
   * @private
   * @type {any[]}
   * @memberof ViewBoxesStateService
   */
  private _viewBoxes: any[] = [];

  /**
   * This is the number of view boxes that have been completed.
   *
   * @private
   * @memberof ViewBoxesStateService
   */
  private _viewBoxesCompleted = 0;

  /**
   * This is the subject that is used to notify the view boxes that they are ready.
   *
   * @private
   * @memberof ViewBoxesStateService
   */
  private subject = new Subject<any>();

  /**
   * It returns an observable that can be subscribed to
   * @returns An observable
   * @memberof ViewBoxesStateService
   */
  getObserver(): Observable<any> {
    return this.subject.asObservable();
  }

  /**
   * This function returns the number of view boxes in the view box array.
   *
   * @returns The number of view boxes in the view box array.
   * @memberof ViewBoxesStateService
   */
  getTotalViewBoxes(): number {
    return this._viewBoxes.length;
  }

  /**
   * This function takes a ViewBoxComponent as an argument and pushes it into the _viewBoxes array.
   *
   * @param viewBox ViewBoxComponent - this is the viewBox that is being registered.
   * @memberof ViewBoxesStateService
   */
  registerViewBox(viewBox: any): void {
    this._viewBoxes.push(viewBox);
  }

  /**
   * When the viewBoxReady() function is called, the _viewBoxesCompleted variable is incremented by one
   *
   * @memberof ViewBoxesStateService
   */
  viewBoxReady(): void {
    this._viewBoxesCompleted++;
    if (this._viewBoxesCompleted === this._viewBoxes.length) {
      this.subject.next(this._viewBoxesCompleted);
    }
  }

  /**
   * It clears the view boxes array and resets the view boxes completed counter
   *
   * @memberof ViewBoxesStateService
   */
  clear(): void {
    this._viewBoxes = [];
    this._viewBoxesCompleted = 0;
  }
}

result-matching ""

    No results matching ""