forked from veteransaffairscanada/vac-benefits-directory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.js
101 lines (95 loc) · 2.7 KB
/
store.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import lunr from "lunr";
import { createStore } from "redux";
const initialState = {
areaOffices: [],
benefits: [],
eligibilityPaths: [],
enIdx: {},
examples: [],
favouriteBenefits: [],
frIdx: {},
needs: [],
patronType: "",
searchString: "",
selectedNeeds: {},
serviceType: "",
statusAndVitals: "",
translations: [],
option: ""
};
// REDUCERS
export const reducer = (state = initialState, action) => {
let benefits;
let enIdx;
let frIdx;
switch (action.type) {
case "INDEX_BENEFITS":
benefits = state.benefits;
enIdx = lunr(function() {
this.pipeline.remove(lunr.stemmer);
this.pipeline.remove(lunr.stopWordFilter);
this.ref("id");
this.field("vacNameEn");
this.field("oneLineDescriptionEn");
benefits.forEach(function(doc) {
this.add(doc);
}, this);
});
frIdx = lunr(function() {
this.pipeline.remove(lunr.stemmer);
this.pipeline.remove(lunr.stopWordFilter);
this.ref("id");
this.field("vacNameFr");
this.field("oneLineDescriptionFr");
benefits.forEach(function(doc) {
this.add(doc);
}, this);
});
return Object.assign({}, state, {
enIdx: JSON.stringify(enIdx),
frIdx: JSON.stringify(frIdx)
});
case "LOAD_DATA":
return Object.assign({}, state, {
storeHydrated: action.data.storeHydrated || state.storeHydrated,
benefits: action.data.benefits || state.benefits,
eligibilityPaths:
action.data.eligibilityPaths || state.eligibilityPaths,
needs: action.data.needs || state.needs,
examples: action.data.examples || state.examples,
favouriteBenefits:
action.data.favouriteBenefits || state.favouriteBenefits,
translations: action.data.translations || state.translations,
areaOffices: action.data.areaOffices || state.areaOffices
});
case "SET_PATRON_TYPE":
return Object.assign({}, state, {
patronType: action.data
});
case "SET_SEARCH_STRING":
return Object.assign({}, state, {
searchString: action.data
});
case "SET_SELECTED_NEEDS":
return Object.assign({}, state, {
selectedNeeds: action.data
});
case "SET_SERVICE_TYPE":
return Object.assign({}, state, {
serviceType: action.data
});
case "SET_STATUS_TYPE":
return Object.assign({}, state, {
statusAndVitals: action.data
});
case "SET_OPTION":
return Object.assign({}, state, {
option: action.data
});
default:
return state;
}
};
export const initStore = (state = initialState) => {
return createStore(reducer, state);
};