-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-1.ts
47 lines (38 loc) · 948 Bytes
/
app-1.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
46
47
interface Action {
type: string;
payload?: any;
}
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;
default:
return state;
}
}
// Uso del "reducer".
const incrementadorAction: Action = {
type: 'INCREMENTAR'
};
console.log(reducer(10, incrementadorAction));
const decrementadorAction: Action = {
type: 'DECREMENTAR'
};
console.log(reducer(10, decrementadorAction));
const multiplicarAction: Action = {
type: 'MULTIPLICAR',
payload: 2
};
console.log(reducer(10, multiplicarAction));
// Tarea: Dividir.
const dividirAction: Action = {
type: 'DIVIDIR',
payload: 2
};
console.log(reducer(10, dividirAction));