Skip to content

Instantly share code, notes, and snippets.

@alfredayibonte
Last active August 22, 2018 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredayibonte/2c2e275814f83ea859bb140c7eeb20eb to your computer and use it in GitHub Desktop.
Save alfredayibonte/2c2e275814f83ea859bb140c7eeb20eb to your computer and use it in GitHub Desktop.
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