Home / File/ ReactGenericBatching.js — react Source File

ReactGenericBatching.js — react Source File

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

File javascript BabelCompiler Validation 4 dependents 5 functions

Entity Profile

Dependency Diagram

graph LR
  cb0565f2_ac6f_4c74_0235_a8c5f28c4334["ReactGenericBatching.js"]
  c3cad15d_c9da_151e_b05e_05fb765a0a1d["ReactFabric.js"]
  c3cad15d_c9da_151e_b05e_05fb765a0a1d --> cb0565f2_ac6f_4c74_0235_a8c5f28c4334
  846f0667_39ae_eb6e_55fe_26d3acf81e44["ReactFabricEventEmitter.js"]
  846f0667_39ae_eb6e_55fe_26d3acf81e44 --> cb0565f2_ac6f_4c74_0235_a8c5f28c4334
  baab5855_112a_37e6_6ca7_0813fd6ae027["ReactNativeEventEmitter.js"]
  baab5855_112a_37e6_6ca7_0813fd6ae027 --> cb0565f2_ac6f_4c74_0235_a8c5f28c4334
  05ccf719_9df5_4e38_01ba_8eadf09bacc1["ReactNativeRenderer.js"]
  05ccf719_9df5_4e38_01ba_8eadf09bacc1 --> cb0565f2_ac6f_4c74_0235_a8c5f28c4334
  style cb0565f2_ac6f_4c74_0235_a8c5f28c4334 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.
 */

// Used as a way to call batchedUpdates when we don't have a reference to
// the renderer. Such as when we're dispatching events or if third party
// libraries need to call batchedUpdates. Eventually, this API will go away when
// everything is batched by default. We'll then have a similar API to opt-out of
// scheduled work and instead do synchronous work.

// Defaults
let batchedUpdatesImpl = function (fn, bookkeeping) {
  return fn(bookkeeping);
};
let discreteUpdatesImpl = function (fn, a, b, c, d) {
  return fn(a, b, c, d);
};

let isInsideEventHandler = false;

export function batchedUpdates(fn, bookkeeping) {
  if (isInsideEventHandler) {
    // If we are currently inside another batch, we need to wait until it
    // fully completes before restoring state.
    return fn(bookkeeping);
  }
  isInsideEventHandler = true;
  try {
    return batchedUpdatesImpl(fn, bookkeeping);
  } finally {
    isInsideEventHandler = false;
  }
}

export function discreteUpdates(fn, a, b, c, d) {
  const prevIsInsideEventHandler = isInsideEventHandler;
  isInsideEventHandler = true;
  try {
    return discreteUpdatesImpl(fn, a, b, c, d);
  } finally {
    isInsideEventHandler = prevIsInsideEventHandler;
  }
}

export function setBatchingImplementation(
  _batchedUpdatesImpl,
  _discreteUpdatesImpl,
) {
  batchedUpdatesImpl = _batchedUpdatesImpl;
  discreteUpdatesImpl = _discreteUpdatesImpl;
}

Domain

Subdomains

Frequently Asked Questions

What does ReactGenericBatching.js do?
ReactGenericBatching.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in ReactGenericBatching.js?
ReactGenericBatching.js defines 5 function(s): batchedUpdates, batchedUpdatesImpl, discreteUpdates, discreteUpdatesImpl, setBatchingImplementation.
What files import ReactGenericBatching.js?
ReactGenericBatching.js is imported by 4 file(s): ReactFabric.js, ReactFabricEventEmitter.js, ReactNativeEventEmitter.js, ReactNativeRenderer.js.
Where is ReactGenericBatching.js in the architecture?
ReactGenericBatching.js is located at packages/react-native-renderer/src/legacy-events/ReactGenericBatching.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-native-renderer/src/legacy-events).

Analyze Your Own Codebase

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

Try Supermodel Free