lbry-desktop/ui/js/actions/availability.js
2017-06-05 21:21:55 -07:00

27 lines
627 B
JavaScript

import * as types from 'constants/action_types';
import lbry from 'lbry';
import { selectFetchingAvailability } from 'selectors/availability';
export function doFetchAvailability(uri) {
return function(dispatch, getState) {
const state = getState();
const alreadyFetching = !!selectFetchingAvailability(state)[uri];
if (!alreadyFetching) {
dispatch({
type: types.FETCH_AVAILABILITY_STARTED,
data: { uri }
});
lbry.get_availability({ uri }).then(availability => {
dispatch({
type: types.FETCH_AVAILABILITY_COMPLETED,
data: {
availability,
uri
}
});
});
}
};
}