Home / File/ hookSerializer.js — react Source File

hookSerializer.js — react Source File

Architecture documentation for hookSerializer.js, a javascript file in the react codebase.

Entity Profile

Relationship Graph

Source Code

function hasAbsoluteFileName(hook) {
  const fileName = hook.hookSource ? hook.hookSource.fileName : null;
  if (fileName == null) {
    return false;
  } else {
    return fileName.indexOf('/react-devtools-shared/') > 0;
  }
}

function serializeHook(hook) {
  if (!hook.hookSource) return hook;

  // Remove user-specific portions of this file path.
  let fileName = hook.hookSource.fileName;
  const index = fileName.lastIndexOf('/react-devtools-shared/');
  fileName = fileName.slice(index + 1);

  let subHooks = hook.subHooks;
  if (subHooks) {
    subHooks = subHooks.map(serializeHook);
  }

  return {
    ...hook,
    hookSource: {
      ...hook.hookSource,
      fileName,

      // Otherwise changes in any test case or formatting might invalidate other tests.
      columnNumber: 'removed by Jest serializer',
      lineNumber: 'removed by Jest serializer',
    },
    subHooks,
  };
}

// `test` is part of Jest's serializer API
export function test(maybeHook) {
  if (maybeHook === null || typeof maybeHook !== 'object') {
    return false;
  }

  const hasOwnProperty = Object.prototype.hasOwnProperty.bind(maybeHook);

  return (
    hasOwnProperty('id') &&
    hasOwnProperty('isStateEditable') &&
    hasOwnProperty('name') &&
    hasOwnProperty('subHooks') &&
    hasOwnProperty('value') &&
    // Don't re-process an already printed hook.
    hasAbsoluteFileName(maybeHook)
  );
}

// print() is part of Jest's serializer API
export function print(hook, serialize, indent) {
  // Don't stringify this object; that would break nested serializers.
  return serialize(serializeHook(hook));
}

Domain

Subdomains

Frequently Asked Questions

What does hookSerializer.js do?
hookSerializer.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 hookSerializer.js?
hookSerializer.js defines 4 function(s): hasAbsoluteFileName, print, serializeHook, test.
Where is hookSerializer.js in the architecture?
hookSerializer.js is located at packages/react-devtools-shared/src/__tests__/__serializers__/hookSerializer.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/__tests__/__serializers__).

Analyze Your Own Codebase

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

Try Supermodel Free