Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. import React, { PureComponent, PropTypes } from 'react'
  2. import Perf from 'react-addons-perf'
  3.  
  4. class PerfProfiler extends PureComponent {
  5.  
  6. state = {
  7. isStarted: false,
  8. isMinimized: this.props.minimized,
  9. }
  10.  
  11. toggle = () => {
  12. const { isStarted } = this.state
  13.  
  14. this.setState({
  15. isStarted: !isStarted,
  16. }, () => {
  17. if (isStarted) { Perf.stop() }
  18. else { Perf.start() }
  19. })
  20. }
  21.  
  22. toggleContent = () => {
  23. const { isMinimized } = this.state
  24. this.setState({
  25. isMinimized: !isMinimized,
  26. })
  27. }
  28.  
  29. printWasted = () => {
  30. const lastMeasurement = Perf.getLastMeasurements()
  31. return Perf.printWasted(lastMeasurement)
  32. }
  33.  
  34. printOperations = () => {
  35. const lastMeasurement = Perf.getLastMeasurements()
  36. return Perf.printOperations(lastMeasurement)
  37. }
  38.  
  39. printExclusive = () => {
  40. const lastMeasurement = Perf.getLastMeasurements()
  41. return Perf.printExclusive(lastMeasurement)
  42. }
  43.  
  44. printInclusive = () => {
  45. const lastMeasurement = Perf.getLastMeasurements()
  46. return Perf.printInclusive(lastMeasurement)
  47. }
  48.  
  49. render() {
  50. const { position, className } = this.props
  51. const { isMinimized } = this.state
  52. return (
  53. <div className={`perf-profiler ${position} ${className}`}>
  54. <div className="min-button-container">
  55. <button onClick={this.toggleContent}>_</button>
  56. </div>
  57. <div className={`buttons-container ${isMinimized ? 'hidden' :
  58. ''}`}>
  59. <button className="toggle-button" onClick={this.toggle}>
  60. {this.state.isStarted ? 'Stop' : 'Start'}
  61. </button>
  62. <button onClick={this.printWasted}>Print Wasted</button>
  63. <button onClick={this.printOperations}>Print Operations</button>
  64. <button onClick={this.printInclusive}>Print Inclusive</button>
  65. <button onClick={this.printExclusive}>Print Exclusive</button>
  66. </div>
  67. </div>)}
  68. }
  69. export default PerfProfiler
  70.  
  71. .perf-profiler {
  72.  
  73. display: flex;
  74. flex-direction: column;
  75. position: absolute;
  76. border: 1px solid;
  77. padding: 20px;
  78. background-color: rgba(#ffffff, 0.8);
  79. z-index: 10;
  80.  
  81. &.top-left {
  82. left: 0;
  83. top: 0;
  84. }
  85.  
  86. &.top-right {
  87. right: 0;
  88. top: 0;
  89. }
  90.  
  91. &.bottom-left {
  92. bottom: 0;
  93. left: 0;
  94. }
  95.  
  96. &.bottom-right {
  97. bottom: 0;
  98. right: 0;
  99. }
  100.  
  101. &.center {
  102. top: 50%;
  103. left: 50%;
  104. }
  105.  
  106. .toggle-button {
  107. margin-left: 0.5em;
  108. }
  109.  
  110. .min-button-container {
  111. display: flex;
  112.  
  113. flex: 1;
  114. justify-content: flex-end;
  115. }
  116.  
  117. .buttons-container {
  118. display: flex;
  119. flex-direction: column;
  120. }
  121.  
  122. .hidden {
  123. display: none;
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement