-
Notifications
You must be signed in to change notification settings - Fork 0
/
redux(insurance).js
65 lines (61 loc) · 1.52 KB
/
redux(insurance).js
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
console.clear();
const CreatePolicy = (name, amount) => {
return {
type: "CREATE_POLICY",
payload: {
name: name,
amount: amount
}
};
};
const CreateClaim = (name, amountclaimed) => {
return {
type: "CREATE_CLAIM",
payload: {
name: name,
amountclaimed: amountclaimed
}
};
};
const DeletePolicy = name => {
return {
type: "DELETE_POLICY",
payload: {
name: name
}
};
};
const ClaimHistory = (OldClaimList = [], action) => {
if (action.type === "CREATE_CLAIM") {
return [...OldClaimList, action.payload];
}
return OldClaimList;
};
const accounting = (money = 100, action) => {
if (action.type === "CREATE_CLAIM") {
return money - action.payload.amountclaimed;
} else if (action.type === "CREATE_POLICY") {
return money + action.payload.amount;
}
return money;
};
const policy = (listofpolicy = [], action) => {
if (action.type === "CREATE_POLICY") {
return [...listofpolicy, action.payload.name];
} else if (action.type === "DELETE_POLICY") {
return listofpolicy.filter(name => name !== action.payload.name);
}
return listofpolicy;
};
const { createStore, combineReducers } = Redux;
const ourdept = combineReducers({
accounting: accounting,
ClaimHistory: ClaimHistory,
policy: policy
});
const store = createStore(ourdept);
store.dispatch(CreatePolicy("anuj", 1000));
store.dispatch(CreatePolicy("prakash", 1000));
store.dispatch(DeletePolicy("anuj"));
store.dispatch(CreateClaim("prakash", 100));
console.log(store.getState());