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

33 lines
877 B
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import { createSelector } from "reselect";
2017-06-06 06:21:55 +02:00
const _selectState = state => state.availability;
export const selectAvailabilityByUri = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.byUri || {}
2017-06-06 06:21:55 +02:00
);
const selectAvailabilityForUri = (state, props) => {
2017-06-06 23:19:12 +02:00
return selectAvailabilityByUri(state)[props.uri];
2017-06-06 06:21:55 +02:00
};
2017-05-15 05:50:59 +02:00
export const makeSelectIsAvailableForUri = () => {
return createSelector(
selectAvailabilityForUri,
2017-06-06 23:19:12 +02:00
availability => (availability === undefined ? undefined : availability > 0)
);
2017-06-06 06:21:55 +02:00
};
2017-05-15 05:50:59 +02:00
export const selectFetchingAvailability = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.fetching || {}
2017-06-06 06:21:55 +02:00
);
2017-05-15 05:50:59 +02:00
const selectFetchingAvailabilityForUri = (state, props) => {
2017-06-06 23:19:12 +02:00
return selectFetchingAvailability(state)[props.uri];
2017-06-06 06:21:55 +02:00
};
export const makeSelectFetchingAvailabilityForUri = () => {
2017-06-06 23:19:12 +02:00
return createSelector(selectFetchingAvailabilityForUri, fetching => fetching);
2017-06-06 06:21:55 +02:00
};