cache.js — react Source File
Architecture documentation for cache.js, a javascript file in the react codebase. 2 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 7c3a162e_3c18_db78_b0f1_47504f41bf48["cache.js"] d8f20c67_f5fa_0f0a_c967_c41fd9ffce07["ReactTypes"] 7c3a162e_3c18_db78_b0f1_47504f41bf48 --> d8f20c67_f5fa_0f0a_c967_c41fd9ffce07 ac587885_e294_a1e9_b13f_5e7b920fdb42["react"] 7c3a162e_3c18_db78_b0f1_47504f41bf48 --> ac587885_e294_a1e9_b13f_5e7b920fdb42 fd0c3251_3b74_cf9d_8897_18f7e16e765e["OwnersListContext.js"] fd0c3251_3b74_cf9d_8897_18f7e16e765e --> 7c3a162e_3c18_db78_b0f1_47504f41bf48 style 7c3a162e_3c18_db78_b0f1_47504f41bf48 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {
ReactContext,
Thenable,
FulfilledThenable,
RejectedThenable,
} from 'shared/ReactTypes';
import * as React from 'react';
import {createContext} from 'react';
// TODO (cache) Remove this cache; it is outdated and will not work with newer APIs like startTransition.
// Cache implementation was forked from the React repo:
// https://github.com/facebook/react/blob/main/packages/react-cache/src/ReactCacheOld.js
//
// This cache is simpler than react-cache in that:
// 1. Individual items don't need to be invalidated.
// Profiling data is invalidated as a whole.
// 2. We didn't need the added overhead of an LRU cache.
// The size of this cache is bounded by how many renders were profiled,
// and it will be fully reset between profiling sessions.
export type {Thenable};
export type Resource<Input, Key, Value> = {
clear(): void,
invalidate(Key): void,
read(Input): Value,
preload(Input): void,
write(Key, Value): void,
};
let readContext;
if (typeof React.use === 'function') {
readContext = function (Context: ReactContext<null>) {
// eslint-disable-next-line react-hooks-published/rules-of-hooks
return React.use(Context);
};
} else if (
typeof (React: any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ===
'object'
) {
const ReactCurrentDispatcher = (React: any)
.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher;
readContext = function (Context: ReactContext<null>) {
const dispatcher = ReactCurrentDispatcher.current;
if (dispatcher === null) {
throw new Error(
'react-cache: read and preload may only be called from within a ' +
"component's render. They are not supported in event handlers or " +
'lifecycle methods.',
// ... (132 more lines)
Domain
Dependencies
- ReactTypes
- react
Source
Frequently Asked Questions
What does cache.js do?
cache.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does cache.js depend on?
cache.js imports 2 module(s): ReactTypes, react.
What files import cache.js?
cache.js is imported by 1 file(s): OwnersListContext.js.
Where is cache.js in the architecture?
cache.js is located at packages/react-devtools-shared/src/devtools/cache.js (domain: BabelCompiler, directory: packages/react-devtools-shared/src/devtools).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free