Last active
March 28, 2017 19:27
-
-
Save luqmaan/13c106009bd0bd61d3f411e31c6e0c9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function* getMissingRates(orderNumbers, labelType) { | |
const ratesDeltaByOrderNumber = {}; | |
const orderNumbersMissingRates = yield select(orderNumbersMissingRatesSelector, {orderNumbers, labelType}); | |
if (!orderNumbersMissingRates.length) { | |
return; | |
} | |
yield put(startUpdatingRates(orderNumbersMissingRates, labelType)); | |
const ratesDeltaList = yield orderNumbersMissingRates.map( | |
(orderNumber) => call(fetchRates, orderNumber, labelType), | |
); | |
ratesDeltaList.forEach((ratesDelta, i) => { | |
const orderNumber = orderNumbersMissingRates[i]; | |
ratesDeltaByOrderNumber[orderNumber] = ratesDelta; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function* getMissingRates(orderNumbers, labelType) { | |
const ratesDeltaByOrderNumber = {}; | |
const orderNumbersMissingRates = yield select(orderNumbersMissingRatesSelector, {orderNumbers, labelType}); | |
if (!orderNumbersMissingRates.length) { | |
return; | |
} | |
yield put(startUpdatingRates(orderNumbersMissingRates, labelType)); | |
try { | |
for (let i = 0; i < orderNumbersMissingRates.length; i++) { | |
const orderNumber = orderNumbersMissingRates[i]; | |
const ratesDelta = yield call(fetchRates, orderNumber, labelType); | |
ratesDeltaByOrderNumber[orderNumber] = ratesDelta; | |
} | |
} | |
finally { | |
// Commit the finished rates, even if the generator was cancelled. | |
// This way we don't have to refresh rates we've already loaded | |
yield put(updateRatesByOrderNumber(labelType, ratesDeltaByOrderNumber)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment