Merge pull request #153 from 6ea86b96/double-fetch-cost

Don't try to fetch cost info if it's already fetching
This commit is contained in:
Jeremy Kauffman 2017-05-28 11:28:14 -04:00 committed by GitHub
commit 6bccb67585
3 changed files with 22 additions and 2 deletions

View file

@ -7,14 +7,17 @@ import {
} from 'actions/cost_info'
import {
makeSelectCostInfoForUri,
makeSelectFetchingCostInfoForUri,
} from 'selectors/cost_info'
import FilePrice from './view'
const makeSelect = () => {
const selectCostInfoForUri = makeSelectCostInfoForUri()
const selectFetchingCostInfoForUri = makeSelectFetchingCostInfoForUri()
const select = (state, props) => ({
costInfo: selectCostInfoForUri(state, props),
fetching: selectFetchingCostInfoForUri(state, props),
})
return select

View file

@ -16,10 +16,11 @@ class FilePrice extends React.Component{
const {
costInfo,
fetchCostInfo,
uri
uri,
fetching,
} = props
if (costInfo === undefined) {
if (costInfo === undefined && !fetching) {
fetchCostInfo(uri)
}
}

View file

@ -17,3 +17,19 @@ export const makeSelectCostInfoForUri = () => {
(costInfo) => costInfo
)
}
export const selectFetchingCostInfo = createSelector(
_selectState,
(state) => state.fetching || {}
)
const selectFetchingCostInfoForUri = (state, props) => {
return selectFetchingCostInfo(state)[props.uri]
}
export const makeSelectFetchingCostInfoForUri = () => {
return createSelector(
selectFetchingCostInfoForUri,
(fetching) => !!fetching
)
}