Created
October 10, 2017 08:43
-
-
Save dakom/e68503e59c7a73c3bc926b7e8ae65a07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class extends React.Component { | |
private canRender: boolean = false; | |
private latestData: any; | |
constructor(props) { | |
super(props); | |
let nJobs = 0; | |
let lastRenderTime: number; | |
props.someObservableThing.listen(data => { | |
nJobs++; | |
this.latestData = data; | |
if (this.canRender) { | |
const now = performance.now(); | |
this.canRender = false; | |
this.setState({ | |
data: this.latestData, | |
jobsPerRender: nJobs, | |
fps: (lastRenderTime === undefined) ? 0 : 1000 / (now - lastRenderTime) | |
}); | |
nJobs = 0; | |
lastRenderTime = now; | |
} | |
}); | |
this.state = {}; | |
} | |
/* Lifecycle */ | |
componentDidMount() { | |
this.canRender = true; | |
} | |
componentDidUpdate() { | |
this.canRender = true; | |
} | |
render() { | |
outputStats(this.state); | |
return this.state.data === undefined ? null : <View {...this.state.data} /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment