Using web workers to display out the number of words count, character count keyed in text area. However, I am unable to call a specific string Getting Started as it matches the case type. Should I be using two web workers?
This is my index.js page.
btn.addEventListener("click", function(){
worker.postMessage("Getting Started");
})
text.addEventListener("keyup", ()=> {
worker.postMessage(text.value);
});
Below is my webworker.js file
self.onmessage = function(event) {
switch(event){
case event.data === 'Getting Started':
postMessage("web worker started");
break;
case typeof event.data === "string":
postMessage(analyze(event.data));
break;
default:
postMessage("closing");
close();
}
}
//The analyze function
function analyze(str) {
const mostRepeatedWordInfo = findMostRepeatedWord(str);
return {
wordCount: countWords(str)
charCount: countChars(str)
};
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/uSv3GPU
Comments
Post a Comment