1
1
import Tree from '../../models/tree' ;
2
2
import routes from '../../models/routes' ;
3
- import { ComponentData , Fiber } from '../../types/backendTypes' ;
3
+ import { ComponentData , Fiber , FiberRoot } from '../../types/backendTypes' ;
4
4
import { FunctionComponent , ClassComponent , HostRoot } from '../../types/backendTypes' ;
5
5
import IncrementFunc from './IncrementFunc' ;
6
6
import IncrementClass from './IncrementClass' ;
7
+ import { transformSync } from '@babel/core' ;
7
8
9
+ // ----------------------------TEST CASES FOR ROOT------------------------------
8
10
export const root : Fiber = {
9
11
tag : HostRoot ,
10
12
elementType : null ,
@@ -22,14 +24,15 @@ export const root: Fiber = {
22
24
export const rootPayload = new Tree ( 'root' , 'root' ) ;
23
25
rootPayload . route = routes . addRoute ( 'http://localhost/' ) ;
24
26
27
+ // ----------------------TEST CASE FOR FUNCTIONAL COMPONENT---------------------
25
28
export const functionalComponent : Fiber = {
26
29
tag : FunctionComponent ,
27
30
elementType : IncrementFunc ,
28
31
sibling : null ,
29
32
stateNode : null ,
30
33
child : null ,
31
34
memoizedState : {
32
- memoizeState : 0 ,
35
+ memoizedState : 0 ,
33
36
queue : {
34
37
dispatch : function ( newState ) {
35
38
this . memoizedState = newState ;
@@ -44,6 +47,25 @@ export const functionalComponent: Fiber = {
44
47
_debugHookTypes : [ 'useState' ] ,
45
48
} ;
46
49
50
+ const functionalComponentData : ComponentData = {
51
+ actualDuration : 1 ,
52
+ actualStartTime : 2 ,
53
+ selfBaseDuration : 3 ,
54
+ treeBaseDuration : 4 ,
55
+ context : { } ,
56
+ hooksIndex : [ 0 ] ,
57
+ hooksState : { count : 0 } ,
58
+ index : null ,
59
+ props : { } ,
60
+ state : null ,
61
+ } ;
62
+
63
+ export const functionalPayload : Tree = new Tree ( 'root' , 'root' ) ;
64
+ functionalPayload . route = rootPayload . route ;
65
+ functionalPayload . addChild ( { count : 0 } , 'IncrementFunc' , functionalComponentData , null ) ;
66
+
67
+ // -----------------------TEST CASE FOR CLASS COMPONENT-------------------------
68
+
47
69
export const classComponent : Fiber = {
48
70
tag : ClassComponent ,
49
71
elementType : IncrementClass ,
@@ -66,11 +88,7 @@ export const classComponent: Fiber = {
66
88
_debugHookTypes : null ,
67
89
} ;
68
90
69
- export const classPayload = new Tree ( 'root' , 'root' ) ;
70
- classPayload . route = rootPayload . route ;
71
-
72
- // Append increment child to root
73
- const componentData : ComponentData = {
91
+ const classComponentData : ComponentData = {
74
92
actualDuration : 1 ,
75
93
actualStartTime : 2 ,
76
94
selfBaseDuration : 3 ,
@@ -82,13 +100,82 @@ const componentData: ComponentData = {
82
100
props : { } ,
83
101
state : { count : 0 } ,
84
102
} ;
85
- classPayload . addChild ( { count : 0 } , 'IncrementClass' , componentData , null ) ;
103
+
104
+ export const classPayload = new Tree ( 'root' , 'root' ) ;
105
+ classPayload . route = rootPayload . route ;
106
+
107
+ classPayload . addChild ( { count : 0 } , 'IncrementClass' , classComponentData , null ) ;
86
108
87
109
export const updateClassPayload = new Tree ( 'root' , 'root' ) ;
88
110
updateClassPayload . route = rootPayload . route ;
89
111
updateClassPayload . addChild (
90
112
{ count : 2 } ,
91
113
'IncrementClass' ,
92
- { ...componentData , state : { count : 2 } } ,
114
+ { ...classComponentData , state : { count : 2 } } ,
93
115
null ,
94
116
) ;
117
+
118
+ // -----------------------TEST CASE FOR MIX OF COMPONENTS-----------------------
119
+ export const mixComponents : Fiber = deepCopy ( root ) ;
120
+ mixComponents . child = deepCopy ( functionalComponent ) ;
121
+ mixComponents . sibling = deepCopy ( classComponent ) ;
122
+ mixComponents . child ! . child = deepCopy ( functionalComponent ) ;
123
+ mixComponents . child ! . child ! . sibling = deepCopy ( classComponent ) ;
124
+ // console.dir(mixComponents, { depth: null });
125
+
126
+ export const mixPayload = new Tree ( 'root' , 'root' ) ;
127
+ mixPayload . route = rootPayload . route ;
128
+
129
+ // Outer Func Comp
130
+ let funcPayloadMix = new Tree ( { count : 0 } , 'IncrementFunc' , functionalComponentData , null ) ;
131
+ funcPayloadMix . componentData = {
132
+ ...funcPayloadMix . componentData ,
133
+ hooksState : { count : 0 } ,
134
+ hooksIndex : [ 0 ] ,
135
+ } ;
136
+ mixPayload . children . push ( deepCopy ( funcPayloadMix ) ) ;
137
+
138
+ // Outer Class Comp
139
+ let classPayloadMix = new Tree ( { count : 0 } , 'IncrementClass' , classComponentData , null ) ;
140
+ classPayloadMix . componentData = {
141
+ ...classPayloadMix . componentData ,
142
+ state : { count : 0 } ,
143
+ index : 3 ,
144
+ } ;
145
+ mixPayload . children . push ( deepCopy ( classPayloadMix ) ) ;
146
+
147
+ // Inner Func Comp
148
+ funcPayloadMix = new Tree ( { count : 0 } , 'IncrementFunc' , functionalComponentData , null ) ;
149
+ funcPayloadMix . componentData = {
150
+ ...funcPayloadMix . componentData ,
151
+ hooksState : { count : 0 } ,
152
+ hooksIndex : [ 1 ] ,
153
+ } ;
154
+ funcPayloadMix . name = 'IncrementFunc1' ;
155
+ mixPayload . children [ 0 ] . children . push ( deepCopy ( funcPayloadMix ) ) ;
156
+
157
+ // Inner Class Comp
158
+ classPayloadMix = new Tree ( { count : 0 } , 'IncrementClass' , classComponentData , null ) ;
159
+ classPayloadMix . componentData = {
160
+ ...classPayloadMix . componentData ,
161
+ state : { count : 0 } ,
162
+ index : 2 ,
163
+ } ;
164
+ mixPayload . children [ 0 ] . children . push ( deepCopy ( classPayloadMix ) ) ;
165
+
166
+ // console.dir(mixPayload, { depth: null });
167
+
168
+ function deepCopy ( obj ) {
169
+ if ( obj === null || typeof obj !== 'object' ) {
170
+ return obj ;
171
+ }
172
+ const copy = Array . isArray ( obj ) ? [ ] : { } ;
173
+ Object . keys ( obj ) . forEach ( ( key ) => {
174
+ if ( typeof obj [ key ] === 'function' ) {
175
+ copy [ key ] = obj [ key ] ;
176
+ } else {
177
+ copy [ key ] = deepCopy ( obj [ key ] ) ;
178
+ }
179
+ } ) ;
180
+ return copy ;
181
+ }
0 commit comments