docs_app/src/app/search/search-worker.js
function handleMessage(message) {
  var type = message.data.type;
  var id = message.data.id;
  var payload = message.data.payload;
  switch(type) {
    case 'load-index':
      makeRequest(SEARCH_TERMS_URL, function(searchInfo) {
        index = createIndex(loadIndex(searchInfo));
        self.postMessage({type: type, id: id, payload: true});
      });
      break;
    case 'query-index':
      self.postMessage({type: type, id: id, payload: {query: payload, results: queryIndex(payload)}});
      break;
    default:
      self.postMessage({type: type, id: id, payload: {error: 'invalid message type'}})
  }
}
function handleMessage(message) {
  var type = message.data.type;
  var id = message.data.id;
  var payload = message.data.payload;
  switch(type) {
    case 'load-index':
      makeRequest(SEARCH_TERMS_URL, function(searchInfo) {
        index = createIndex(loadIndex(searchInfo));
        self.postMessage({type: type, id: id, payload: true});
      });
      break;
    case 'query-index':
      self.postMessage({type: type, id: id, payload: {query: payload, results: queryIndex(payload)}});
      break;
    default:
      self.postMessage({type: type, id: id, payload: {error: 'invalid message type'}})
  }
}
function handleMessage ( message ) { var type = message . data . type ; var id = message . data . id ; var payload = message . data . payload ; switch ( type ) { case 'load-index' : makeRequest ( SEARCH_TERMS_URL , function ( searchInfo ) { index = createIndex ( loadIndex ( searchInfo ) ) ; self . postMessage ( { type : type , id : id , payload : true } ) ; } ) ; break ; case 'query-index' : self . postMessage ( { type : type , id : id , payload : { query : payload , results : queryIndex ( payload ) } } ) ; break ; default : self . postMessage ( { type : type , id : id , payload : { error : 'invalid message type' } } ) } }
The worker receives a message to load the index and to query the index
The worker receives a message to load the index and to query the index