Commit b425de85 authored by KJlmfe's avatar KJlmfe Committed by 偏右

refactor: reduce code duplication of routerDataCache

parent c9186043
...@@ -6,6 +6,13 @@ import { getMenuData } from './menu'; ...@@ -6,6 +6,13 @@ import { getMenuData } from './menu';
let routerDataCache; let routerDataCache;
const getRouterDataCache = app => {
if (!routerDataCache) {
routerDataCache = getRouterData(app);
}
return routerDataCache;
};
const modelNotExisted = (app, model) => const modelNotExisted = (app, model) =>
// eslint-disable-next-line // eslint-disable-next-line
!app._models.some(({ namespace }) => { !app._models.some(({ namespace }) => {
...@@ -26,27 +33,21 @@ const dynamicWrapper = (app, models, component) => { ...@@ -26,27 +33,21 @@ const dynamicWrapper = (app, models, component) => {
// transformed by babel-plugin-dynamic-import-node-sync // transformed by babel-plugin-dynamic-import-node-sync
if (component.toString().indexOf('.then(') < 0) { if (component.toString().indexOf('.then(') < 0) {
return props => { return props => {
if (!routerDataCache) {
routerDataCache = getRouterData(app);
}
return createElement(component().default, { return createElement(component().default, {
...props, ...props,
routerData: routerDataCache, routerData: getRouterDataCache(app),
}); });
}; };
} }
// () => import('module') // () => import('module')
return Loadable({ return Loadable({
loader: () => { loader: () => {
if (!routerDataCache) {
routerDataCache = getRouterData(app);
}
return component().then(raw => { return component().then(raw => {
const Component = raw.default || raw; const Component = raw.default || raw;
return props => return props =>
createElement(Component, { createElement(Component, {
...props, ...props,
routerData: routerDataCache, routerData: getRouterDataCache(app),
}); });
}); });
}, },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment