-
Notifications
You must be signed in to change notification settings - Fork 6
/
app-2.ts
45 lines (27 loc) · 955 Bytes
/
app-2.ts
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
import { Action } from './ngrx-fake/ngrx';
import { incrementadorAction,
decrementadorAction,
multiplicarAction,
dividirAction,
resetAction } from './contador/contador.actions';
function reducer( state = 10, action: Action ) {
switch ( action.type ) {
case 'INCREMENTAR':
return state += 1;
case 'DECREMENTAR':
return state -= 1;
case 'MULTIPLICAR':
return state * action.payload;
case 'DIVIDIR':
return state / action.payload;
case 'RESET':
return state = 0;
default:
return state;
}
}
console.log( reducer( 10, incrementadorAction ) ); // 11
console.log( reducer( 10, decrementadorAction ) ); // 9
console.log( reducer( 10, multiplicarAction ) ); // 20
console.log( reducer( 10, dividirAction ) ); // 5
console.log( reducer( 10, resetAction ) ); // 0