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

Function printStore

packages/react-devtools-shared/src/devtools/utils.js:103–213  ·  view source on GitHub ↗
(
  store: Store,
  includeWeight: boolean = false,
  state: StateContext | null = null,
  includeSuspense: boolean = true,
)

Source from the content-addressed store, hash-verified

101}
102
103export function printStore(
104 store: Store,
105 includeWeight: boolean = false,
106 state: StateContext | null = null,
107 includeSuspense: boolean = true,
108): string {
109 const snapshotLines = [];
110
111 let rootWeight = 0;
112
113 function printSelectedMarker(index: number): string {
114 if (state === null) {
115 return '';
116 }
117 return state.inspectedElementIndex === index ? `→` : ' ';
118 }
119
120 function printErrorsAndWarnings(element: Element): string {
121 const {errorCount, warningCount} =
122 store.getErrorAndWarningCountForElementID(element.id);
123 if (errorCount === 0 && warningCount === 0) {
124 return '';
125 }
126 return ` ${errorCount > 0 ? '✕' : ''}${warningCount > 0 ? '⚠' : ''}`;
127 }
128
129 const ownerFlatTree = state !== null ? state.ownerFlatTree : null;
130 if (ownerFlatTree !== null) {
131 snapshotLines.push(
132 '[owners]' + (includeWeight ? ` (${ownerFlatTree.length})` : ''),
133 );
134 ownerFlatTree.forEach((element, index) => {
135 const printedSelectedMarker = printSelectedMarker(index);
136 const printedElement = printElement(element, false);
137 const printedErrorsAndWarnings = printErrorsAndWarnings(element);
138 snapshotLines.push(
139 `${printedSelectedMarker}${printedElement}${printedErrorsAndWarnings}`,
140 );
141 });
142 } else {
143 const errorsAndWarnings = store._errorsAndWarnings;
144 if (errorsAndWarnings.size > 0) {
145 let errorCount = 0;
146 let warningCount = 0;
147 errorsAndWarnings.forEach(entry => {
148 errorCount += entry.errorCount;
149 warningCount += entry.warningCount;
150 });
151
152 snapshotLines.push(`✕ ${errorCount}, ⚠ ${warningCount}`);
153 }
154
155 store.roots.forEach(rootID => {
156 const {weight} = ((store.getElementByID(rootID): any): Element);
157 const maybeWeightLabel = includeWeight ? ` (${weight})` : '';
158
159 // Store does not (yet) expose a way to get errors/warnings per root.
160 snapshotLines.push(`[root]${maybeWeightLabel}`);

Callers 3

printFunction · 0.90
printFunction · 0.90
StoreClass · 0.90

Calls 12

printSelectedMarkerFunction · 0.85
printElementFunction · 0.85
printErrorsAndWarningsFunction · 0.85
printRectsFunction · 0.85
getElementByIDMethod · 0.80
getElementAtIndexMethod · 0.80
getSuspenseByIDMethod · 0.80
joinMethod · 0.80
pushMethod · 0.65
forEachMethod · 0.65

Tested by 2

printFunction · 0.72
printFunction · 0.72