react 0.11.2 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/dist/JSXTransformer.js +2714 -7859
  2. package/dist/react-with-addons.js +3139 -3593
  3. package/dist/react-with-addons.min.js +11 -17
  4. package/dist/react.js +2940 -3308
  5. package/dist/react.min.js +11 -16
  6. package/lib/AutoFocusMixin.js +5 -12
  7. package/lib/BeforeInputEventPlugin.js +12 -14
  8. package/lib/CSSCore.js +6 -13
  9. package/lib/CSSProperty.js +10 -14
  10. package/lib/CSSPropertyOperations.js +46 -12
  11. package/lib/CallbackQueue.js +7 -14
  12. package/lib/ChangeEventPlugin.js +5 -12
  13. package/lib/ClientReactRootIndex.js +5 -12
  14. package/lib/CompositionEventPlugin.js +5 -12
  15. package/lib/DOMChildrenOperations.js +8 -15
  16. package/lib/DOMProperty.js +16 -19
  17. package/lib/DOMPropertyOperations.js +14 -14
  18. package/lib/Danger.js +12 -17
  19. package/lib/DefaultEventPluginOrder.js +5 -12
  20. package/lib/EnterLeaveEventPlugin.js +5 -12
  21. package/lib/EventConstants.js +5 -12
  22. package/lib/EventListener.js +14 -0
  23. package/lib/EventPluginHub.js +8 -26
  24. package/lib/EventPluginRegistry.js +5 -12
  25. package/lib/EventPluginUtils.js +5 -12
  26. package/lib/EventPropagators.js +12 -17
  27. package/lib/ExecutionEnvironment.js +5 -12
  28. package/lib/HTMLDOMPropertyConfig.js +16 -15
  29. package/lib/LinkedStateMixin.js +5 -12
  30. package/lib/LinkedValueUtils.js +5 -12
  31. package/lib/LocalEventTrapMixin.js +8 -14
  32. package/lib/MobileSafariClickEventPlugin.js +5 -12
  33. package/lib/Object.assign.js +45 -0
  34. package/lib/PooledClass.js +5 -12
  35. package/lib/React.js +87 -54
  36. package/lib/ReactBrowserComponentMixin.js +5 -12
  37. package/lib/ReactBrowserEventEmitter.js +7 -14
  38. package/lib/ReactCSSTransitionGroup.js +15 -17
  39. package/lib/ReactCSSTransitionGroupChild.js +9 -13
  40. package/lib/ReactChildren.js +5 -12
  41. package/lib/ReactComponent.js +61 -68
  42. package/lib/ReactComponentBrowserEnvironment.js +5 -12
  43. package/lib/ReactComponentWithPureRenderMixin.js +5 -12
  44. package/lib/ReactCompositeComponent.js +191 -180
  45. package/lib/ReactContext.js +8 -15
  46. package/lib/ReactCurrentOwner.js +5 -12
  47. package/lib/ReactDOM.js +145 -177
  48. package/lib/ReactDOMButton.js +8 -14
  49. package/lib/ReactDOMComponent.js +103 -38
  50. package/lib/ReactDOMForm.js +9 -15
  51. package/lib/ReactDOMIDOperations.js +5 -12
  52. package/lib/ReactDOMImg.js +8 -14
  53. package/lib/ReactDOMInput.js +30 -38
  54. package/lib/ReactDOMOption.js +8 -14
  55. package/lib/ReactDOMSelect.js +25 -24
  56. package/lib/ReactDOMSelection.js +11 -18
  57. package/lib/ReactDOMTextarea.js +19 -24
  58. package/lib/ReactDefaultBatchingStrategy.js +14 -18
  59. package/lib/ReactDefaultInjection.js +23 -26
  60. package/lib/ReactDefaultPerf.js +14 -17
  61. package/lib/ReactDefaultPerfAnalysis.js +18 -17
  62. package/lib/ReactElement.js +242 -0
  63. package/lib/{ReactDescriptorValidator.js → ReactElementValidator.js} +51 -56
  64. package/lib/ReactEmptyComponent.js +8 -13
  65. package/lib/ReactErrorUtils.js +5 -12
  66. package/lib/ReactEventEmitterMixin.js +5 -12
  67. package/lib/ReactEventListener.js +7 -14
  68. package/lib/ReactInjection.js +7 -14
  69. package/lib/ReactInputSelection.js +5 -12
  70. package/lib/ReactInstanceHandles.js +5 -12
  71. package/lib/ReactLegacyElement.js +243 -0
  72. package/lib/ReactLink.js +5 -12
  73. package/lib/ReactMarkupChecksum.js +5 -12
  74. package/lib/ReactMount.js +45 -32
  75. package/lib/ReactMultiChild.js +14 -18
  76. package/lib/ReactMultiChildUpdateTypes.js +5 -12
  77. package/lib/ReactNativeComponent.js +69 -0
  78. package/lib/ReactOwner.js +5 -12
  79. package/lib/ReactPerf.js +8 -13
  80. package/lib/ReactPropTransferer.js +34 -33
  81. package/lib/ReactPropTypeLocationNames.js +5 -12
  82. package/lib/ReactPropTypeLocations.js +5 -12
  83. package/lib/ReactPropTypes.js +38 -29
  84. package/lib/ReactPutListenerQueue.js +7 -14
  85. package/lib/ReactReconcileTransaction.js +7 -15
  86. package/lib/ReactRootIndex.js +5 -12
  87. package/lib/ReactServerRendering.js +21 -34
  88. package/lib/ReactServerRenderingTransaction.js +11 -15
  89. package/lib/ReactStateSetters.js +5 -12
  90. package/lib/ReactTestUtils.js +31 -33
  91. package/lib/ReactTextComponent.js +18 -21
  92. package/lib/ReactTransitionChildMapping.js +6 -13
  93. package/lib/ReactTransitionEvents.js +5 -12
  94. package/lib/ReactTransitionGroup.js +14 -17
  95. package/lib/ReactUpdates.js +43 -22
  96. package/lib/ReactWithAddons.js +7 -13
  97. package/lib/SVGDOMPropertyConfig.js +5 -12
  98. package/lib/SelectEventPlugin.js +13 -20
  99. package/lib/ServerReactRootIndex.js +5 -12
  100. package/lib/SimpleEventPlugin.js +20 -15
  101. package/lib/SyntheticClipboardEvent.js +5 -12
  102. package/lib/SyntheticCompositionEvent.js +5 -12
  103. package/lib/SyntheticDragEvent.js +5 -12
  104. package/lib/SyntheticEvent.js +9 -17
  105. package/lib/SyntheticFocusEvent.js +5 -12
  106. package/lib/SyntheticInputEvent.js +4 -11
  107. package/lib/SyntheticKeyboardEvent.js +17 -19
  108. package/lib/SyntheticMouseEvent.js +5 -12
  109. package/lib/SyntheticTouchEvent.js +5 -12
  110. package/lib/SyntheticUIEvent.js +5 -12
  111. package/lib/SyntheticWheelEvent.js +5 -12
  112. package/lib/Transaction.js +5 -12
  113. package/lib/ViewportMetrics.js +5 -12
  114. package/lib/accumulateInto.js +62 -0
  115. package/lib/adler32.js +6 -13
  116. package/lib/camelize.js +30 -0
  117. package/lib/camelizeStyleName.js +40 -0
  118. package/lib/cloneWithProps.js +9 -15
  119. package/lib/containsNode.js +5 -12
  120. package/lib/copyProperties.js +12 -12
  121. package/lib/createArrayFrom.js +5 -12
  122. package/lib/createFullPageComponent.js +12 -18
  123. package/lib/createNodesFromMarkup.js +5 -12
  124. package/lib/cx.js +5 -12
  125. package/lib/dangerousStyleValue.js +5 -12
  126. package/lib/deprecated.js +47 -0
  127. package/lib/emptyFunction.js +11 -22
  128. package/lib/emptyObject.js +5 -12
  129. package/lib/escapeTextForBrowser.js +5 -12
  130. package/lib/flattenChildren.js +19 -13
  131. package/lib/focusNode.js +10 -16
  132. package/lib/forEachAccumulated.js +5 -12
  133. package/lib/getActiveElement.js +5 -12
  134. package/lib/getEventCharCode.js +50 -0
  135. package/lib/getEventKey.js +9 -21
  136. package/lib/getEventModifierState.js +4 -11
  137. package/lib/getEventTarget.js +5 -12
  138. package/lib/getMarkupWrap.js +5 -12
  139. package/lib/getNodeForCharacterOffset.js +5 -12
  140. package/lib/getReactRootElementInContainer.js +5 -12
  141. package/lib/getTextContentAccessor.js +5 -12
  142. package/lib/getUnboundedScrollPosition.js +5 -12
  143. package/lib/hyphenate.js +5 -12
  144. package/lib/hyphenateStyleName.js +8 -15
  145. package/lib/instantiateReactComponent.js +90 -42
  146. package/lib/invariant.js +5 -12
  147. package/lib/isEventSupported.js +5 -12
  148. package/lib/isNode.js +5 -12
  149. package/lib/isTextInputElement.js +5 -12
  150. package/lib/isTextNode.js +5 -12
  151. package/lib/joinClasses.js +8 -13
  152. package/lib/keyMirror.js +5 -12
  153. package/lib/keyOf.js +5 -12
  154. package/lib/mapObject.js +35 -36
  155. package/lib/memoizeStringOnly.js +5 -12
  156. package/lib/merge.js +14 -17
  157. package/lib/mergeInto.js +13 -35
  158. package/lib/monitorCodeUse.js +5 -12
  159. package/lib/onlyChild.js +8 -15
  160. package/lib/performance.js +5 -12
  161. package/lib/performanceNow.js +5 -12
  162. package/lib/setInnerHTML.js +10 -19
  163. package/lib/shallowEqual.js +6 -13
  164. package/lib/shouldUpdateReactComponent.js +14 -22
  165. package/lib/toArray.js +5 -12
  166. package/lib/traverseAllChildren.js +34 -48
  167. package/lib/update.js +8 -15
  168. package/lib/warning.js +6 -13
  169. package/package.json +3 -8
  170. package/lib/ReactDescriptor.js +0 -251
  171. package/lib/accumulate.js +0 -54
  172. package/lib/mergeHelpers.js +0 -147
  173. package/lib/mixInto.js +0 -34
@@ -1,17 +1,10 @@
1
1
  /**
2
- * Copyright 2013-2014 Facebook, Inc.
2
+ * Copyright 2013-2014, Facebook, Inc.
3
+ * All rights reserved.
3
4
  *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
15
8
  *
16
9
  * @providesModule ReactDOMComponent
17
10
  * @typechecks static-only
@@ -29,11 +22,12 @@ var ReactMount = require("./ReactMount");
29
22
  var ReactMultiChild = require("./ReactMultiChild");
30
23
  var ReactPerf = require("./ReactPerf");
31
24
 
25
+ var assign = require("./Object.assign");
32
26
  var escapeTextForBrowser = require("./escapeTextForBrowser");
33
27
  var invariant = require("./invariant");
28
+ var isEventSupported = require("./isEventSupported");
34
29
  var keyOf = require("./keyOf");
35
- var merge = require("./merge");
36
- var mixInto = require("./mixInto");
30
+ var monitorCodeUse = require("./monitorCodeUse");
37
31
 
38
32
  var deleteListener = ReactBrowserEventEmitter.deleteListener;
39
33
  var listenTo = ReactBrowserEventEmitter.listenTo;
@@ -58,6 +52,16 @@ function assertValidProps(props) {
58
52
  props.children == null || props.dangerouslySetInnerHTML == null,
59
53
  'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
60
54
  ) : invariant(props.children == null || props.dangerouslySetInnerHTML == null));
55
+ if ("production" !== process.env.NODE_ENV) {
56
+ if (props.contentEditable && props.children != null) {
57
+ console.warn(
58
+ 'A component is `contentEditable` and contains `children` managed by ' +
59
+ 'React. It is now your responsibility to guarantee that none of those '+
60
+ 'nodes are unexpectedly modified or duplicated. This is probably not ' +
61
+ 'intentional.'
62
+ );
63
+ }
64
+ }
61
65
  ("production" !== process.env.NODE_ENV ? invariant(
62
66
  props.style == null || typeof props.style === 'object',
63
67
  'The `style` prop expects a mapping from style properties to values, ' +
@@ -66,6 +70,15 @@ function assertValidProps(props) {
66
70
  }
67
71
 
68
72
  function putListener(id, registrationName, listener, transaction) {
73
+ if ("production" !== process.env.NODE_ENV) {
74
+ // IE8 has no API for event capturing and the `onScroll` event doesn't
75
+ // bubble.
76
+ if (registrationName === 'onScroll' &&
77
+ !isEventSupported('scroll', true)) {
78
+ monitorCodeUse('react_no_scroll_event');
79
+ console.warn('This browser doesn\'t support the `onScroll` event');
80
+ }
81
+ }
69
82
  var container = ReactMount.findReactContainerForID(id);
70
83
  if (container) {
71
84
  var doc = container.nodeType === ELEMENT_NODE_TYPE ?
@@ -80,18 +93,66 @@ function putListener(id, registrationName, listener, transaction) {
80
93
  );
81
94
  }
82
95
 
96
+ // For HTML, certain tags should omit their close tag. We keep a whitelist for
97
+ // those special cased tags.
98
+
99
+ var omittedCloseTags = {
100
+ 'area': true,
101
+ 'base': true,
102
+ 'br': true,
103
+ 'col': true,
104
+ 'embed': true,
105
+ 'hr': true,
106
+ 'img': true,
107
+ 'input': true,
108
+ 'keygen': true,
109
+ 'link': true,
110
+ 'meta': true,
111
+ 'param': true,
112
+ 'source': true,
113
+ 'track': true,
114
+ 'wbr': true
115
+ // NOTE: menuitem's close tag should be omitted, but that causes problems.
116
+ };
117
+
118
+ // We accept any tag to be rendered but since this gets injected into abitrary
119
+ // HTML, we want to make sure that it's a safe tag.
120
+ // http://www.w3.org/TR/REC-xml/#NT-Name
121
+
122
+ var VALID_TAG_REGEX = /^[a-zA-Z][a-zA-Z:_\.\-\d]*$/; // Simplified subset
123
+ var validatedTagCache = {};
124
+ var hasOwnProperty = {}.hasOwnProperty;
125
+
126
+ function validateDangerousTag(tag) {
127
+ if (!hasOwnProperty.call(validatedTagCache, tag)) {
128
+ ("production" !== process.env.NODE_ENV ? invariant(VALID_TAG_REGEX.test(tag), 'Invalid tag: %s', tag) : invariant(VALID_TAG_REGEX.test(tag)));
129
+ validatedTagCache[tag] = true;
130
+ }
131
+ }
83
132
 
84
133
  /**
134
+ * Creates a new React class that is idempotent and capable of containing other
135
+ * React components. It accepts event listeners and DOM properties that are
136
+ * valid according to `DOMProperty`.
137
+ *
138
+ * - Event listeners: `onClick`, `onMouseDown`, etc.
139
+ * - DOM properties: `className`, `name`, `title`, etc.
140
+ *
141
+ * The `style` property functions differently from the DOM API. It accepts an
142
+ * object mapping of style properties to values.
143
+ *
85
144
  * @constructor ReactDOMComponent
86
145
  * @extends ReactComponent
87
146
  * @extends ReactMultiChild
88
147
  */
89
- function ReactDOMComponent(tag, omitClose) {
90
- this._tagOpen = '<' + tag;
91
- this._tagClose = omitClose ? '' : '</' + tag + '>';
148
+ function ReactDOMComponent(tag) {
149
+ validateDangerousTag(tag);
150
+ this._tag = tag;
92
151
  this.tagName = tag.toUpperCase();
93
152
  }
94
153
 
154
+ ReactDOMComponent.displayName = 'ReactDOMComponent';
155
+
95
156
  ReactDOMComponent.Mixin = {
96
157
 
97
158
  /**
@@ -115,10 +176,11 @@ ReactDOMComponent.Mixin = {
115
176
  mountDepth
116
177
  );
117
178
  assertValidProps(this.props);
179
+ var closeTag = omittedCloseTags[this._tag] ? '' : '</' + this._tag + '>';
118
180
  return (
119
181
  this._createOpenTagMarkupAndPutListeners(transaction) +
120
182
  this._createContentMarkup(transaction) +
121
- this._tagClose
183
+ closeTag
122
184
  );
123
185
  }
124
186
  ),
@@ -137,7 +199,7 @@ ReactDOMComponent.Mixin = {
137
199
  */
138
200
  _createOpenTagMarkupAndPutListeners: function(transaction) {
139
201
  var props = this.props;
140
- var ret = this._tagOpen;
202
+ var ret = '<' + this._tag;
141
203
 
142
204
  for (var propKey in props) {
143
205
  if (!props.hasOwnProperty(propKey)) {
@@ -152,7 +214,7 @@ ReactDOMComponent.Mixin = {
152
214
  } else {
153
215
  if (propKey === STYLE) {
154
216
  if (propValue) {
155
- propValue = props.style = merge(props.style);
217
+ propValue = props.style = assign({}, props.style);
156
218
  }
157
219
  propValue = CSSPropertyOperations.createMarkupForStyles(propValue);
158
220
  }
@@ -205,22 +267,22 @@ ReactDOMComponent.Mixin = {
205
267
  return '';
206
268
  },
207
269
 
208
- receiveComponent: function(nextDescriptor, transaction) {
209
- if (nextDescriptor === this._descriptor &&
210
- nextDescriptor._owner != null) {
211
- // Since descriptors are immutable after the owner is rendered,
270
+ receiveComponent: function(nextElement, transaction) {
271
+ if (nextElement === this._currentElement &&
272
+ nextElement._owner != null) {
273
+ // Since elements are immutable after the owner is rendered,
212
274
  // we can do a cheap identity compare here to determine if this is a
213
275
  // superfluous reconcile. It's possible for state to be mutable but such
214
276
  // change should trigger an update of the owner which would recreate
215
- // the descriptor. We explicitly check for the existence of an owner since
216
- // it's possible for a descriptor created outside a composite to be
277
+ // the element. We explicitly check for the existence of an owner since
278
+ // it's possible for a element created outside a composite to be
217
279
  // deeply mutated and reused.
218
280
  return;
219
281
  }
220
282
 
221
283
  ReactComponent.Mixin.receiveComponent.call(
222
284
  this,
223
- nextDescriptor,
285
+ nextElement,
224
286
  transaction
225
287
  );
226
288
  },
@@ -230,22 +292,22 @@ ReactDOMComponent.Mixin = {
230
292
  * attached to the DOM. Reconciles the root DOM node, then recurses.
231
293
  *
232
294
  * @param {ReactReconcileTransaction} transaction
233
- * @param {ReactDescriptor} prevDescriptor
295
+ * @param {ReactElement} prevElement
234
296
  * @internal
235
297
  * @overridable
236
298
  */
237
299
  updateComponent: ReactPerf.measure(
238
300
  'ReactDOMComponent',
239
301
  'updateComponent',
240
- function(transaction, prevDescriptor) {
241
- assertValidProps(this._descriptor.props);
302
+ function(transaction, prevElement) {
303
+ assertValidProps(this._currentElement.props);
242
304
  ReactComponent.Mixin.updateComponent.call(
243
305
  this,
244
306
  transaction,
245
- prevDescriptor
307
+ prevElement
246
308
  );
247
- this._updateDOMProperties(prevDescriptor.props, transaction);
248
- this._updateDOMChildren(prevDescriptor.props, transaction);
309
+ this._updateDOMProperties(prevElement.props, transaction);
310
+ this._updateDOMChildren(prevElement.props, transaction);
249
311
  }
250
312
  ),
251
313
 
@@ -301,7 +363,7 @@ ReactDOMComponent.Mixin = {
301
363
  }
302
364
  if (propKey === STYLE) {
303
365
  if (nextProp) {
304
- nextProp = nextProps.style = merge(nextProp);
366
+ nextProp = nextProps.style = assign({}, nextProp);
305
367
  }
306
368
  if (lastProp) {
307
369
  // Unset styles on `lastProp` but not on `nextProp`.
@@ -410,9 +472,12 @@ ReactDOMComponent.Mixin = {
410
472
 
411
473
  };
412
474
 
413
- mixInto(ReactDOMComponent, ReactComponent.Mixin);
414
- mixInto(ReactDOMComponent, ReactDOMComponent.Mixin);
415
- mixInto(ReactDOMComponent, ReactMultiChild.Mixin);
416
- mixInto(ReactDOMComponent, ReactBrowserComponentMixin);
475
+ assign(
476
+ ReactDOMComponent.prototype,
477
+ ReactComponent.Mixin,
478
+ ReactDOMComponent.Mixin,
479
+ ReactMultiChild.Mixin,
480
+ ReactBrowserComponentMixin
481
+ );
417
482
 
418
483
  module.exports = ReactDOMComponent;
@@ -1,17 +1,10 @@
1
1
  /**
2
- * Copyright 2013-2014 Facebook, Inc.
2
+ * Copyright 2013-2014, Facebook, Inc.
3
+ * All rights reserved.
3
4
  *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
15
8
  *
16
9
  * @providesModule ReactDOMForm
17
10
  */
@@ -22,10 +15,11 @@ var EventConstants = require("./EventConstants");
22
15
  var LocalEventTrapMixin = require("./LocalEventTrapMixin");
23
16
  var ReactBrowserComponentMixin = require("./ReactBrowserComponentMixin");
24
17
  var ReactCompositeComponent = require("./ReactCompositeComponent");
18
+ var ReactElement = require("./ReactElement");
25
19
  var ReactDOM = require("./ReactDOM");
26
20
 
27
- // Store a reference to the <form> `ReactDOMComponent`.
28
- var form = ReactDOM.form;
21
+ // Store a reference to the <form> `ReactDOMComponent`. TODO: use string
22
+ var form = ReactElement.createFactory(ReactDOM.form.type);
29
23
 
30
24
  /**
31
25
  * Since onSubmit doesn't bubble OR capture on the top level in IE8, we need
@@ -42,7 +36,7 @@ var ReactDOMForm = ReactCompositeComponent.createClass({
42
36
  // TODO: Instead of using `ReactDOM` directly, we should use JSX. However,
43
37
  // `jshint` fails to parse JSX so in order for linting to work in the open
44
38
  // source repo, we need to just use `ReactDOM.form`.
45
- return this.transferPropsTo(form(null, this.props.children));
39
+ return form(this.props);
46
40
  },
47
41
 
48
42
  componentDidMount: function() {
@@ -1,17 +1,10 @@
1
1
  /**
2
- * Copyright 2013-2014 Facebook, Inc.
2
+ * Copyright 2013-2014, Facebook, Inc.
3
+ * All rights reserved.
3
4
  *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
15
8
  *
16
9
  * @providesModule ReactDOMIDOperations
17
10
  * @typechecks static-only
@@ -1,17 +1,10 @@
1
1
  /**
2
- * Copyright 2013-2014 Facebook, Inc.
2
+ * Copyright 2013-2014, Facebook, Inc.
3
+ * All rights reserved.
3
4
  *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
15
8
  *
16
9
  * @providesModule ReactDOMImg
17
10
  */
@@ -22,10 +15,11 @@ var EventConstants = require("./EventConstants");
22
15
  var LocalEventTrapMixin = require("./LocalEventTrapMixin");
23
16
  var ReactBrowserComponentMixin = require("./ReactBrowserComponentMixin");
24
17
  var ReactCompositeComponent = require("./ReactCompositeComponent");
18
+ var ReactElement = require("./ReactElement");
25
19
  var ReactDOM = require("./ReactDOM");
26
20
 
27
- // Store a reference to the <img> `ReactDOMComponent`.
28
- var img = ReactDOM.img;
21
+ // Store a reference to the <img> `ReactDOMComponent`. TODO: use string
22
+ var img = ReactElement.createFactory(ReactDOM.img.type);
29
23
 
30
24
  /**
31
25
  * Since onLoad doesn't bubble OR capture on the top level in IE8, we need to
@@ -1,17 +1,10 @@
1
1
  /**
2
- * Copyright 2013-2014 Facebook, Inc.
2
+ * Copyright 2013-2014, Facebook, Inc.
3
+ * All rights reserved.
3
4
  *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
15
8
  *
16
9
  * @providesModule ReactDOMInput
17
10
  */
@@ -23,17 +16,26 @@ var DOMPropertyOperations = require("./DOMPropertyOperations");
23
16
  var LinkedValueUtils = require("./LinkedValueUtils");
24
17
  var ReactBrowserComponentMixin = require("./ReactBrowserComponentMixin");
25
18
  var ReactCompositeComponent = require("./ReactCompositeComponent");
19
+ var ReactElement = require("./ReactElement");
26
20
  var ReactDOM = require("./ReactDOM");
27
21
  var ReactMount = require("./ReactMount");
22
+ var ReactUpdates = require("./ReactUpdates");
28
23
 
24
+ var assign = require("./Object.assign");
29
25
  var invariant = require("./invariant");
30
- var merge = require("./merge");
31
26
 
32
- // Store a reference to the <input> `ReactDOMComponent`.
33
- var input = ReactDOM.input;
27
+ // Store a reference to the <input> `ReactDOMComponent`. TODO: use string
28
+ var input = ReactElement.createFactory(ReactDOM.input.type);
34
29
 
35
30
  var instancesByReactID = {};
36
31
 
32
+ function forceUpdateIfMounted() {
33
+ /*jshint validthis:true */
34
+ if (this.isMounted()) {
35
+ this.forceUpdate();
36
+ }
37
+ }
38
+
37
39
  /**
38
40
  * Implements an <input> native component that allows setting these optional
39
41
  * props: `checked`, `value`, `defaultChecked`, and `defaultValue`.
@@ -58,28 +60,23 @@ var ReactDOMInput = ReactCompositeComponent.createClass({
58
60
  getInitialState: function() {
59
61
  var defaultValue = this.props.defaultValue;
60
62
  return {
61
- checked: this.props.defaultChecked || false,
62
- value: defaultValue != null ? defaultValue : null
63
+ initialChecked: this.props.defaultChecked || false,
64
+ initialValue: defaultValue != null ? defaultValue : null
63
65
  };
64
66
  },
65
67
 
66
- shouldComponentUpdate: function() {
67
- // Defer any updates to this component during the `onChange` handler.
68
- return !this._isChanging;
69
- },
70
-
71
68
  render: function() {
72
69
  // Clone `this.props` so we don't mutate the input.
73
- var props = merge(this.props);
70
+ var props = assign({}, this.props);
74
71
 
75
72
  props.defaultChecked = null;
76
73
  props.defaultValue = null;
77
74
 
78
75
  var value = LinkedValueUtils.getValue(this);
79
- props.value = value != null ? value : this.state.value;
76
+ props.value = value != null ? value : this.state.initialValue;
80
77
 
81
78
  var checked = LinkedValueUtils.getChecked(this);
82
- props.checked = checked != null ? checked : this.state.checked;
79
+ props.checked = checked != null ? checked : this.state.initialChecked;
83
80
 
84
81
  props.onChange = this._handleChange;
85
82
 
@@ -119,14 +116,12 @@ var ReactDOMInput = ReactCompositeComponent.createClass({
119
116
  var returnValue;
120
117
  var onChange = LinkedValueUtils.getOnChange(this);
121
118
  if (onChange) {
122
- this._isChanging = true;
123
119
  returnValue = onChange.call(this, event);
124
- this._isChanging = false;
125
120
  }
126
- this.setState({
127
- checked: event.target.checked,
128
- value: event.target.value
129
- });
121
+ // Here we use asap to wait until all updates have propagated, which
122
+ // is important when using controlled components within layers:
123
+ // https://github.com/facebook/react/issues/1698
124
+ ReactUpdates.asap(forceUpdateIfMounted, this);
130
125
 
131
126
  var name = this.props.name;
132
127
  if (this.props.type === 'radio' && name != null) {
@@ -164,13 +159,10 @@ var ReactDOMInput = ReactCompositeComponent.createClass({
164
159
  'ReactDOMInput: Unknown radio button ID %s.',
165
160
  otherID
166
161
  ) : invariant(otherInstance));
167
- // In some cases, this will actually change the `checked` state value.
168
- // In other cases, there's no change but this forces a reconcile upon
169
- // which componentDidUpdate will reset the DOM property to whatever it
170
- // should be.
171
- otherInstance.setState({
172
- checked: false
173
- });
162
+ // If this is a controlled radio button group, forcing the input that
163
+ // was previously checked to update will cause it to be come re-checked
164
+ // as appropriate.
165
+ ReactUpdates.asap(forceUpdateIfMounted, otherInstance);
174
166
  }
175
167
  }
176
168