forked from WebMemex/webmemex-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreducer.js
35 lines (28 loc) · 1 KB
/
reducer.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
import { createReducer } from 'redux-act'
import * as actions from './actions'
const defaultState = {
searchResult: {rows: []},
query: '',
waitingForResults: 0,
}
function setQuery(state, {query}) {
return {...state, query}
}
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.setSearchResult]: setSearchResult,
[actions.showLoadingIndicator]: showLoadingIndicator,
[actions.hideLoadingIndicator]: hideLoadingIndicator,
}, defaultState)