1 | import axios from "axios";
|
2 | import * as R from "ramda";
|
3 |
|
4 | function fetchLocalization({ locale, url }) {
|
5 | return axios
|
6 | .get(url)
|
7 | .then(R.prop("data"))
|
8 | .then(R.assoc(locale, R.__, {}));
|
9 | }
|
10 |
|
11 | export function loadLocalizations(localizations, dispatch) {
|
12 | const localizationsPromises = R.compose(
|
13 | R.map(fetchLocalization),
|
14 | R.values,
|
15 | R.mapObjIndexed((url, locale) => ({ locale, url }))
|
16 | )(localizations);
|
17 |
|
18 | const baseAction = { type: "LOAD_LOCALIZATIONS" };
|
19 |
|
20 | return Promise.all(localizationsPromises)
|
21 | .then(R.reduce(R.merge, {}))
|
22 | .then(R.assoc("payload", R.__, baseAction))
|
23 | .then(dispatch);
|
24 | }
|