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

37 lines
945 B
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import * as types from "constants/action_types";
2017-06-06 06:21:55 +02:00
const reducers = {};
const defaultState = {};
reducers[types.FETCH_AVAILABILITY_STARTED] = function(state, action) {
2017-06-06 23:19:12 +02:00
const { uri } = action.data;
const newFetching = Object.assign({}, state.fetching);
2017-06-06 23:19:12 +02:00
newFetching[uri] = true;
return Object.assign({}, state, {
fetching: newFetching,
2017-06-06 23:19:12 +02:00
});
2017-06-06 06:21:55 +02:00
};
reducers[types.FETCH_AVAILABILITY_COMPLETED] = function(state, action) {
2017-06-06 23:19:12 +02:00
const { uri, availability } = action.data;
2017-05-15 05:50:59 +02:00
2017-06-06 23:19:12 +02:00
const newFetching = Object.assign({}, state.fetching);
const newAvailabilityByUri = Object.assign({}, state.byUri);
2017-06-06 23:19:12 +02:00
delete newFetching[uri];
newAvailabilityByUri[uri] = availability;
return Object.assign({}, state, {
fetching: newFetching,
2017-06-06 23:19:12 +02:00
byUri: newAvailabilityByUri,
});
2017-06-06 06:21:55 +02:00
};
export default function reducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);
return state;
}