deepDiffer.js — react Source File
Architecture documentation for deepDiffer.js, a javascript file in the react codebase. 0 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR f095975f_d060_c110_1c71_056d3e27b5d0["deepDiffer.js"] 829c86ab_8869_c64b_48b1_20ee575054de["diffAttributePayloads.js"] 829c86ab_8869_c64b_48b1_20ee575054de --> f095975f_d060_c110_1c71_056d3e27b5d0 style f095975f_d060_c110_1c71_056d3e27b5d0 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 Options = {+unsafelyIgnoreFunctions?: boolean};
/*
* @returns {bool} true if different, false if equal
*/
function deepDiffer(
one: any,
two: any,
maxDepthOrOptions: Options | number = -1,
maybeOptions?: Options,
): boolean {
const options =
typeof maxDepthOrOptions === 'number' ? maybeOptions : maxDepthOrOptions;
const maxDepth =
typeof maxDepthOrOptions === 'number' ? maxDepthOrOptions : -1;
if (maxDepth === 0) {
return true;
}
if (one === two) {
// Short circuit on identical object references instead of traversing them.
return false;
}
if (typeof one === 'function' && typeof two === 'function') {
// We consider all functions equal unless explicitly configured otherwise
let unsafelyIgnoreFunctions =
options == null ? null : options.unsafelyIgnoreFunctions;
if (unsafelyIgnoreFunctions == null) {
unsafelyIgnoreFunctions = true;
}
return !unsafelyIgnoreFunctions;
}
if (typeof one !== 'object' || one === null) {
// Primitives can be directly compared
return one !== two;
}
if (typeof two !== 'object' || two === null) {
// We know they are different because the previous case would have triggered
// otherwise.
return true;
}
if (one.constructor !== two.constructor) {
return true;
}
if (Array.isArray(one)) {
// We know two is also an array because the constructors are equal
const len = one.length;
if (two.length !== len) {
return true;
}
for (let ii = 0; ii < len; ii++) {
if (deepDiffer(one[ii], two[ii], maxDepth - 1, options)) {
return true;
}
}
} else {
for (const key in one) {
if (deepDiffer(one[key], two[key], maxDepth - 1, options)) {
return true;
}
}
for (const twoKey in two) {
// The only case we haven't checked yet is keys that are in two but aren't
// in one, which means they are different.
if (one[twoKey] === undefined && two[twoKey] !== undefined) {
return true;
}
}
}
return false;
}
module.exports = deepDiffer;
Domain
Subdomains
Functions
Imported By
Source
Frequently Asked Questions
What does deepDiffer.js do?
deepDiffer.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 deepDiffer.js?
deepDiffer.js defines 1 function(s): deepDiffer.
What files import deepDiffer.js?
deepDiffer.js is imported by 1 file(s): diffAttributePayloads.js.
Where is deepDiffer.js in the architecture?
deepDiffer.js is located at packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/deepDiffer.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free