Home / Function/ createTextCache() — react Function Reference

createTextCache() — react Function Reference

Architecture documentation for the createTextCache() function in ReactWrongReturnPointer-test.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  2d4dfa22_73df_d30b_5866_62fadaf8fb6f["createTextCache()"]
  008cb6af_1523_1e04_cd6e_1a1af2a946e7["ReactWrongReturnPointer-test.js"]
  2d4dfa22_73df_d30b_5866_62fadaf8fb6f -->|defined in| 008cb6af_1523_1e04_cd6e_1a1af2a946e7
  style 2d4dfa22_73df_d30b_5866_62fadaf8fb6f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-dom/src/__tests__/ReactWrongReturnPointer-test.js lines 41–89

function createTextCache() {
  if (seededCache !== null) {
    // Trick to seed a cache before it exists.
    // TODO: Need a built-in API to seed data before the initial render (i.e.
    // not a refresh because nothing has mounted yet).
    const cache = seededCache;
    seededCache = null;
    return cache;
  }

  const data = new Map();
  const version = caches.length + 1;
  const cache = {
    version,
    data,
    resolve(text) {
      const record = data.get(text);
      if (record === undefined) {
        const newRecord = {
          status: 'resolved',
          value: text,
        };
        data.set(text, newRecord);
      } else if (record.status === 'pending') {
        const thenable = record.value;
        record.status = 'resolved';
        record.value = text;
        thenable.pings.forEach(t => t());
      }
    },
    reject(text, error) {
      const record = data.get(text);
      if (record === undefined) {
        const newRecord = {
          status: 'rejected',
          value: error,
        };
        data.set(text, newRecord);
      } else if (record.status === 'pending') {
        const thenable = record.value;
        record.status = 'rejected';
        record.value = error;
        thenable.pings.forEach(t => t());
      }
    },
  };
  caches.push(cache);
  return cache;
}

Domain

Subdomains

Frequently Asked Questions

What does createTextCache() do?
createTextCache() is a function in the react codebase, defined in packages/react-dom/src/__tests__/ReactWrongReturnPointer-test.js.
Where is createTextCache() defined?
createTextCache() is defined in packages/react-dom/src/__tests__/ReactWrongReturnPointer-test.js at line 41.

Analyze Your Own Codebase

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

Try Supermodel Free