Home / File/ tags.js — react Source File

tags.js — react Source File

Architecture documentation for tags.js, a javascript file in the react codebase. 0 imports, 1 dependents.

File javascript BabelCompiler Optimization 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  7d63591d_64d7_3647_f176_d8bc764bfb02["tags.js"]
  c789f524_d8a3_6787_39a9_b5039ca79e1b["VersionPicker.js"]
  c789f524_d8a3_6787_39a9_b5039ca79e1b --> 7d63591d_64d7_3647_f176_d8bc764bfb02
  style 7d63591d_64d7_3647_f176_d8bc764bfb02 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Version tags are loaded from the GitHub API. Since the GitHub API is rate-limited
 * we attempt to save and load the tags in sessionStorage when possible. Since its unlikely
 * that versions will change during a single session this should be safe.
 */

const TAGS_CACHE_KEY = '@react-dom-fixtures/tags';

/**
 * Its possible that users will be testing changes frequently
 * in a browser that does not support sessionStorage. If the API does
 * get rate limited this hardcoded fallback will be loaded instead.
 * This way users can still switch between ~some versions while testing.
 * If there's a specific version they need to test that is not here, they
 * can manually load it by editing the URL (`?version={whatever}`)
 */
const fallbackTags = [
  '15.4.2',
  '15.3.2',
  '15.2.1',
  '15.1.0',
  '15.0.2',
  '0.14.8',
  '0.13.0',
].map(version => ({
  name: `v${version}`,
}));

let canUseSessionStorage = true;

try {
  sessionStorage.setItem('foo', '');
} catch (err) {
  canUseSessionStorage = false;
}

/**
 * Attempts to load tags from sessionStorage. In cases where
 * sessionStorage is not available (Safari private browsing) or the
 * tags are cached a fetch request is made to the GitHub API.
 *
 * Returns a promise so that the consuming module can always assume
 * the request is async, even if its loaded from sessionStorage.
 */
export default function getVersionTags() {
  return new Promise(resolve => {
    let cachedTags;
    if (canUseSessionStorage) {
      cachedTags = sessionStorage.getItem(TAGS_CACHE_KEY);
    }
    if (cachedTags) {
      cachedTags = JSON.parse(cachedTags);
      resolve(cachedTags);
    } else {
      fetch('https://api.github.com/repos/facebook/react/tags?per_page=1000', {
        mode: 'cors',
      })
        .then(res => res.json())
        .then(tags => {
          // A message property indicates an error was sent from the API
          if (tags.message) {
            return resolve(fallbackTags);
          }
          if (canUseSessionStorage) {
            sessionStorage.setItem(TAGS_CACHE_KEY, JSON.stringify(tags));
          }
          resolve(tags);
        })
        .catch(() => resolve(fallbackTags));
    }
  });
}

Domain

Subdomains

Frequently Asked Questions

What does tags.js do?
tags.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Optimization subdomain.
What functions are defined in tags.js?
tags.js defines 2 function(s): fallbackTags, getVersionTags.
What files import tags.js?
tags.js is imported by 1 file(s): VersionPicker.js.
Where is tags.js in the architecture?
tags.js is located at fixtures/dom/src/tags.js (domain: BabelCompiler, subdomain: Optimization, directory: fixtures/dom/src).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free