forked from WebMemex/webmemex-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreducer.js
More file actions
47 lines (38 loc) · 1.29 KB
/
Copy pathreducer.js
File metadata and controls
47 lines (38 loc) · 1.29 KB
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
import { createReducer } from 'redux-act'
import * as actions from './actions'
const defaultState = {
searchResult: {rows: []},
query: '',
waitingForResults: 0,
startDate: undefined,
endDate: undefined,
}
function setQuery(state, {query}) {
return {...state, query}
}
function setStartDate(state, {startDate}) {
return {...state, startDate}
}
function setEndDate(state, {endDate}) {
return {...state, endDate}
}
function setSearchResult(state, {searchResult}) {
return {...state, searchResult}
}
function showLoadingIndicator(state) {
// We have to keep a counter, rather than a boolean, as it can currently
// happen that multiple subsequent searches are running simultaneously. The
// animation will thus hide again when all of them have completed.
return {...state, waitingForResults: state.waitingForResults + 1}
}
function hideLoadingIndicator(state) {
return {...state, waitingForResults: state.waitingForResults - 1}
}
export default createReducer({
[actions.setQuery]: setQuery,
[actions.setStartDate]: setStartDate,
[actions.setEndDate]: setEndDate,
[actions.setSearchResult]: setSearchResult,
[actions.showLoadingIndicator]: showLoadingIndicator,
[actions.hideLoadingIndicator]: hideLoadingIndicator,
}, defaultState)