import { Injectable } from '@angular/core';
import { UpdateService } from './update.service';
import { BaseButtonService } from './base-button.service';

@Injectable({
  providedIn: 'root'
})
export class RefreshService extends BaseButtonService {

  constructor(private updateService: UpdateService) { 
    super()
  }

  private actions: Array<() => void> = [];

  add(action: () => void): void {
    this.actions.push(action);
  }

  removeAll(): void {
    this.actions = [];
  }

  executeAll(): void {
    this.actions.forEach(action => action());
    this.updateService.removeAll()
  }
}
