import { Injectable } from '@angular/core' ; import { Actions , Effect , toPayload } from '@ngrx/effects' ; import 'rxjs/add/operator/switchMap' ; import { CompanyService } from '../company/company.service' ; import * as companyActions from './../actions/company.actions' ; import { DeleteCompanySuccessAction } from '../actions/company.actions' ; @ Injectable ( ) export class CompanyEffects { constructor ( private actions$ , private companyService ) { } @ Effect ( ) loadCompanies$ = this . actions$ . ofType ( companyActions . LOAD_COMPANIES ) . switchMap ( ( ) => { return this . companyService . loadCompanies ( ) . map ( companies => new companyActions . LoadCompaniesSuccessAction ( companies ) ) ; } ) ; @ Effect ( ) deleteCompany$ = this . actions$ . ofType ( companyActions . DELETE_COMPANY ) . switchMap ( ( action ) => { return this . companyService . deleteCompany ( action . payload ) . map ( company => new companyActions . DeleteCompanySuccessAction ( company . id ) ) ; } ) ; } ;