@@ -22,59 +22,14 @@ var RESERVED_PROPS = {
22
22
ref : true
23
23
} ;
24
24
25
- /**
26
- * Warn for mutations.
27
- *
28
- * @internal
29
- * @param {object } object
30
- * @param {string } key
31
- */
32
- function defineWarningProperty ( object , key ) {
33
- Object . defineProperty ( object , key , {
34
-
35
- configurable : false ,
36
- enumerable : true ,
37
-
38
- get : function ( ) {
39
- if ( ! this . _store ) {
40
- return null ;
41
- }
42
- return this . _store [ key ] ;
43
- } ,
44
-
45
- set : function ( value ) {
46
- warning (
47
- false ,
48
- 'Don\'t set the %s property of the React element. Instead, ' +
49
- 'specify the correct value when initially creating the element.' ,
50
- key
51
- ) ;
52
- this . _store [ key ] = value ;
53
- }
54
-
55
- } ) ;
56
- }
57
-
58
25
/**
59
26
* This is updated to true if the membrane is successfully created.
60
27
*/
61
- var useMutationMembrane = false ;
62
-
63
- /**
64
- * Warn for mutations.
65
- *
66
- * @internal
67
- * @param {object } element
68
- */
69
- function defineMutationMembrane ( prototype ) {
28
+ var canDefineProperty = false ;
29
+ if ( __DEV__ ) {
70
30
try {
71
- var pseudoFrozenProperties = {
72
- props : true
73
- } ;
74
- for ( var key in pseudoFrozenProperties ) {
75
- defineWarningProperty ( prototype , key ) ;
76
- }
77
- useMutationMembrane = true ;
31
+ Object . defineProperty ( { } , 'x' , { } ) ;
32
+ canDefineProperty = true ;
78
33
} catch ( x ) {
79
34
// IE will fail on defineProperty
80
35
}
@@ -91,57 +46,46 @@ function defineMutationMembrane(prototype) {
91
46
* @internal
92
47
*/
93
48
var ReactElement = function ( type , key , ref , owner , context , props ) {
94
- // Built-in properties that belong on the element
95
- this . type = type ;
96
- this . key = key ;
97
- this . ref = ref ;
49
+ var element = {
50
+ // Built-in properties that belong on the element
51
+ type : type ,
52
+ key : key ,
53
+ ref : ref ,
98
54
99
- // Record the component responsible for creating this element.
100
- this . _owner = owner ;
55
+ // Record the component responsible for creating this element.
56
+ _owner : owner ,
57
+
58
+ props : props ,
59
+
60
+ _isReactElement : true
61
+ } ;
101
62
102
63
if ( __DEV__ ) {
103
64
// The validation flag and props are currently mutative. We put them on
104
65
// an external backing store so that we can freeze the whole object.
105
66
// This can be replaced with a WeakMap once they are implemented in
106
67
// commonly used development environments.
107
- this . _store = { props : props , originalProps : assign ( { } , props ) } ;
68
+ element . _store = { originalProps : assign ( { } , props ) } ;
108
69
109
70
// To make comparing ReactElements easier for testing purposes, we make
110
71
// the validation flag non-enumerable (where possible, which should
111
72
// include every environment we run tests in), so the test framework
112
73
// ignores it.
113
- try {
114
- Object . defineProperty ( this . _store , 'validated' , {
74
+ if ( canDefineProperty ) {
75
+ Object . defineProperty ( element . _store , 'validated' , {
115
76
configurable : false ,
116
77
enumerable : false ,
117
78
writable : true
118
79
} ) ;
119
- } catch ( x ) {
120
- }
121
- this . _store . validated = false ;
122
-
123
- // We're not allowed to set props directly on the object so we early
124
- // return and rely on the prototype membrane to forward to the backing
125
- // store.
126
- if ( useMutationMembrane ) {
127
- Object . freeze ( this ) ;
128
- return ;
129
80
}
130
- }
81
+ element . _store . validated = false ;
131
82
132
- this . props = props ;
133
- } ;
83
+ Object . freeze ( element ) ;
84
+ }
134
85
135
- // We intentionally don't expose the function on the constructor property.
136
- // ReactElement should be indistinguishable from a plain object.
137
- ReactElement . prototype = {
138
- _isReactElement : true
86
+ return element ;
139
87
} ;
140
88
141
- if ( __DEV__ ) {
142
- defineMutationMembrane ( ReactElement . prototype ) ;
143
- }
144
-
145
89
ReactElement . createElement = function ( type , config , children ) {
146
90
var propName ;
147
91
@@ -186,7 +130,7 @@ ReactElement.createElement = function(type, config, children) {
186
130
}
187
131
}
188
132
189
- return new ReactElement (
133
+ return ReactElement (
190
134
type ,
191
135
key ,
192
136
ref ,
@@ -208,7 +152,7 @@ ReactElement.createFactory = function(type) {
208
152
} ;
209
153
210
154
ReactElement . cloneAndReplaceProps = function ( oldElement , newProps ) {
211
- var newElement = new ReactElement (
155
+ var newElement = ReactElement (
212
156
oldElement . type ,
213
157
oldElement . key ,
214
158
oldElement . ref ,
@@ -268,7 +212,7 @@ ReactElement.cloneElement = function(element, config, children) {
268
212
props . children = childArray ;
269
213
}
270
214
271
- return new ReactElement (
215
+ return ReactElement (
272
216
element . type ,
273
217
key ,
274
218
ref ,
0 commit comments