So if the event dot data, that is the name of the operation, I call operation. But I can name with, I don't know, I'm very bad, I'm sorry. But I don't know, jsnation event name, OK. So just I put here and this is going to be the name of our event, OK. So if the name of our event equals event.data equals operation, I just call the handler operation and I post the value here. So when I return, I'm going to post the message with the the value, OK. So note that I remove the processing have function for worker.js. So I don't have the handler operation function here.
And now we need to instantiate the worker API with new worker here, OK. So I'm going to instantiate the web worker, OK. So I'm going to call pass as parameter, the name of our file. And here, I have some before, I'm going to get the date now. And here, I'm going to call the operation name here of our event, OK. The same name, OK. And here, I'm going to call the all message function. And here, I'm calling after with the date now. And here, I'm going to create the when we receive the message here, the post message here. I'm going to just print the time, OK. And I'm going to create, put on the pre-tag, the text content with the value, OK. The event.date. So here, this is the timestamp, OK.
And the event listener to change the background color, don't change, OK. So I just changed the event listener to click, OK. And when I click, so I just call the operation name of our event. And after we finish the work, we will, it's going to receive the message, OK, with the value. So let's see the example here. I start, I click, so it's, I click on the start large operation. And when I click on the start large operation, I can click on the change background color. And after the process is finished, the value will be printed here, OK. And with the web workers and start having process, the UI is not blocked due to the main thread, OK.
Comments