import { Injectable, Inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Store, select } from '@ngrx/store'; import * as fromTabReducer from '../reducer/tabs.reducer'; import { Observable } from 'rxjs'; import { AddMultipleTabAction, AddTabAction, CloseTabAction, ResetTabAction, SetActiveTabAction } from '../action/tabs.action'; import { TabEntity } from '../models/tab-entity'; @Injectable() export class TabService { activeTabs: Observable; activeTabIndex: Observable; activeTab: Observable; constructor(private http: HttpClient, private store: Store) { this.activeTabs = store.pipe(select(fromTabReducer.getAllList)); this.activeTabIndex = store.pipe(select(fromTabReducer.getSelectedEntityId)); this.activeTab = store.pipe(select(fromTabReducer.getSelectedEntity)); } dispatchAddTab( payload: TabEntity ): void { this.store.dispatch( new AddTabAction( payload ) ); } dispatchAddMultipleTabs( payload: TabEntity[] ): void { this.store.dispatch( new AddMultipleTabAction( payload ) ); } dispatchCloseTab( payload: string ): void { this.store.dispatch( new CloseTabAction( payload ) ); } dispatchSetActiveTab( payload: TabEntity ): void { this.store.dispatch( new SetActiveTabAction( payload ) ); } dispatchResetTab(): void { this.store.dispatch( new ResetTabAction( ) ); } }