Last active
May 28, 2019 15:47
-
-
Save leofab86/c4c6bd52bb99addd21e78a62144b6f4b to your computer and use it in GitHub Desktop.
Fuzzy search automcomplete v1.2.4
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
//ww1.js | |
self.importScripts('...the search engine script, provides the SearchEngine constructor'); | |
let searchEngine; | |
let port; | |
function initiate (data, port) { | |
searchEngine = new SearchEngine(data); | |
port = port; | |
port.onmessage = search; | |
} | |
/* search is attached to the port as the message handler so it | |
runs when communicating with the workerArray only */ | |
function search (e) { | |
const {searchTerm} = e.data; | |
const message = { | |
searchResults: searchEngine.search(searchTerm) | |
}; | |
port.postMessage(message) | |
} | |
/* self.onmessage is the handler that responds to messages from | |
the main thread, which only fires during initiation */ | |
self.onmessage = function(e) { | |
const {data} = e.data; | |
initiate(data, e.ports[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment