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

37 lines
941 B
JavaScript
Raw Normal View History

import * as ACTIONS from 'constants/action_types';
2017-06-06 06:21:55 +02:00
const reducers = {};
const defaultState = {};
reducers[ACTIONS.FETCH_AVAILABILITY_STARTED] = (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[ACTIONS.FETCH_AVAILABILITY_COMPLETED] = (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;
}