-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathlocal-state-advanced.effects.ts
More file actions
35 lines (31 loc) · 1.07 KB
/
local-state-advanced.effects.ts
File metadata and controls
35 lines (31 loc) · 1.07 KB
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
import { Injectable } from '@angular/core';
import { Effect, ofType } from '@ngrx/effects';
import { Observable } from 'rxjs';
import { debounceTime, delay, map } from 'rxjs/operators';
import {
GetManufacturersAction,
ManufacturersActionsTypes,
SetManufacturersAction
} from './local-state-advanced.reducer';
@Injectable()
export class LocalStateAdvancedEffects {
@Effect()
getManufacturers$: Observable<ManufacturersActionsTypes> = this.actions$.pipe(
debounceTime(300),
delay(1000),
ofType(GetManufacturersAction.type),
map((action: ManufacturersActionsTypes) => {
if (action.type === GetManufacturersAction.type) {
if (action.countryCode === 'US') {
return SetManufacturersAction(['Ford', 'Chevrolet']);
} else if (action.countryCode === 'UK') {
return SetManufacturersAction(['Aston Martin', 'Jaguar']);
} else {
return SetManufacturersAction([]);
}
}
return SetManufacturersAction([]);
})
);
constructor(private actions$: Observable<ManufacturersActionsTypes>) { }
}