forked from Klerith/redux-basico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-1.ts
71 lines (44 loc) · 1.08 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Acciones
interface Action {
type: string;
payload?: any;
}
// const incrementadorAction: Action = {
// type: 'INCREMENTAR'
// };
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;
}
}
// Usar el reducer
const incrementadorAction: Action = {
type: 'INCREMENTAR'
};
console.log( reducer(10, incrementadorAction ) ); // 11
const decrementadorAction: Action = {
type: 'DECREMENTAR'
};
console.log( reducer(10, decrementadorAction ) ); // 9
const multiplicarAction: Action = {
type: 'MULTIPLICAR',
payload: 2
};
console.log( reducer(10, multiplicarAction ) ); // 20
// Tarea
// dividirAction
// payload
const dividirAction: Action = {
type: 'DIVIDIR',
payload: 2
};
console.log( reducer(10, dividirAction ) ); // 5