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

@Injectable({
  providedIn: 'root'
})
export class LoadingService {

  loadingVisibility: Subject<boolean> = new Subject;
  requestors: number = 0;

  constructor() { }

  enableLoading(){
    this.requestors = this.requestors + 1;
    this.loadingVisibility.next(true);
  }

  disableLoading(){
    this.requestors = this.requestors - 1;
    if (this.requestors < 1){
      this.loadingVisibility.next(false);
      this.requestors = 0;
    }
  }

}
