lbry-desktop/ui/js/reducers/cost_info.js

35 lines
893 B
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import * as types from "constants/action_types";
2017-04-28 17:14:44 +02:00
2017-06-06 06:21:55 +02:00
const reducers = {};
const defaultState = {};
2017-04-28 17:14:44 +02:00
reducers[types.FETCH_COST_INFO_STARTED] = function(state, action) {
2017-06-06 23:19:12 +02:00
const { uri } = action.data;
const newFetching = Object.assign({}, state.fetching);
newFetching[uri] = true;
2017-04-28 17:14:44 +02:00
return Object.assign({}, state, {
fetching: newFetching,
2017-06-06 23:19:12 +02:00
});
2017-06-06 06:21:55 +02:00
};
2017-04-28 17:14:44 +02:00
reducers[types.FETCH_COST_INFO_COMPLETED] = function(state, action) {
2017-06-06 23:19:12 +02:00
const { uri, costInfo } = action.data;
const newByUri = Object.assign({}, state.byUri);
const newFetching = Object.assign({}, state.fetching);
2017-04-28 17:14:44 +02:00
2017-06-06 23:19:12 +02:00
newByUri[uri] = costInfo;
delete newFetching[uri];
2017-04-28 17:14:44 +02:00
return Object.assign({}, state, {
byUri: newByUri,
fetching: newFetching,
2017-06-06 23:19:12 +02:00
});
2017-06-06 06:21:55 +02:00
};
2017-04-28 17:14:44 +02:00
export default function reducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);
return state;
}