Skip to content

Commit 1ea1628

Browse files
committed
Working on backend for componentContext
1 parent 1054fc4 commit 1ea1628

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

src/backend/linkFiber.ts

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -194,38 +194,45 @@ const exclude = new Set([
194194
'_threadCount',
195195
'$$typeof',
196196
]);
197-
// -------------------CONVERT PROPT DATA TO STRING------------------------------
198-
// This recursive function is used to grab the state of children components
199-
// and push them into the parent componenent
200-
// react elements throw errors on client side of application - convert react/functions into string
201-
function convertDataToString(newObj, newPropData = {}, depth = 0) {
202-
// const newPropData = oldObj;
203-
for (const key in newObj) {
197+
// -----------------TRIMMING PASSED IN FIBER ROOT DATA--------------------------
198+
/**
199+
* This recursive function is used to grab the state of children components
200+
and push them into the parent componenent react elements throw errors on client side of application - convert react/functions into string
201+
*
202+
* @param reactDevData - The data object obtained from React Devtool. Ex: memoizedProps, memoizedState
203+
* @param reactimeData - The updated data object to send to front end of Reactime.
204+
* @param depth - reactDevData is nested object. The value in reactDevData can be another object. Depth is use to keep track the depth during the unraveling of nested object
205+
* @returns reactimeData - the updated data object to send to front end of ReactTime
206+
*/
207+
function convertDataToString(reactDevData, reactimeData = {}, depth = 0) {
208+
for (const key in reactDevData) {
204209
// Skip keys that are in exclude list OR if there is no value at key
205-
if (exclude.has(key) || !newObj[key]) {
210+
if (exclude.has(key) || !reactDevData[key]) {
206211
continue;
207-
// newPropData[key] = 'reactFiber';
208-
// return newPropData;
209212
}
210-
// If value at key is a function, assign key with value 'function' to newPropData object
211-
else if (typeof newObj[key] === 'function') {
212-
newPropData[key] = 'function';
213+
// If value at key is a function, assign key with value 'function' to reactimeData object
214+
else if (typeof reactDevData[key] === 'function') {
215+
reactimeData[key] = 'function';
213216
}
214-
// If value at key is an object, recusive call convertDataToString to traverse through all keys and append to newPropData object accodingly
215-
else if (typeof newObj[key] === 'object') {
216-
// newPropData[key] =
217+
// If value at key is an object, recusive call convertDataToString to traverse through all keys and append to reactimeData object accodingly
218+
else if (typeof reactDevData[key] === 'object') {
217219
depth > 10
218220
? 'convertDataToString reached max depth'
219-
: convertDataToString(newObj[key], newPropData, depth + 1);
221+
: convertDataToString(reactDevData[key], reactimeData, depth + 1);
220222
} else {
221-
newPropData[key] = newObj[key];
223+
reactimeData[key] = reactDevData[key];
222224
}
223225
}
224-
return newPropData;
226+
return reactimeData;
225227
}
226228
// -------------------------CREATE TREE TO SEND TO FRONT END--------------------
227229
/**
228230
* Every time a state change is made in the accompanying app, the extension creates a Tree “snapshot” of the current state, and adds it to the current “cache” of snapshots in the extension
231+
*
232+
* @param currentFiber
233+
* @param tree
234+
* @param fromSibling
235+
* @returns
229236
*/
230237
function createTree(
231238
currentFiber: Fiber,
@@ -262,6 +269,8 @@ function createTree(
262269
elementType,
263270
memoizedProps,
264271
memoizedState,
272+
dependencies,
273+
_debugHookTypes,
265274
});
266275

267276
// Tag === 5 signify this is a React Fragment. Each JSX component return a React fragment => The parent of a React Fragment could be a JSX component
@@ -304,12 +313,12 @@ function createTree(
304313

305314
// check to see if the parent component has any state/props
306315
if (memoizedProps && Object.keys(memoizedProps).length) {
307-
componentData.props = convertDataToString(memoizedProps, {});
316+
componentData.props = convertDataToString(memoizedProps);
308317
}
309-
310318
// if the component uses the useContext hook, we want to grab the context object and add it to the componentData object for that fiber
311319
if (tag === 0 && _debugHookTypes && dependencies?.firstContext?.memoizedValue) {
312-
componentData.context = convertDataToString(dependencies.firstContext.memoizedValue, null);
320+
componentData.context = convertDataToString(dependencies.firstContext.memoizedValue);
321+
console.log('Linkfiber', { context: componentData.context });
313322
}
314323
// Check if node is a stateful class component
315324
if (stateNode && stateNode.state && (tag === 0 || tag === 1 || tag === 2)) {

0 commit comments

Comments
 (0)