All files / src/app/services/file-service file.actions.ts

91.3% Statements 21/23
100% Branches 0/0
75% Functions 6/8
90.48% Lines 19/21
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 681x   1x           1x   1x 1x 1x 1x             12x     1x 3x                 1x 3x     1x 1x                     1x 1x     1x                   1x     1x  
import { Injectable} from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { NgRedux, select } from '@angular-redux/store';
 
import { IAppState } from '../../store/state/AppState';
import { IFileInfo } from '../../model/fileInfo.model';
 
@Injectable()
export class FileActions {
 
  static SET_FILELIST_PENDING = 'SET_FILELIST_PENDING';
  static SET_FILELIST_SUCCESS = 'SET_FILELIST_SUCCESS';
  static SET_FILELIST_FAILED = 'SET_FILELIST_FAILED';
  static ACTIONS = [
    FileActions.SET_FILELIST_PENDING,
    FileActions.SET_FILELIST_SUCCESS,
    FileActions.SET_FILELIST_FAILED
  ];
 
  constructor(
    protected ngRedux: NgRedux<IAppState>,
  ) {}
 
  createSetFileListPending(value) {
    return {
      type: FileActions.SET_FILELIST_PENDING,
      payload: {
        fileList: {
          pending: value
        }
      }
    };
  }
  setFileListPending(value) {
    this.ngRedux.dispatch( this.createSetFileListPending(value) );
  }
 
  createSetFileListSuccess(files: string[]) {
    return {
      type: FileActions.SET_FILELIST_SUCCESS,
      payload: {
        fileList: {
          files,
          pending: false,
          error: null
        }
      }
    };
  }
  setFileListSuccess(files: string[]) {
    this.ngRedux.dispatch( this.createSetFileListSuccess(files) );
  }
 
  createSetFileListFailed(error: Error) {
    return {
      type: FileActions.SET_FILELIST_SUCCESS,
      payload: {
        fileList: {
          error
        }
      }
    };
  }
  setFileListFailed(error: Error) {
    this.ngRedux.dispatch( this.createSetFileListFailed(error) );
  }
}