Home / File/ accumulate.js — react Source File

accumulate.js — react Source File

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

File javascript BabelCompiler 1 imports 1 dependents

Entity Profile

Dependency Diagram

graph LR
  700e509c_b4f0_81bd_4316_b918f7f693c3["accumulate.js"]
  af78c51d_c7cb_3bf4_550f_f3fcc48f4f34["isArray"]
  700e509c_b4f0_81bd_4316_b918f7f693c3 --> af78c51d_c7cb_3bf4_550f_f3fcc48f4f34
  674c6180_b91e_e17d_fb2d_40a6a3631bb3["ResponderEventPlugin.js"]
  674c6180_b91e_e17d_fb2d_40a6a3631bb3 --> 700e509c_b4f0_81bd_4316_b918f7f693c3
  style 700e509c_b4f0_81bd_4316_b918f7f693c3 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 isArray from 'shared/isArray';

/**
 * Accumulates items that must not be null or undefined.
 *
 * This is used to conserve memory by avoiding array allocations.
 *
 * @return {*|array<*>} An accumulation of items.
 */
function accumulate<T>(
  current: ?(T | Array<T>),
  next: T | Array<T>,
): T | Array<T> {
  if (next == null) {
    throw new Error('Accumulated items must not be null or undefined.');
  }

  if (current == null) {
    return next;
  }

  // Both are not empty. Warning: Never call x.concat(y) when you are not
  // certain that x is an Array (x could be a string with concat method).
  if (isArray(current)) {
    // $FlowFixMe[incompatible-use] `isArray` does not ensure array is mutable
    return current.concat(next);
  }

  if (isArray(next)) {
    /* $FlowFixMe[incompatible-return] unsound if `next` is `T` and `T` an array,
     * `isArray` might refine to the array element type of `T` */
    return [current].concat(next);
  }

  return [current, next];
}

export default accumulate;

Domain

Dependencies

  • isArray

Frequently Asked Questions

What does accumulate.js do?
accumulate.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does accumulate.js depend on?
accumulate.js imports 1 module(s): isArray.
What files import accumulate.js?
accumulate.js is imported by 1 file(s): ResponderEventPlugin.js.
Where is accumulate.js in the architecture?
accumulate.js is located at packages/react-native-renderer/src/legacy-events/accumulate.js (domain: BabelCompiler, 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