Просмотр исходного кода

Remove Authorized circular reference

陈帅 7 лет назад
Родитель
Сommit
494a4681dc

+ 4 - 5
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",

+ 1 - 1
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 (

+ 1 - 1
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 ? (
       <Component {...this.props} />
     ) : (

+ 2 - 23
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);

+ 24 - 0
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);