Don't try to fetch cost info if it's already fetching #153
3 changed files with 22 additions and 2 deletions
|
@ -7,14 +7,17 @@ import {
|
||||||
} from 'actions/cost_info'
|
} from 'actions/cost_info'
|
||||||
import {
|
import {
|
||||||
makeSelectCostInfoForUri,
|
makeSelectCostInfoForUri,
|
||||||
|
makeSelectFetchingCostInfoForUri,
|
||||||
} from 'selectors/cost_info'
|
} from 'selectors/cost_info'
|
||||||
import FilePrice from './view'
|
import FilePrice from './view'
|
||||||
|
|
||||||
const makeSelect = () => {
|
const makeSelect = () => {
|
||||||
const selectCostInfoForUri = makeSelectCostInfoForUri()
|
const selectCostInfoForUri = makeSelectCostInfoForUri()
|
||||||
|
const selectFetchingCostInfoForUri = makeSelectFetchingCostInfoForUri()
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
costInfo: selectCostInfoForUri(state, props),
|
costInfo: selectCostInfoForUri(state, props),
|
||||||
|
fetching: selectFetchingCostInfoForUri(state, props),
|
||||||
})
|
})
|
||||||
|
|
||||||
return select
|
return select
|
||||||
|
|
|
@ -16,10 +16,11 @@ class FilePrice extends React.Component{
|
||||||
const {
|
const {
|
||||||
costInfo,
|
costInfo,
|
||||||
fetchCostInfo,
|
fetchCostInfo,
|
||||||
uri
|
uri,
|
||||||
|
fetching,
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
if (costInfo === undefined) {
|
if (costInfo === undefined && !fetching) {
|
||||||
fetchCostInfo(uri)
|
fetchCostInfo(uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,3 +17,19 @@ export const makeSelectCostInfoForUri = () => {
|
||||||
(costInfo) => costInfo
|
(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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue