1
+ /* eslint-disable indent */
2
+ /* eslint-disable brace-style */
3
+ /* eslint-disable comma-dangle */
1
4
/**
2
5
* This file contains core module functionality.
3
6
*
41
44
/* eslint-disable no-use-before-define */
42
45
/* eslint-disable no-param-reassign */
43
46
44
- const Tree = require ( './tree' ) ;
47
+ const { Tree, UnfilteredTreeNode } = require ( './tree' ) ;
45
48
const astParser = require ( './astParser' ) ;
46
49
const { saveState } = require ( './masterState' ) ;
50
+ // import * as reactWorkTags from './reactWorkTags';
47
51
48
52
module . exports = ( snap , mode ) => {
49
53
let fiberRoot = null ;
50
54
let astHooks ;
51
55
let concurrent = false ; // flag to check if we are in concurrent mode
56
+ const reactWorkTags = [
57
+ 'FunctionComponent' ,
58
+ 'ClassComponent' ,
59
+ 'IndeterminateComponent' ,
60
+ 'HostRoot' , // Root of a host tree. Could be nested inside another node.
61
+ 'HostPortal' , // A subtree. Could be an entry point to a different renderer.
62
+ 'HostComponent' ,
63
+ 'HostText' ,
64
+ ] ;
65
+
52
66
53
67
function sendSnapshot ( ) {
54
68
// Don't send messages while jumping or while paused
@@ -123,50 +137,72 @@ module.exports = (snap, mode) => {
123
137
return memoized ;
124
138
}
125
139
126
- function createTree ( currentFiber , tree = new Tree ( 'root' ) ) {
127
- // Base case: child or sibling pointed to null
128
- if ( ! currentFiber ) return tree ;
129
-
130
- const {
131
- sibling,
132
- stateNode,
133
- child,
134
- memoizedState,
135
- elementType,
136
- } = currentFiber ;
140
+
141
+ function createTree ( curFiber , parentNode ) {
142
+ // on call from updateSnapShot, no parentNode provided, so create a root node
143
+ if ( ! parentNode ) parentNode = new Tree ( 'root' ) ;
144
+
145
+ // Base case: parentNode's child or sibling pointed to null
146
+ if ( ! curFiber ) return parentNode ;
147
+
148
+ let newChildNode = null ;
137
149
138
- let nextTree = tree ;
150
+ // If stateful, add to parentNode's children array, then inject new setState into fiber node
151
+ if ( curFiber . stateNode && curFiber . stateNode . state ) {
152
+ newChildNode = parentNode . appendChild ( curFiber . stateNode ) ;
153
+ changeSetState ( curFiber . stateNode ) ;
139
154
140
- // Check if stateful component
141
- if ( stateNode && stateNode . state ) {
142
- nextTree = tree . appendChild ( stateNode ) ; // Add component to tree
143
- changeSetState ( stateNode ) ; // Change setState functionality
155
+ // newChildNode.isStateful = true;
156
+ newChildNode . tagLabel = reactWorkTags [ curFiber . tag ] ;
157
+ newChildNode . actualDuration = curFiber . actualDuration ;
158
+ // newChildNode.actualStartTime = curFiber.actualStartTime;
159
+ // newChildNode.selfBaseDuration = curFiber.selfBaseDuration;
160
+ // newChildNode.treeBaseDuration = curFiber.treeBaseDuration;
144
161
}
145
162
146
- // Check if the component uses hooks
147
- if (
148
- memoizedState
149
- && Object . hasOwnProperty . call ( memoizedState , 'baseState' )
150
- ) {
151
- // 'catch-all' for suspense elements (experimental)
152
- if ( typeof elementType . $$typeof === 'symbol' ) return ;
153
- // Traverse through the currentFiber and extract the getters/setters
154
- astHooks = astParser ( elementType ) ;
155
- saveState ( astHooks ) ;
156
- // Create a traversed property and assign to the evaluated result of
157
- // invoking traverseHooks with memoizedState
158
- memoizedState . traversed = traverseHooks ( memoizedState ) ;
159
- nextTree = tree . appendChild ( memoizedState ) ;
160
- }
163
+ // Recurse to sibling; siblings that have state should be added to our parentNode
164
+ createTree ( curFiber . sibling , parentNode ) ;
161
165
162
- // Recurse on siblings
163
- createTree ( sibling , tree ) ;
164
- // Recurse on children
165
- createTree ( child , nextTree ) ;
166
+ // Recurse to child; If this fiber was stateful, then we added a newChildNode here, and we want
167
+ // to attach further children to that. If this fiber wasn't stateful, we want to attach any
168
+ // children to our existing parentNode.
169
+ createTree ( curFiber . child , newChildNode || parentNode ) ;
166
170
167
- return tree ;
171
+ return parentNode ;
168
172
}
169
173
174
+
175
+ // function createUnfilteredTree(curFiber, parentNode) {
176
+ // // on call from updateSnapShot, no parentNode provided, so create a root node
177
+ // if(! parentNode) parentNode = new Tree('root');
178
+
179
+ // // Base case: parentNode's child or sibling pointed to null
180
+ // if (!curFiber) return parentNode;
181
+
182
+ // let newChildNode = null;
183
+
184
+ // // If stateful, add to parentNode's children array, then inject new setState into fiber node
185
+ // if (curFiber.stateNode && curFiber.stateNode.state) {
186
+ // newChildNode = parentNode.appendChild(curFiber.stateNode);
187
+ // // changeSetState(curFiber.stateNode);
188
+ // newChildNode.isStateful = true;
189
+ // }
190
+ // else {
191
+
192
+ // }
193
+
194
+ // // Recurse to sibling; siblings that have state should be added to our parentNode
195
+ // createTree(curFiber.sibling, parentNode);
196
+
197
+ // // Recurse to child; If this fiber was stateful, then we added a newChildNode here, and we want
198
+ // // to attach further children to that. If this fiber wasn't stateful, we want to attach any
199
+ // // children to our existing parentNode.
200
+ // createTree(curFiber.child, newChildNode || parentNode);
201
+
202
+ // return parentNode;
203
+ // }
204
+
205
+
170
206
// ! BUG: skips 1st hook click
171
207
async function updateSnapShotTree ( ) {
172
208
let current ;
@@ -185,6 +221,9 @@ module.exports = (snap, mode) => {
185
221
}
186
222
187
223
snap . tree = createTree ( current ) ;
224
+ console . log ( "updateSnapShotTree -> snap.tree" , snap . tree )
225
+ // snap.unfilteredTree = createUnfilteredTree(current);
226
+ // console.log("updateSnapShotTree -> snap.unfilteredTree", snap.unfilteredTree)
188
227
}
189
228
190
229
return async container => {
@@ -213,3 +252,82 @@ module.exports = (snap, mode) => {
213
252
} ) ;
214
253
} ;
215
254
} ;
255
+
256
+
257
+
258
+
259
+ // function createUnfilteredTree(currentFiber, tree = new Tree('root')) {
260
+ // // Base case: child or sibling pointed to null
261
+ // if (!currentFiber) return tree;
262
+
263
+ // const { sibling, stateNode, child, memoizedState, elementType,
264
+ // tag, actualDuration, actualStartTime, selfBaseDuration, treeBaseDuration,
265
+ // } = currentFiber;
266
+
267
+ // const extraProps = {
268
+ // tag, actualDuration, actualStartTime, selfBaseDuration, treeBaseDuration,
269
+ // };
270
+
271
+ // let nextTree = tree;
272
+ // let nextTreeUnfiltered = unfilteredTreeNode = new UnfilteredTreeNode('root');
273
+
274
+ // // Check if stateful component
275
+ // if (stateNode && stateNode.state) {
276
+ // nextTree = tree.appendChild(stateNode); // Add component to tree
277
+ // changeSetState(stateNode); // Change setState functionality
278
+ // }
279
+ // nextTreeUnfiltered = unfilteredTreeNode.appendChild(stateNode);
280
+
281
+ // // TODO: handle Hooks cases...
282
+
283
+ // // Recurse on siblings
284
+ // createTree(sibling, tree);
285
+ // // Recurse on children
286
+ // createTree(child, nextTree);
287
+
288
+ // return tree;
289
+ // }
290
+
291
+
292
+
293
+ // Check if the component uses hooks
294
+ // if (memoizedState && Object.hasOwnProperty.call(memoizedState, 'baseState')) {
295
+ // // 'catch-all' for suspense elements (experimental)
296
+ // if (typeof elementType.$$typeof === 'symbol') return;
297
+ // // Traverse through the currentFiber and extract the getters/setters
298
+ // astHooks = astParser(elementType);
299
+ // saveState(astHooks);
300
+ // // Create a traversed property and assign to the evaluated result of
301
+ // // invoking traverseHooks with memoizedState
302
+ // memoizedState.traversed = traverseHooks(memoizedState);
303
+ // nextTree = tree.appendChild(memoizedState);
304
+ // }
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+ // function createTree(currentFiber, tree = new Tree('root')) {
314
+ // // Base case: child or sibling pointed to null
315
+ // if (!currentFiber) return tree;
316
+
317
+ // const { sibling, stateNode, child, memoizedState, elementType } = currentFiber;
318
+
319
+ // let nextTree = tree;
320
+
321
+ // // Check if stateful component
322
+ // if (stateNode && stateNode.state) {
323
+ // nextTree = tree.appendChild(stateNode); // Add component to tree
324
+ // changeSetState(stateNode); // Change setState functionality
325
+ // }
326
+
327
+ // // Recurse on siblings
328
+ // createTree(sibling, tree);
329
+ // // Recurse on children
330
+ // createTree(child, nextTree);
331
+
332
+ // return tree;
333
+ // }
0 commit comments