@samitouri / QOS-React-2 / commits / 009b7c8ae1

adding __self and __source special props

Jared Forsyth committed Aug 10, 2015 at 13:49 UTC 009b7c8ae10ce80df98ee45f772e0fd75959d5aa
2 files changed +26 -1
src/isomorphic/classic/element/ReactElement.js
+24 -1
@@ -18,6 +18,8 @@ var assign = require('Object.assign');
18 var RESERVED_PROPS = {
19 key: true,
20 ref: true,
21 + __self: true,
22 + __source: true,
23 };
24
25 /**
@@ -27,15 +29,24 @@ var RESERVED_PROPS = {
29 * @param {*} type
30 * @param {*} key
31 * @param {string|object} ref
32 + * @param {*} self A *temporary* helper to detect places where `this` is
33 + * different from the `owner` when React.createElement is called, so that we
34 + * can warn. We want to get rid of owner and replace string `ref`s with arrow
35 + * functions, and as long as `this` and owner are the same, there will be no
36 + * change in behavior.
37 + * @param {*} source An annotation object (added by a transpiler or otherwise)
38 + * indicating filename, line number, and/or other information.
39 * @param {*} owner
40 * @param {*} props
41 * @internal
42 */
34 -var ReactElement = function(type, key, ref, owner, props) {
43 +var ReactElement = function(type, key, ref, self, source, owner, props) {
44 // Built-in properties that belong on the element
45 this.type = type;
46 this.key = key;
47 this.ref = ref;
48 + this.self = self;
49 + this.source = source;
50
51 // Record the component responsible for creating this element.
52 this._owner = owner;
@@ -82,10 +93,14 @@ ReactElement.createElement = function(type, config, children) {
93
94 var key = null;
95 var ref = null;
96 + var self = null;
97 + var source = null;
98
99 if (config != null) {
100 ref = config.ref === undefined ? null : config.ref;
101 key = config.key === undefined ? null : '' + config.key;
102 + self = config.__self === undefined ? null : config.__self;
103 + source = config.__source === undefined ? null : config.__source;
104 // Remaining properties are added to a new props object
105 for (propName in config) {
106 if (config.hasOwnProperty(propName) &&
@@ -122,6 +137,8 @@ ReactElement.createElement = function(type, config, children) {
137 type,
138 key,
139 ref,
140 + self,
141 + source,
142 ReactCurrentOwner.current,
143 props
144 );
@@ -143,6 +160,8 @@ ReactElement.cloneAndReplaceProps = function(oldElement, newProps) {
160 oldElement.type,
161 oldElement.key,
162 oldElement.ref,
163 + oldElement.self,
164 + oldElement.source,
165 oldElement._owner,
166 newProps
167 );
@@ -164,6 +183,8 @@ ReactElement.cloneElement = function(element, config, children) {
183 // Reserved names are extracted
184 var key = element.key;
185 var ref = element.ref;
186 + var self = element.__self;
187 + var source = element.__source;
188
189 // Owner will be preserved, unless ref is overridden
190 var owner = element._owner;
@@ -203,6 +224,8 @@ ReactElement.cloneElement = function(element, config, children) {
224 element.type,
225 key,
226 ref,
227 + self,
228 + source,
229 owner,
230 props
231 );
src/renderers/dom/client/ReactMount.js
+2
@@ -539,6 +539,8 @@ var ReactMount = {
539 null,
540 null,
541 null,
542 + null,
543 + null,
544 nextElement
545 );
546