mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 14:57:18 +10:00
24 lines
664 B
JavaScript
24 lines
664 B
JavaScript
const url = require('url');
|
|
const { matchPathname, configureStore } = require('./importer');
|
|
|
|
exports.loadData = function(requestUrl, sdk) {
|
|
const { pathname, query } = url.parse(requestUrl);
|
|
const matchedRoutes = matchPathname(pathname);
|
|
|
|
const store = configureStore(sdk);
|
|
|
|
const dataLoadingCalls = matchedRoutes.reduce(
|
|
(calls, match) => {
|
|
const { route, params } = match;
|
|
if (typeof route.loadData === 'function' && !route.auth) {
|
|
calls.push(store.dispatch(route.loadData(params, query)));
|
|
}
|
|
return calls;
|
|
},
|
|
[]
|
|
);
|
|
|
|
return Promise.all(dataLoadingCalls).then(() => {
|
|
return store.getState();
|
|
});
|
|
};
|