speedscope/index.tsx

54 lines
1.3 KiB
TypeScript
Raw Normal View History

import {h, render, Component} from 'preact'
import {StyleSheet, css} from 'aphrodite'
import {importFromStackprof} from './stackprof'
2017-11-23 12:25:25 +03:00
import {Profile} from './profile'
import {Flamechart, FlamechartView} from './flamechart'
2017-11-23 06:19:10 +03:00
import { request } from 'https';
2017-11-23 12:25:25 +03:00
interface ApplicaionState {
profile: Profile | null
flamechart: Flamechart | null
2017-11-23 06:19:10 +03:00
}
2017-11-23 12:25:25 +03:00
class Application extends Component<{}, ApplicaionState> {
onDrop = (ev: DragEvent) => {
const reader = new FileReader
reader.addEventListener('loadend', () => {
2017-11-23 12:25:25 +03:00
const profile = importFromStackprof(reader.result)
const flamechart = new Flamechart(profile)
this.setState({profile, flamechart})
})
reader.readAsText(ev.dataTransfer.files.item(0))
ev.preventDefault()
}
onDragOver = (ev: DragEvent) => {
ev.preventDefault()
}
2017-11-28 10:43:37 +03:00
componentDidMount() {
window.addEventListener('resize', () => {
this.forceUpdate()
})
}
render() {
2017-11-23 12:25:25 +03:00
const {flamechart} = this.state
return <div onDrop={this.onDrop} onDragOver={this.onDragOver} className={css(style.root)}>
2017-11-28 10:43:37 +03:00
{flamechart &&
2017-12-08 07:14:06 +03:00
<FlamechartView flamechart={flamechart} />}
</div>
}
}
const style = StyleSheet.create({
root: {
width: '100vw',
2017-11-23 06:19:10 +03:00
height: '100vh',
overflow: 'hidden'
}
})
render(<Application />, document.body)