tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

removeSources.js (1337B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 import { getEditor } from "../../utils/editor/index";
      6 
      7 export function removeSources(
      8  sources,
      9  actors,
     10  { resetSelectedLocation = true } = {}
     11 ) {
     12  return async ({ parserWorker, dispatch, sourceMapLoader }) => {
     13    // Remove the sources from the reducers first, and most importantly before any async work
     14    // as we may otherwise remove the source at an unexpected time.
     15    dispatch({
     16      type: "REMOVE_SOURCES",
     17      sources,
     18      actors,
     19      resetSelectedLocation,
     20    });
     21 
     22    const sourceIds = sources.map(source => source.id);
     23 
     24    // Clear the ParserWorker
     25    parserWorker.clearSources(sourceIds);
     26 
     27    // Clear the shared editor module from related CodeMirror instances
     28    const editor = getEditor();
     29    editor.clearSources(sourceIds);
     30 
     31    // Clear the Source Map Loader/Worker from any potential bundle data
     32    const generatedSourceIds = new Set();
     33    for (const source of sources) {
     34      if (source.isOriginal) {
     35        generatedSourceIds.add(source.generatedSource.id);
     36      }
     37    }
     38    await sourceMapLoader.clearSourceMapForGeneratedSources(
     39      Array.from(generatedSourceIds)
     40    );
     41  };
     42 }