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

perf: use requestAnimationFrame

Shuai Chen 6 лет назад
Родитель
Сommit
e1290d8e16

+ 10 - 12
src/components/ActiveChart/index.js

@@ -33,18 +33,16 @@ export default class ActiveChart extends Component {
   }
 
   loopData = () => {
-    this.requestRef = requestAnimationFrame(() => {
-      this.timer = setTimeout(() => {
-        this.setState(
-          {
-            activeData: getActiveData(),
-          },
-          () => {
-            this.loopData();
-          }
-        );
-      }, 1000);
-    });
+    this.timer = setTimeout(() => {
+      this.setState(
+        {
+          activeData: getActiveData(),
+        },
+        () => {
+          this.loopData();
+        }
+      );
+    }, 500);
   };
 
   render() {

+ 4 - 2
src/components/Charts/AsyncLoadBizCharts.js

@@ -24,8 +24,10 @@ class AsyncLoadBizCharts extends React.Component {
 
   async componentDidMount() {
     await loadBizCharts();
-    this.setState({
-      loading: false,
+    requestAnimationFrame(() => {
+      this.setState({
+        loading: false,
+      });
     });
   }
 

+ 2 - 2
src/components/Charts/index.js

@@ -1,11 +1,12 @@
 import React, { Suspense } from 'react';
 import numeral from 'numeral';
 import ChartCard from './ChartCard';
+import Field from './Field';
 
 const getComponent = Component => {
   return props => {
     return (
-      <Suspense fallback={null}>
+      <Suspense fallback="...">
         <Component {...props} />
       </Suspense>
     );
@@ -19,7 +20,6 @@ const Gauge = getComponent(React.lazy(() => import('./Gauge')));
 const MiniArea = getComponent(React.lazy(() => import('./MiniArea')));
 const MiniBar = getComponent(React.lazy(() => import('./MiniBar')));
 const MiniProgress = getComponent(React.lazy(() => import('./MiniProgress')));
-const Field = getComponent(React.lazy(() => import('./Field')));
 const WaterWave = getComponent(React.lazy(() => import('./WaterWave')));
 const TagCloud = getComponent(React.lazy(() => import('./TagCloud')));
 const TimelineChart = getComponent(React.lazy(() => import('./TimelineChart')));

+ 0 - 1
src/pages/Dashboard/Analysis.js

@@ -25,7 +25,6 @@ class Analysis extends Component {
   };
 
   componentDidMount() {
-    console.log('run');
     const { dispatch } = this.props;
     this.reqRef = requestAnimationFrame(() => {
       dispatch({