MCPcopy Index your code
hub / github.com/react/react / hydrate

Function hydrate

packages/react-devtools-shared/src/hydration.js:688–745  ·  view source on GitHub ↗
(
  object: any,
  cleaned: Array<Array<string | number>>,
  unserializable: Array<Array<string | number>>,
)

Source from the content-addressed store, hash-verified

686}
687
688export function hydrate(
689 object: any,
690 cleaned: Array<Array<string | number>>,
691 unserializable: Array<Array<string | number>>,
692): Object {
693 cleaned.forEach((path: Array<string | number>) => {
694 const length = path.length;
695 const last = path[length - 1];
696 const parent = getInObject(object, path.slice(0, length - 1));
697 if (!parent || !parent.hasOwnProperty(last)) {
698 return;
699 }
700
701 const value = parent[last];
702
703 if (!value) {
704 return;
705 } else if (value.type === 'infinity') {
706 parent[last] = Infinity;
707 } else if (value.type === 'nan') {
708 parent[last] = NaN;
709 } else if (value.type === 'undefined') {
710 parent[last] = undefined;
711 } else {
712 // Replace the string keys with Symbols so they're non-enumerable.
713 const replaced: {[key: symbol]: boolean | string} = {};
714 replaced[meta.inspectable] = !!value.inspectable;
715 replaced[meta.inspected] = false;
716 replaced[meta.name] = value.name;
717 replaced[meta.preview_long] = value.preview_long;
718 replaced[meta.preview_short] = value.preview_short;
719 replaced[meta.size] = value.size;
720 replaced[meta.readonly] = !!value.readonly;
721 replaced[meta.type] = value.type;
722
723 parent[last] = replaced;
724 }
725 });
726 unserializable.forEach((path: Array<string | number>) => {
727 const length = path.length;
728 const last = path[length - 1];
729 const parent = getInObject(object, path.slice(0, length - 1));
730 if (!parent || !parent.hasOwnProperty(last)) {
731 return;
732 }
733
734 const node = parent[last];
735
736 const replacement = {
737 ...node,
738 };
739
740 upgradeUnserializable(replacement, node);
741
742 parent[last] = replacement;
743 });
744 return object;
745}

Callers 1

hydrateHelperFunction · 0.90

Calls 3

getInObjectFunction · 0.90
upgradeUnserializableFunction · 0.85
forEachMethod · 0.65

Tested by

no test coverage detected