Home / File/ makeReadOnly.ts — react Source File

makeReadOnly.ts — react Source File

Architecture documentation for makeReadOnly.ts, a typescript file in the react codebase. 0 imports, 1 dependents.

File typescript BabelCompiler Optimization 1 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  d6c796a8_fd31_85fd_3d28_009b4955a0c4["makeReadOnly.ts"]
  9d3f0d29_1a88_4136_a1d9_f33cb8e7eac9["makeReadOnly-test.ts"]
  9d3f0d29_1a88_4136_a1d9_f33cb8e7eac9 --> d6c796a8_fd31_85fd_3d28_009b4955a0c4
  style d6c796a8_fd31_85fd_3d28_009b4955a0c4 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.
 */

'use strict';

type ROViolationType =
  | 'FORGET_MUTATE_IMMUT'
  | 'FORGET_DELETE_PROP_IMMUT'
  | 'FORGET_CHANGE_PROP_IMMUT'
  | 'FORGET_ADD_PROP_IMMUT';
type ROViolationLogger = (
  violation: ROViolationType,
  source: string,
  key: string,
  value?: any,
) => void;

/**
 * Represents a "proxy" of a read-only object property
 *   savedVal: underlying "source of truth" for a property value
 *   getter: hack, this lets us check whether we have already saved this property
 * */
type SavedEntry = {
  savedVal: unknown;
  getter: () => unknown;
};
type SavedROObject = Map<string, SavedEntry>;
type SavedROObjects = WeakMap<Object, SavedROObject>;

// Utility functions
function isWriteable(desc: PropertyDescriptor) {
  return (desc.writable || desc.set) && desc.configurable;
}

function getOrInsertDefault(
  m: SavedROObjects,
  k: object,
): {existed: boolean; entry: SavedROObject} {
  const entry = m.get(k);
  if (entry) {
    return {existed: true, entry};
  } else {
    const newEntry: SavedROObject = new Map();
    m.set(k, newEntry);
    return {existed: false, entry: newEntry};
  }
}

function buildMakeReadOnly(
  logger: ROViolationLogger,
  skippedClasses: string[],
): <T>(val: T, source: string) => T {
  // All saved proxys
  const savedROObjects: SavedROObjects = new WeakMap();

  // Overwrites an object property with its proxy and saves its original value
// ... (94 more lines)

Domain

Subdomains

Frequently Asked Questions

What does makeReadOnly.ts do?
makeReadOnly.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Optimization subdomain.
What functions are defined in makeReadOnly.ts?
makeReadOnly.ts defines 4 function(s): buildMakeReadOnly, getOrInsertDefault, isWriteable, violation.
What files import makeReadOnly.ts?
makeReadOnly.ts is imported by 1 file(s): makeReadOnly-test.ts.
Where is makeReadOnly.ts in the architecture?
makeReadOnly.ts is located at compiler/packages/make-read-only-util/src/makeReadOnly.ts (domain: BabelCompiler, subdomain: Optimization, directory: compiler/packages/make-read-only-util/src).

Analyze Your Own Codebase

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

Try Supermodel Free