All files / src/app/store/computed computed-properties.ts

100% Statements 20/20
50% Branches 3/6
100% Functions 8/8
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 351x 1x             1x     2x     1x 1x     2x 1x 1x 1x     1x 1x     2x 1x 1x     1x  
import { Injectable } from '@angular/core';
import { NgRedux, select } from '@angular-redux/store';
import { Observable } from 'rxjs/Observable';
 
import { IAppState } from '../state/AppState';
import { IFileInfo } from '../../model/fileInfo.model';
 
@Injectable()
export class Computed {
 
  constructor(
    private ngRedux: NgRedux<IAppState>
  ) {}
 
  visibleFiles$(page): Observable<IFileInfo[]> {
    return this.ngRedux.select<IFileInfo[]>(this.visibleFiles(page));
  }
 
  private visibleFiles = (page) => (state) => {
    const files = state.pages[page].files || [];
    const numVisible = state.pages[page].numVisible || 0;
    return files.slice(0, numVisible);
  }
 
  fileCount$(page): Observable<number> {
    return this.ngRedux.select<number>(this.fileCount(page));
  }
 
  private fileCount = (page) => (state) => {
    const files = state.pages[page].files || [];
    return files.length;
  }
 
}