Update the torrent reducer from switch to map

This commit is contained in:
Grégoire Delattre 2017-06-02 21:08:26 +02:00
parent 7014b3933d
commit 99fbe22d6d

View File

@ -1,20 +1,17 @@
import { Map, List, fromJS } from 'immutable' import { Map, List, fromJS } from "immutable"
const defaultState = Map({ const defaultState = Map({
'fetching': false, "fetching": false,
'torrents': List(), "torrents": List(),
}); });
export default function torrentStore(state = defaultState, action) { const handlers = {
switch (action.type) { "TORRENTS_FETCH_PENDING": state => state.set("fetching", false),
case 'TORRENTS_FETCH_PENDING': "TORRENTS_FETCH_FULFILLED": (state, action) => state.merge(fromJS({
return state.set('fetching', false);
case 'TORRENTS_FETCH_FULFILLED':
return state.merge(fromJS({
fetching: false, fetching: false,
torrents: action.payload.response.data, torrents: action.payload.response.data,
})); })),
default:
return state
}
} }
export default (state = defaultState, action) =>
handlers[action.type] ? handlers[action.type](state, action) : state;