File

libs/video-stat-dashboard/src/services/dashboard.service.ts

Index

Properties
Methods

Constructor

constructor(store: Store)
Parameters :
Name Type Optional
store Store<VideoStatsState> no

Methods

setCurrentVideo
setCurrentVideo(id: string)
Parameters :
Name Type Optional
id string no
Returns : void

Properties

currentVideo
currentVideo: Observable<Video>
Type : Observable<Video>
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { filter } from 'rxjs/operators';
import { combineLatest } from 'rxjs/observable/combineLatest'

import { VideoStatsState } from '../+state/video-stats.interfaces';
import { Video } from '../+state/video-stats.interfaces';

@Injectable()
export class DashboardService {

  currentVideo: Observable<Video>;

  constructor(private store: Store<VideoStatsState>) {
    this.currentVideo = combineLatest(
      this.store.select(appState => appState.videoStats.currentVideo),
      this.store.select(appState => appState.videoStats.videoList)
        .pipe(filter(x => !!x)),
      (id: string, list: Video[]) => list.find(video => video.id === id));
  }

  setCurrentVideo(id: string) {
    this.store.dispatch({
      type: 'VIDEO_SELECTED',
      payload: id
    });
  }
}

results matching ""

    No results matching ""