From 494a4681dcb9672f6d8175d9bb2e014388dff89a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Mon, 25 Jun 2018 08:41:43 +0800 Subject: [PATCH] Remove Authorized circular reference --- package.json | 9 +++---- src/components/Authorized/CheckPermissions.js | 2 +- src/components/Authorized/PromiseRender.js | 2 +- src/components/Authorized/index.js | 25 ++----------------- src/components/Authorized/renderAuthorize.js | 24 ++++++++++++++++++ 5 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 src/components/Authorized/renderAuthorize.js diff --git a/package.json b/package.json index 7c8395da..ab41cfbd 100755 --- a/package.json +++ b/package.json @@ -23,9 +23,7 @@ "dependencies": { "@antv/data-set": "^0.8.0", "@babel/polyfill": "^7.0.0-beta.36", - "antd": "^3.4.3", - "babel-plugin-transform-decorators-legacy": "^1.3.4", - "babel-runtime": "^6.9.2", + "antd": "3.6.4", "bizcharts": "^3.1.10", "bizcharts-plugin-slider": "^2.0.1", "classnames": "^2.2.5", @@ -53,11 +51,12 @@ "babel-eslint": "^8.1.2", "babel-plugin-dva-hmr": "^0.4.1", "babel-plugin-import": "^1.6.7", + "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-module-resolver": "^3.1.1", "cross-env": "^5.1.1", "cross-port-killer": "^1.0.1", "enzyme": "^3.1.0", - "eslint": "^4.14.0", + "eslint": "^5.0.0", "eslint-config-airbnb": "^17.0.0", "eslint-config-prettier": "^2.9.0", "eslint-plugin-babel": "^5.1.0", @@ -73,7 +72,7 @@ "prettier": "1.13.5", "pro-download": "^1.0.1", "redbox-react": "^1.5.0", - "regenerator-runtime": "^0.11.1", + "regenerator-runtime": "^0.12.0", "roadhog": "^2.4.2", "roadhog-api-doc": "^1.0.3", "stylelint": "^9.2.1", diff --git a/src/components/Authorized/CheckPermissions.js b/src/components/Authorized/CheckPermissions.js index 06dc0ab9..a79e2859 100644 --- a/src/components/Authorized/CheckPermissions.js +++ b/src/components/Authorized/CheckPermissions.js @@ -1,6 +1,6 @@ import React from 'react'; import PromiseRender from './PromiseRender'; -import { CURRENT } from './index'; +import { CURRENT } from './renderAuthorize'; function isPromise(obj) { return ( diff --git a/src/components/Authorized/PromiseRender.js b/src/components/Authorized/PromiseRender.js index b18bcbec..292d3b1a 100644 --- a/src/components/Authorized/PromiseRender.js +++ b/src/components/Authorized/PromiseRender.js @@ -44,7 +44,7 @@ export default class PromiseRender extends React.PureComponent { }; render() { - const Component = this.state.component; + const { component: Component } = this.state; return Component ? ( ) : ( diff --git a/src/components/Authorized/index.js b/src/components/Authorized/index.js index 48d1b2b8..91eabf87 100644 --- a/src/components/Authorized/index.js +++ b/src/components/Authorized/index.js @@ -2,31 +2,10 @@ import Authorized from './Authorized'; import AuthorizedRoute from './AuthorizedRoute'; import Secured from './Secured'; import check from './CheckPermissions.js'; - -/* eslint-disable import/no-mutable-exports */ -let CURRENT = 'NULL'; +import renderAuthorize from './renderAuthorize'; Authorized.Secured = Secured; Authorized.AuthorizedRoute = AuthorizedRoute; Authorized.check = check; -/** - * use authority or getAuthority - * @param {string|()=>String} currentAuthority - */ -const renderAuthorize = currentAuthority => { - if (currentAuthority) { - if (currentAuthority.constructor.name === 'Function') { - CURRENT = currentAuthority(); - } - if (currentAuthority.constructor.name === 'String') { - CURRENT = currentAuthority; - } - } else { - CURRENT = 'NULL'; - } - return Authorized; -}; - -export { CURRENT }; -export default renderAuthorize; +export default renderAuthorize(Authorized); diff --git a/src/components/Authorized/renderAuthorize.js b/src/components/Authorized/renderAuthorize.js new file mode 100644 index 00000000..8e34c694 --- /dev/null +++ b/src/components/Authorized/renderAuthorize.js @@ -0,0 +1,24 @@ +/* eslint-disable import/no-mutable-exports */ +let CURRENT = 'NULL'; +/** + * use authority or getAuthority + * @param {string|()=>String} currentAuthority + */ +const renderAuthorize = Authorized => { + return currentAuthority => { + if (currentAuthority) { + if (currentAuthority.constructor.name === 'Function') { + CURRENT = currentAuthority(); + } + if (currentAuthority.constructor.name === 'String') { + CURRENT = currentAuthority; + } + } else { + CURRENT = 'NULL'; + } + return Authorized; + }; +}; + +export { CURRENT }; +export default Authorized => renderAuthorize(Authorized); -- GitLab