12
12
{
13
13
type : Button ,
14
14
props : {
15
- ...Button . defaultProps , // optional
16
- foo : 'bar' ,
15
+ foo : bar ,
17
16
children : [
18
17
{ type : 'span' , props : { children : a } } ,
19
18
{ type : 'span' , props : { children : b } }
22
21
23
22
// optional
24
23
key : 'mybutton' ,
25
- ref : myButtonRef ,
26
-
27
- // optional
28
- owner : React . currentOwner ,
29
- context : React . currentContext
24
+ ref : myButtonRef
30
25
}
31
26
32
27
/**
33
28
* JSX
34
29
*/
35
30
36
- < Button foo = " bar" key = "mybutton" ref = { myButtonRef} >
31
+ < Button foo = { bar} key = "mybutton" ref = { myButtonRef} >
37
32
< span > { a } </ span >
38
33
< span > { b} < / s p a n >
39
34
</Button >
40
35
41
36
/**
42
37
* PLAIN JS
38
+ * __DEV__ MODE
43
39
*
44
40
* This helper function ensures that your static children don't get the key
45
41
* warning. It creates a descriptor for you with the current owner/context.
46
42
* The props object is cloned and key/ref moved onto the descriptor.
47
43
*/
48
44
49
- var C = React . createDescriptor ;
45
+ var _Button = React . createFactory ( Button ) ;
46
+ var _span = React . createFactory ( 'span' ) ;
50
47
51
- C ( { type : Button , foo : ' bar' , key : 'mybutton' , ref : myButtonRef } ,
52
- C ( { type : 'span' } , a ) ,
53
- C ( { type : 'span' } , b )
48
+ _Button ( { foo : bar , key : 'mybutton' , ref : myButtonRef } ,
49
+ _span ( null , a ) ,
50
+ _span ( null , b )
54
51
)
55
52
56
53
/**
57
- * If you use JSX or statically can analyze that the C(...) call belongs to
54
+ * If you use JSX, or can statically analyze that the Factory calls belongs to
58
55
* React, then you can chose to opt-in to one of the optimizations modes.
59
56
*/
60
57
61
58
/**
62
- * FAST MODE
59
+ * INLINE
60
+ * PRODUCTION MODE
63
61
*
64
- * Fast mode allocates a props object inline instead of cloning a temporary
65
- * object. type, key and ref are separate arguments. Default props gets merged
66
- * in by mutating the props object. If they can be statically inferred, they
67
- * could also be inlined instead. This should not be typed in user code .
62
+ * Inline mode simply creates the descriptor objects inline in the code, with
63
+ * a lookup for current owner/context as well as resolving default props.
64
+ * If defaults aren't known statically, then we create a factory that can help
65
+ * assign defaults quickly on the newly created object .
68
66
*/
69
67
70
- var F = React . createDescriptorFast ;
68
+ var Button_assignDefaults = React . createDefaultsFactory ( Button ) ;
69
+
70
+ {
71
+ type : Button ,
72
+ props : Button_assignDefaults ( {
73
+ foo : bar ,
74
+ children : [
75
+ { type : 'span' , props : { children : a } , key : null , ref : null , _owner : React . _currentOwner , _context : React . _currentContext } ,
76
+ { type : 'span' , props : { children : b } , key : null , ref : null , _owner : React . _currentOwner , _context : React . _currentContext }
77
+ ]
78
+ } ) ,
79
+
80
+ key : 'mybutton' ,
81
+ ref : myButtonRef ,
71
82
72
- F ( Button , 'mybutton' , myButtonRef , { foo : 'bar' , children : [
73
- F ( 'span' , null , null , { children : a } ) ,
74
- F ( 'span' , null , null , { children : b } )
75
- ] } )
83
+ _owner : React . _currentOwner ,
84
+ _context : React . _currentContext
85
+ }
76
86
77
87
/**
78
88
* POOLED MODE
@@ -81,14 +91,34 @@ F(Button, 'mybutton', myButtonRef, { foo: 'bar', children: [
81
91
* from an pool and reuses them. It overrides the props on the pooled object.
82
92
*/
83
93
84
- var P = React . getPooledDescriptor ;
85
- var A = React . getPooledArray ;
86
- var t1 , t2 ;
87
-
88
- ( t1 = P ( Button , 'mybutton' , myButtonRef ) , t1 . props . foo = 'bar' , t1 . props . children = A ( 2 ) ,
89
- t1 . props . children [ 0 ] = ( t2 = P ( 'span' ) , t2 . props . children = a , t2 ) ,
90
- t1 . props . children [ 1 ] = ( t2 = P ( 'span' ) , t2 . props . children = b , t2 ) ,
91
- , t1 )
94
+ var P1 = React . createDescriptorPool ( {
95
+ type : Button ,
96
+ key : 'mybutton' ,
97
+ props : {
98
+ foo : null ,
99
+ children : null
100
+ }
101
+ } ) ;
102
+ var P2 = React . createDescriptorPool ( {
103
+ type : 'span' ,
104
+ props : {
105
+ children : null
106
+ }
107
+ } ) ;
108
+ var A2 = React . createArrayPool ( 2 ) ; // Number of items in the array
109
+ var t1 , t1p , t1c , t2 ;
110
+
111
+ (
112
+ t1 = P1 ( ) ,
113
+ t1 . ref = myButtonRef ,
114
+ t1p = t1 . props ,
115
+ t1p . foo = bar ,
116
+ t1p . children = A2 ( ) ,
117
+ t1c = t1p . children ,
118
+ t1c [ 0 ] = ( t2 = P2 ( ) , t2 . props . children = a , t2 ) ,
119
+ t1c [ 1 ] = ( t2 = P2 ( ) , t2 . props . children = b , t2 ) ,
120
+ t1
121
+ )
92
122
93
123
/**
94
124
* NATIVE COMPONENTS
@@ -97,10 +127,6 @@ var t1, t2;
97
127
* just strings. JSX will convert any lower-case tag name, or if it has a dash,
98
128
* into a string value instead of a scope reference. This makes them compatible
99
129
* with custom tags (Web Components).
100
- *
101
- * There's no direct dependency between a component and the React runtime.
102
- *
103
- * A tree of just native components should be JSON serializable.
104
130
*/
105
131
106
132
/**
@@ -112,7 +138,7 @@ var t1, t2;
112
138
*/
113
139
114
140
X `
115
- <my-button foo=" bar" key="mybutton" ref=${ myButtonRef } >
141
+ <my-button foo=${ bar } key="mybutton" ref=${ myButtonRef } >
116
142
<span>${ a } </span>
117
143
<span>${ b } </span>
118
144
</my-button>
0 commit comments