-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Format web workers dir (#288)
- Loading branch information
Showing
3 changed files
with
24 additions
and
22 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
const first = document.querySelector('#number1'); | ||
const second = document.querySelector('#number2'); | ||
const first = document.querySelector("#number1"); | ||
const second = document.querySelector("#number2"); | ||
|
||
const result = document.querySelector('.result'); | ||
const result = document.querySelector(".result"); | ||
|
||
if (window.Worker) { | ||
const myWorker = new Worker("worker.js"); | ||
|
||
[first, second].forEach(input => { | ||
input.onchange = function() { | ||
[first, second].forEach((input) => { | ||
input.onchange = () => { | ||
myWorker.postMessage([first.value, second.value]); | ||
console.log('Message posted to worker'); | ||
} | ||
}) | ||
console.log("Message posted to worker"); | ||
}; | ||
}); | ||
|
||
myWorker.onmessage = function(e) { | ||
myWorker.onmessage = (e) => { | ||
result.textContent = e.data; | ||
console.log('Message received from worker'); | ||
} | ||
console.log("Message received from worker"); | ||
}; | ||
} else { | ||
console.log('Your browser doesn\'t support web workers.'); | ||
console.log("Your browser doesn't support web workers."); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
onmessage = function(e) { | ||
console.log('Worker: Message received from main script'); | ||
onmessage = (e) => { | ||
console.log("Worker: Message received from main script"); | ||
|
||
const result = e.data[0] * e.data[1]; | ||
|
||
if (isNaN(result)) { | ||
postMessage('Please write two numbers'); | ||
postMessage("Please write two numbers"); | ||
} else { | ||
const workerResult = 'Result: ' + result; | ||
console.log('Worker: Posting message back to main script'); | ||
const workerResult = "Result: " + result; | ||
console.log("Worker: Posting message back to main script"); | ||
postMessage(workerResult); | ||
} | ||
} | ||
}; |