All files / src/components/PerformanceProfiler index.jsx

0% Statements 0/58
0% Branches 0/37
0% Functions 0/16
0% Lines 0/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                                                                               
import styles from './style.postcss';
 
import React from 'react';
import ReactPerf from 'react-addons-perf';
import Button from 'components/Button';
import Icon from 'components/Icon';
 
class PerformanceProfiler extends React.Component {
  constructor(props) {
    super(props);
    this.state = { started: false };
  }
 
  toggle() {
    const { started } = this.state;
    started ? ReactPerf.stop() : ReactPerf.start();
    this.setState({ started: ! started });
  }
 
  printWasted() {
    const lastMeasurements = ReactPerf.getLastMeasurements();
    ReactPerf.printWasted(lastMeasurements);
  }
 
  printOperations() {
    const lastMeasurements = ReactPerf.getLastMeasurements();
    ReactPerf.printOperations(lastMeasurements);
  }
 
  render() {
    const { started } = this.state;
    return <div className={styles.PerformanceProfiler}>
      <Button className={styles.PerformanceProfiler_button}
          onClick={() => this.toggle()}
          type={Button.Type.primary}>
        <Icon className={styles.PerformanceProfiler_button_icon}
            id={started ? 'cross' : 'magnifying-glass'} />
      </Button>
      <Button className={styles.PerformanceProfiler_button}
          onClick={() => this.printWasted()}
          type={Button.Type.default}>
        <Icon className={styles.PerformanceProfiler_button_icon}
            id="clock" />
      </Button>
      <Button className={styles.PerformanceProfiler_button}
          onClick={() => this.printOperations()}
          type={Button.Type.default}>
        <Icon className={styles.PerformanceProfiler_button_icon}
            id="organisation" />
      </Button>
    </div>;
  }
}
 
export default PerformanceProfiler;