Last active
August 22, 2018 23:32
-
-
Save alfredayibonte/2c2e275814f83ea859bb140c7eeb20eb 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
import React, { Component } from 'react'; | |
const requestUrls = [ | |
'https://jsonplaceholder.typicode.com/posts', | |
'https://jsonplaceholder.typicode.com/users', | |
'https://jsonplaceholder.typicode.com/todos', | |
'https://jsonplaceholder.typicode.com/comments', | |
'https://jsonplaceholder.typicode.com/albums', | |
'https://jsonplaceholder.typicode.com/photos' | |
] | |
export default class MyComponent extends Component { | |
constructor(props) { | |
super(props) | |
this.worker = new Worker('worker.js') | |
} | |
onMessageReceive = (message) => { | |
// get object by message.data and store in db | |
console.log('facility component receiving message::', message) | |
if(message.data.status === 'done') { | |
console.log('status', message.data.status) | |
this.stopWorker(); | |
} | |
} | |
stopWorker = () => { | |
this.worker.terminate(); | |
this.worker = undefined; | |
} | |
componentDidMount() { | |
if(this.worker != undefined) { | |
this.worker.postMessage({ requestUrls }) | |
this.worker.onmessage = this.onMessageReceive | |
} | |
else { | |
this.worker = new Worker('worker.js') | |
} | |
} | |
render() { | |
return ( | |
<div> | |
<h1>My Components</h1> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment