tor-browser

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

sources-content.js (1428B)


      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 { asSettled } from "../utils/async-value";
      6 
      7 import {
      8  getSelectedLocation,
      9  getFirstSourceActorForGeneratedSource,
     10 } from "../selectors/sources";
     11 
     12 export function getSourceTextContentForLocation(state, location) {
     13  return getSourceTextContentForSource(
     14    state,
     15    location.source,
     16    location.sourceActor
     17  );
     18 }
     19 
     20 export function getSourceTextContentForSource(
     21  state,
     22  source,
     23  sourceActor = null
     24 ) {
     25  if (source.isOriginal) {
     26    return state.sourcesContent.mutableOriginalSourceTextContentMapBySourceId.get(
     27      source.id
     28    );
     29  }
     30 
     31  if (!sourceActor) {
     32    sourceActor = getFirstSourceActorForGeneratedSource(state, source.id);
     33  }
     34  return state.sourcesContent.mutableGeneratedSourceTextContentMapBySourceActorId.get(
     35    sourceActor.id
     36  );
     37 }
     38 
     39 export function getSettledSourceTextContent(state, location) {
     40  const content = getSourceTextContentForLocation(state, location);
     41  return asSettled(content);
     42 }
     43 
     44 export function getSelectedSourceTextContent(state) {
     45  const location = getSelectedLocation(state);
     46 
     47  if (!location) {
     48    return null;
     49  }
     50 
     51  return getSourceTextContentForLocation(state, location);
     52 }
     53 
     54 export function getSourcesEpoch(state) {
     55  return state.sourcesContent.epoch;
     56 }