()
| 41 | } |
| 42 | |
| 43 | componentDidMount() { |
| 44 | this.setState({ |
| 45 | id: Math.random().toString().slice(2) |
| 46 | }) |
| 47 | |
| 48 | window.addEventListener('message', (e) => { |
| 49 | let data |
| 50 | try { |
| 51 | data = JSON.parse(e.data) |
| 52 | } catch (err) { |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | const {id, type, payload} = data |
| 57 | |
| 58 | if (id !== this.state.id) { |
| 59 | return |
| 60 | } |
| 61 | |
| 62 | switch (type) { |
| 63 | case 'ready': |
| 64 | this.status = 'ready' |
| 65 | if (this.fileMap) { |
| 66 | this.runApplication(this.fileMap, this.entry) |
| 67 | this.fileMap = null |
| 68 | this.entry = null |
| 69 | } |
| 70 | break |
| 71 | case 'error': |
| 72 | this.props.onError(payload) |
| 73 | break |
| 74 | case 'console': |
| 75 | this.props.onConsole(payload) |
| 76 | break |
| 77 | } |
| 78 | }) |
| 79 | } |
| 80 | |
| 81 | runApplication(fileMap, entry) { |
| 82 | this.props.onRun() |
nothing calls this directly
no test coverage detected