From b425de859f0cf0ad74c18ef7c6977f91a1d9590a Mon Sep 17 00:00:00 2001 From: KJlmfe Date: Sun, 29 Jul 2018 11:58:56 +0800 Subject: [PATCH] refactor: reduce code duplication of routerDataCache --- src/common/router.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/router.js b/src/common/router.js index 25379fb9..eeef241b 100644 --- a/src/common/router.js +++ b/src/common/router.js @@ -6,6 +6,13 @@ import { getMenuData } from './menu'; let routerDataCache; +const getRouterDataCache = app => { + if (!routerDataCache) { + routerDataCache = getRouterData(app); + } + return routerDataCache; +}; + const modelNotExisted = (app, model) => // eslint-disable-next-line !app._models.some(({ namespace }) => { @@ -26,27 +33,21 @@ const dynamicWrapper = (app, models, component) => { // transformed by babel-plugin-dynamic-import-node-sync if (component.toString().indexOf('.then(') < 0) { return props => { - if (!routerDataCache) { - routerDataCache = getRouterData(app); - } return createElement(component().default, { ...props, - routerData: routerDataCache, + routerData: getRouterDataCache(app), }); }; } // () => import('module') return Loadable({ loader: () => { - if (!routerDataCache) { - routerDataCache = getRouterData(app); - } return component().then(raw => { const Component = raw.default || raw; return props => createElement(Component, { ...props, - routerData: routerDataCache, + routerData: getRouterDataCache(app), }); }); }, -- GitLab