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

43 lines
948 B
JavaScript
Raw Normal View History

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