Skip to content

Commit

Permalink
[Simple web worker] Code refactor - iterate over inputs (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukortech authored Jul 19, 2023
1 parent 5c0da23 commit f3e0dbb
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions web-workers/simple-web-worker/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ const result = document.querySelector('.result');
if (window.Worker) {
const myWorker = new Worker("worker.js");

first.onchange = function() {
myWorker.postMessage([first.value, second.value]);
console.log('Message posted to worker');
}

second.onchange = function() {
myWorker.postMessage([first.value, second.value]);
console.log('Message posted to worker');
}
[first, second].forEach(input => {
input.onchange = function() {
myWorker.postMessage([first.value, second.value]);
console.log('Message posted to worker');
}
})

myWorker.onmessage = function(e) {
result.textContent = e.data;
Expand Down

0 comments on commit f3e0dbb

Please sign in to comment.