react 0.6.2 → 0.8.0

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 (204) hide show
  1. package/README.md +15 -217
  2. package/ReactJSErrors.js +40 -0
  3. package/addons.js +4 -0
  4. package/lib/$.js +46 -0
  5. package/lib/CSSCore.js +114 -0
  6. package/lib/CSSProperty.js +90 -0
  7. package/lib/CSSPropertyOperations.js +97 -0
  8. package/lib/CallbackRegistry.js +91 -0
  9. package/lib/ChangeEventPlugin.js +365 -0
  10. package/lib/CompositionEventPlugin.js +212 -0
  11. package/lib/DOMChildrenOperations.js +135 -0
  12. package/lib/DOMProperty.js +266 -0
  13. package/lib/DOMPropertyOperations.js +168 -0
  14. package/lib/Danger.js +186 -0
  15. package/lib/DefaultDOMPropertyConfig.js +187 -0
  16. package/lib/DefaultEventPluginOrder.js +44 -0
  17. package/lib/EnterLeaveEventPlugin.js +112 -0
  18. package/lib/EventConstants.js +73 -0
  19. package/lib/EventListener.js +61 -0
  20. package/lib/EventPluginHub.js +190 -0
  21. package/lib/EventPluginRegistry.js +237 -0
  22. package/lib/EventPluginUtils.js +185 -0
  23. package/lib/EventPropagators.js +179 -0
  24. package/lib/ExecutionEnvironment.js +41 -0
  25. package/lib/LinkedStateMixin.js +46 -0
  26. package/lib/LinkedValueMixin.js +68 -0
  27. package/lib/MobileSafariClickEventPlugin.js +63 -0
  28. package/lib/PooledClass.js +113 -0
  29. package/lib/React.js +71 -0
  30. package/lib/ReactChildren.js +132 -0
  31. package/lib/ReactComponent.js +515 -0
  32. package/lib/ReactComponentBrowserEnvironment.js +140 -0
  33. package/lib/ReactComponentEnvironment.js +24 -0
  34. package/lib/ReactCompositeComponent.js +1020 -0
  35. package/lib/ReactCurrentOwner.js +39 -0
  36. package/lib/ReactDOM.js +194 -0
  37. package/lib/ReactDOMButton.js +64 -0
  38. package/lib/ReactDOMComponent.js +374 -0
  39. package/lib/ReactDOMForm.js +52 -0
  40. package/lib/ReactDOMIDOperations.js +173 -0
  41. package/lib/ReactDOMInput.js +169 -0
  42. package/lib/ReactDOMOption.js +50 -0
  43. package/lib/ReactDOMSelect.js +160 -0
  44. package/lib/ReactDOMSelection.js +189 -0
  45. package/lib/ReactDOMTextarea.js +136 -0
  46. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  47. package/lib/ReactDefaultInjection.js +91 -0
  48. package/lib/ReactDefaultPerf.js +407 -0
  49. package/lib/ReactErrorUtils.js +46 -0
  50. package/lib/ReactEventEmitter.js +341 -0
  51. package/lib/ReactEventEmitterMixin.js +89 -0
  52. package/lib/ReactEventTopLevelCallback.js +89 -0
  53. package/lib/ReactInputSelection.js +140 -0
  54. package/lib/ReactInstanceHandles.js +322 -0
  55. package/lib/ReactLink.js +54 -0
  56. package/lib/ReactMarkupChecksum.js +53 -0
  57. package/lib/ReactMount.js +617 -0
  58. package/lib/ReactMountReady.js +95 -0
  59. package/lib/ReactMultiChild.js +441 -0
  60. package/lib/ReactMultiChildUpdateTypes.js +36 -0
  61. package/lib/ReactOwner.js +146 -0
  62. package/lib/ReactPerf.js +88 -0
  63. package/lib/ReactPropTransferer.js +128 -0
  64. package/lib/ReactPropTypes.js +158 -0
  65. package/lib/ReactReconcileTransaction.js +161 -0
  66. package/lib/ReactServerRendering.js +62 -0
  67. package/lib/ReactStateSetters.js +111 -0
  68. package/lib/ReactTextComponent.js +94 -0
  69. package/lib/ReactTransitionEvents.js +97 -0
  70. package/lib/ReactTransitionGroup.js +112 -0
  71. package/lib/ReactTransitionKeySet.js +111 -0
  72. package/lib/ReactTransitionableChild.js +152 -0
  73. package/lib/ReactUpdates.js +145 -0
  74. package/lib/ReactWithAddons.js +41 -0
  75. package/lib/SelectEventPlugin.js +217 -0
  76. package/lib/SimpleEventPlugin.js +365 -0
  77. package/lib/SyntheticClipboardEvent.js +45 -0
  78. package/lib/SyntheticCompositionEvent.js +51 -0
  79. package/lib/SyntheticEvent.js +163 -0
  80. package/lib/SyntheticFocusEvent.js +44 -0
  81. package/lib/SyntheticKeyboardEvent.js +56 -0
  82. package/lib/SyntheticMouseEvent.js +85 -0
  83. package/lib/SyntheticTouchEvent.js +50 -0
  84. package/lib/SyntheticUIEvent.js +45 -0
  85. package/lib/SyntheticWheelEvent.js +63 -0
  86. package/lib/Transaction.js +251 -0
  87. package/lib/ViewportMetrics.js +37 -0
  88. package/lib/accumulate.js +54 -0
  89. package/lib/adler32.js +39 -0
  90. package/lib/containsNode.js +49 -0
  91. package/lib/copyProperties.js +54 -0
  92. package/lib/createArrayFrom.js +94 -0
  93. package/lib/createNodesFromMarkup.js +93 -0
  94. package/lib/createObjectFrom.js +61 -0
  95. package/lib/cx.js +44 -0
  96. package/lib/dangerousStyleValue.js +57 -0
  97. package/lib/emptyFunction.js +43 -0
  98. package/lib/escapeTextForBrowser.js +47 -0
  99. package/lib/ex.js +49 -0
  100. package/lib/filterAttributes.js +45 -0
  101. package/lib/flattenChildren.js +54 -0
  102. package/lib/forEachAccumulated.js +36 -0
  103. package/lib/ge.js +76 -0
  104. package/lib/getActiveElement.js +33 -0
  105. package/lib/getEventTarget.js +36 -0
  106. package/lib/getMarkupWrap.js +108 -0
  107. package/lib/getNodeForCharacterOffset.js +80 -0
  108. package/lib/getReactRootElementInContainer.js +40 -0
  109. package/lib/getTextContentAccessor.js +40 -0
  110. package/lib/getUnboundedScrollPosition.js +45 -0
  111. package/lib/hyphenate.js +35 -0
  112. package/lib/invariant.js +54 -0
  113. package/lib/isEventSupported.js +74 -0
  114. package/lib/isNode.js +33 -0
  115. package/lib/isTextInputElement.js +49 -0
  116. package/lib/isTextNode.js +30 -0
  117. package/lib/joinClasses.js +44 -0
  118. package/lib/keyMirror.js +58 -0
  119. package/lib/keyOf.js +41 -0
  120. package/lib/memoizeStringOnly.js +39 -0
  121. package/lib/merge.js +37 -0
  122. package/lib/mergeHelpers.js +137 -0
  123. package/lib/mergeInto.js +45 -0
  124. package/lib/mixInto.js +34 -0
  125. package/lib/mutateHTMLNodeWithMarkup.js +100 -0
  126. package/lib/objMap.js +47 -0
  127. package/lib/objMapKeyVal.js +47 -0
  128. package/lib/performanceNow.js +42 -0
  129. package/lib/shallowEqual.js +49 -0
  130. package/lib/traverseAllChildren.js +127 -0
  131. package/package.json +33 -21
  132. package/react.js +4 -0
  133. package/.npmignore +0 -7
  134. package/.travis.yml +0 -5
  135. package/Jakefile.js +0 -39
  136. package/LICENSE +0 -19
  137. package/browser-test/dist.html +0 -89
  138. package/browser-test/index.html +0 -85
  139. package/browser-test/min.html +0 -89
  140. package/dist/react.js +0 -3094
  141. package/dist/react.min.js +0 -22
  142. package/doc/advanced.md +0 -166
  143. package/doc/color-def.graffle +0 -938
  144. package/doc/color-def.png +0 -0
  145. package/doc/simple.dot +0 -25
  146. package/doc/simple.png +0 -0
  147. package/examples/longer-example.js +0 -41
  148. package/examples/simple.js +0 -45
  149. package/examples/using-ast-directly.js +0 -30
  150. package/examples/using-events1.js +0 -79
  151. package/examples/using-log-events.js +0 -43
  152. package/lib/base-task.js +0 -123
  153. package/lib/cb-task.js +0 -84
  154. package/lib/core.js +0 -138
  155. package/lib/dsl.js +0 -138
  156. package/lib/error.js +0 -55
  157. package/lib/event-collector.js +0 -81
  158. package/lib/event-manager.js +0 -85
  159. package/lib/eventemitter.js +0 -20
  160. package/lib/finalcb-first-task.js +0 -68
  161. package/lib/finalcb-task.js +0 -65
  162. package/lib/id.js +0 -22
  163. package/lib/input-parser.js +0 -56
  164. package/lib/log-events.js +0 -92
  165. package/lib/parse.js +0 -41
  166. package/lib/promise-resolve.js +0 -50
  167. package/lib/promise-task.js +0 -93
  168. package/lib/react.js +0 -59
  169. package/lib/ret-task.js +0 -71
  170. package/lib/sprintf.js +0 -18
  171. package/lib/status.js +0 -14
  172. package/lib/task.js +0 -251
  173. package/lib/track-tasks.js +0 -74
  174. package/lib/validate.js +0 -159
  175. package/lib/vcon.js +0 -90
  176. package/lib/when-task.js +0 -85
  177. package/src/dist.build.requirejs +0 -20
  178. package/test/ast.mocha.js +0 -136
  179. package/test/cb-task.mocha.js +0 -220
  180. package/test/core-deferred.mocha.js +0 -143
  181. package/test/core-when.mocha.js +0 -96
  182. package/test/core.mocha.js +0 -589
  183. package/test/dsl.mocha.js +0 -350
  184. package/test/event-manager.mocha.js +0 -119
  185. package/test/exec-options.mocha.js +0 -48
  186. package/test/finalcb-task.mocha.js +0 -58
  187. package/test/input-parser.mocha.js +0 -86
  188. package/test/mocha.opts +0 -2
  189. package/test/module-use.mocha.js +0 -147
  190. package/test/promise-auto-resolve.mocha.js +0 -68
  191. package/test/ret-task.mocha.js +0 -220
  192. package/test/task.mocha.js +0 -42
  193. package/test/validate-cb-task.mocha.js +0 -100
  194. package/test/validate-ret-task.mocha.js +0 -110
  195. package/test/validate.mocha.js +0 -324
  196. package/test/vcon.mocha.js +0 -193
  197. package/vendor/chai/chai.js +0 -2038
  198. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  199. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  200. package/vendor/mocha/mocha.css +0 -135
  201. package/vendor/mocha/mocha.js +0 -3589
  202. package/vendor/node/util.js +0 -531
  203. package/vendor/requirejs/require.js +0 -2053
  204. package/vendor/requirejs/require.min.js +0 -33
@@ -0,0 +1,515 @@
1
+ /**
2
+ * Copyright 2013 Facebook, Inc.
3
+ *
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.
15
+ *
16
+ * @providesModule ReactComponent
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var ReactComponentEnvironment = require("./ReactComponentEnvironment");
22
+ var ReactCurrentOwner = require("./ReactCurrentOwner");
23
+ var ReactOwner = require("./ReactOwner");
24
+ var ReactUpdates = require("./ReactUpdates");
25
+
26
+ var invariant = require("./invariant");
27
+ var keyMirror = require("./keyMirror");
28
+ var merge = require("./merge");
29
+
30
+ /**
31
+ * Every React component is in one of these life cycles.
32
+ */
33
+ var ComponentLifeCycle = keyMirror({
34
+ /**
35
+ * Mounted components have a DOM node representation and are capable of
36
+ * receiving new props.
37
+ */
38
+ MOUNTED: null,
39
+ /**
40
+ * Unmounted components are inactive and cannot receive new props.
41
+ */
42
+ UNMOUNTED: null
43
+ });
44
+
45
+ /**
46
+ * Warn if there's no key explicitly set on dynamic arrays of children.
47
+ * This allows us to keep track of children between updates.
48
+ */
49
+
50
+ var ownerHasWarned = {};
51
+
52
+ /**
53
+ * Warn if the component doesn't have an explicit key assigned to it.
54
+ * This component is in an array. The array could grow and shrink or be
55
+ * reordered. All children, that hasn't already been validated, are required to
56
+ * have a "key" property assigned to it.
57
+ *
58
+ * @internal
59
+ * @param {ReactComponent} component Component that requires a key.
60
+ */
61
+ function validateExplicitKey(component) {
62
+ if (component.__keyValidated__ || component.props.key != null) {
63
+ return;
64
+ }
65
+ component.__keyValidated__ = true;
66
+
67
+ // We can't provide friendly warnings for top level components.
68
+ if (!ReactCurrentOwner.current) {
69
+ return;
70
+ }
71
+
72
+ // Name of the component whose render method tried to pass children.
73
+ var currentName = ReactCurrentOwner.current.constructor.displayName;
74
+ if (ownerHasWarned.hasOwnProperty(currentName)) {
75
+ return;
76
+ }
77
+ ownerHasWarned[currentName] = true;
78
+
79
+ var message = 'Each child in an array should have a unique "key" prop. ' +
80
+ 'Check the render method of ' + currentName + '.';
81
+ if (!component.isOwnedBy(ReactCurrentOwner.current)) {
82
+ // Name of the component that originally created this child.
83
+ var childOwnerName =
84
+ component.props.__owner__ &&
85
+ component.props.__owner__.constructor.displayName;
86
+
87
+ // Usually the current owner is the offender, but if it accepts
88
+ // children as a property, it may be the creator of the child that's
89
+ // responsible for assigning it a key.
90
+ message += ' It was passed a child from ' + childOwnerName + '.';
91
+ }
92
+
93
+ console.warn(message);
94
+ }
95
+
96
+ /**
97
+ * Ensure that every component either is passed in a static location or, if
98
+ * if it's passed in an array, has an explicit key property defined.
99
+ *
100
+ * @internal
101
+ * @param {*} component Statically passed child of any type.
102
+ * @return {boolean}
103
+ */
104
+ function validateChildKeys(component) {
105
+ if (Array.isArray(component)) {
106
+ for (var i = 0; i < component.length; i++) {
107
+ var child = component[i];
108
+ if (ReactComponent.isValidComponent(child)) {
109
+ validateExplicitKey(child);
110
+ }
111
+ }
112
+ } else if (ReactComponent.isValidComponent(component)) {
113
+ // This component was passed in a valid location.
114
+ component.__keyValidated__ = true;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Components are the basic units of composition in React.
120
+ *
121
+ * Every component accepts a set of keyed input parameters known as "props" that
122
+ * are initialized by the constructor. Once a component is mounted, the props
123
+ * can be mutated using `setProps` or `replaceProps`.
124
+ *
125
+ * Every component is capable of the following operations:
126
+ *
127
+ * `mountComponent`
128
+ * Initializes the component, renders markup, and registers event listeners.
129
+ *
130
+ * `receiveComponent`
131
+ * Updates the rendered DOM nodes to match the given component.
132
+ *
133
+ * `unmountComponent`
134
+ * Releases any resources allocated by this component.
135
+ *
136
+ * Components can also be "owned" by other components. Being owned by another
137
+ * component means being constructed by that component. This is different from
138
+ * being the child of a component, which means having a DOM representation that
139
+ * is a child of the DOM representation of that component.
140
+ *
141
+ * @class ReactComponent
142
+ */
143
+ var ReactComponent = {
144
+
145
+ /**
146
+ * @param {?object} object
147
+ * @return {boolean} True if `object` is a valid component.
148
+ * @final
149
+ */
150
+ isValidComponent: function(object) {
151
+ return !!(
152
+ object &&
153
+ typeof object.mountComponentIntoNode === 'function' &&
154
+ typeof object.receiveComponent === 'function'
155
+ );
156
+ },
157
+
158
+ /**
159
+ * Generate a key string that identifies a component within a set.
160
+ *
161
+ * @param {*} component A component that could contain a manual key.
162
+ * @param {number} index Index that is used if a manual key is not provided.
163
+ * @return {string}
164
+ * @internal
165
+ */
166
+ getKey: function(component, index) {
167
+ if (component && component.props && component.props.key != null) {
168
+ // Explicit key
169
+ return '{' + component.props.key + '}';
170
+ }
171
+ // Implicit key determined by the index in the set
172
+ return '[' + index + ']';
173
+ },
174
+
175
+ /**
176
+ * @internal
177
+ */
178
+ LifeCycle: ComponentLifeCycle,
179
+
180
+ /**
181
+ * Injected module that provides ability to mutate individual properties.
182
+ * Injected into the base class because many different subclasses need access
183
+ * to this.
184
+ *
185
+ * @internal
186
+ */
187
+ DOMIDOperations: ReactComponentEnvironment.DOMIDOperations,
188
+
189
+ /**
190
+ * Optionally injectable environment dependent cleanup hook. (server vs.
191
+ * browser etc). Example: A browser system caches DOM nodes based on component
192
+ * ID and must remove that cache entry when this instance is unmounted.
193
+ *
194
+ * @private
195
+ */
196
+ unmountIDFromEnvironment: ReactComponentEnvironment.unmountIDFromEnvironment,
197
+
198
+ /**
199
+ * The "image" of a component tree, is the platform specific (typically
200
+ * serialized) data that represents a tree of lower level UI building blocks.
201
+ * On the web, this "image" is HTML markup which describes a construction of
202
+ * low level `div` and `span` nodes. Other platforms may have different
203
+ * encoding of this "image". This must be injected.
204
+ *
205
+ * @private
206
+ */
207
+ mountImageIntoNode: ReactComponentEnvironment.mountImageIntoNode,
208
+
209
+ /**
210
+ * React references `ReactReconcileTransaction` using this property in order
211
+ * to allow dependency injection.
212
+ *
213
+ * @internal
214
+ */
215
+ ReactReconcileTransaction:
216
+ ReactComponentEnvironment.ReactReconcileTransaction,
217
+
218
+ /**
219
+ * Base functionality for every ReactComponent constructor. Mixed into the
220
+ * `ReactComponent` prototype, but exposed statically for easy access.
221
+ *
222
+ * @lends {ReactComponent.prototype}
223
+ */
224
+ Mixin: merge(ReactComponentEnvironment.Mixin, {
225
+
226
+ /**
227
+ * Checks whether or not this component is mounted.
228
+ *
229
+ * @return {boolean} True if mounted, false otherwise.
230
+ * @final
231
+ * @protected
232
+ */
233
+ isMounted: function() {
234
+ return this._lifeCycleState === ComponentLifeCycle.MOUNTED;
235
+ },
236
+
237
+ /**
238
+ * Sets a subset of the props.
239
+ *
240
+ * @param {object} partialProps Subset of the next props.
241
+ * @param {?function} callback Called after props are updated.
242
+ * @final
243
+ * @public
244
+ */
245
+ setProps: function(partialProps, callback) {
246
+ // Merge with `_pendingProps` if it exists, otherwise with existing props.
247
+ this.replaceProps(
248
+ merge(this._pendingProps || this.props, partialProps),
249
+ callback
250
+ );
251
+ },
252
+
253
+ /**
254
+ * Replaces all of the props.
255
+ *
256
+ * @param {object} props New props.
257
+ * @param {?function} callback Called after props are updated.
258
+ * @final
259
+ * @public
260
+ */
261
+ replaceProps: function(props, callback) {
262
+ ("production" !== process.env.NODE_ENV ? invariant(
263
+ !this.props.__owner__,
264
+ 'replaceProps(...): You called `setProps` or `replaceProps` on a ' +
265
+ 'component with an owner. This is an anti-pattern since props will ' +
266
+ 'get reactively updated when rendered. Instead, change the owner\'s ' +
267
+ '`render` method to pass the correct value as props to the component ' +
268
+ 'where it is created.'
269
+ ) : invariant(!this.props.__owner__));
270
+ ("production" !== process.env.NODE_ENV ? invariant(
271
+ this.isMounted(),
272
+ 'replaceProps(...): Can only update a mounted component.'
273
+ ) : invariant(this.isMounted()));
274
+ this._pendingProps = props;
275
+ ReactUpdates.enqueueUpdate(this, callback);
276
+ },
277
+
278
+ /**
279
+ * Base constructor for all React component.
280
+ *
281
+ * Subclasses that override this method should make sure to invoke
282
+ * `ReactComponent.Mixin.construct.call(this, ...)`.
283
+ *
284
+ * @param {?object} initialProps
285
+ * @param {*} children
286
+ * @internal
287
+ */
288
+ construct: function(initialProps, children) {
289
+ this.props = initialProps || {};
290
+ // Record the component responsible for creating this component.
291
+ this.props.__owner__ = ReactCurrentOwner.current;
292
+ // All components start unmounted.
293
+ this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
294
+
295
+ this._pendingProps = null;
296
+ this._pendingCallbacks = null;
297
+
298
+ // Children can be more than one argument
299
+ var childrenLength = arguments.length - 1;
300
+ if (childrenLength === 1) {
301
+ if ("production" !== process.env.NODE_ENV) {
302
+ validateChildKeys(children);
303
+ }
304
+ this.props.children = children;
305
+ } else if (childrenLength > 1) {
306
+ var childArray = Array(childrenLength);
307
+ for (var i = 0; i < childrenLength; i++) {
308
+ if ("production" !== process.env.NODE_ENV) {
309
+ validateChildKeys(arguments[i + 1]);
310
+ }
311
+ childArray[i] = arguments[i + 1];
312
+ }
313
+ this.props.children = childArray;
314
+ }
315
+ },
316
+
317
+ /**
318
+ * Initializes the component, renders markup, and registers event listeners.
319
+ *
320
+ * NOTE: This does not insert any nodes into the DOM.
321
+ *
322
+ * Subclasses that override this method should make sure to invoke
323
+ * `ReactComponent.Mixin.mountComponent.call(this, ...)`.
324
+ *
325
+ * @param {string} rootID DOM ID of the root node.
326
+ * @param {ReactReconcileTransaction} transaction
327
+ * @param {number} mountDepth number of components in the owner hierarchy.
328
+ * @return {?string} Rendered markup to be inserted into the DOM.
329
+ * @internal
330
+ */
331
+ mountComponent: function(rootID, transaction, mountDepth) {
332
+ ("production" !== process.env.NODE_ENV ? invariant(
333
+ !this.isMounted(),
334
+ 'mountComponent(%s, ...): Can only mount an unmounted component.',
335
+ rootID
336
+ ) : invariant(!this.isMounted()));
337
+ var props = this.props;
338
+ if (props.ref != null) {
339
+ ReactOwner.addComponentAsRefTo(this, props.ref, props.__owner__);
340
+ }
341
+ this._rootNodeID = rootID;
342
+ this._lifeCycleState = ComponentLifeCycle.MOUNTED;
343
+ this._mountDepth = mountDepth;
344
+ // Effectively: return '';
345
+ },
346
+
347
+ /**
348
+ * Releases any resources allocated by `mountComponent`.
349
+ *
350
+ * NOTE: This does not remove any nodes from the DOM.
351
+ *
352
+ * Subclasses that override this method should make sure to invoke
353
+ * `ReactComponent.Mixin.unmountComponent.call(this)`.
354
+ *
355
+ * @internal
356
+ */
357
+ unmountComponent: function() {
358
+ ("production" !== process.env.NODE_ENV ? invariant(
359
+ this.isMounted(),
360
+ 'unmountComponent(): Can only unmount a mounted component.'
361
+ ) : invariant(this.isMounted()));
362
+ var props = this.props;
363
+ if (props.ref != null) {
364
+ ReactOwner.removeComponentAsRefFrom(this, props.ref, props.__owner__);
365
+ }
366
+ ReactComponent.unmountIDFromEnvironment(this._rootNodeID);
367
+ this._rootNodeID = null;
368
+ this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
369
+ },
370
+
371
+ /**
372
+ * Given a new instance of this component, updates the rendered DOM nodes
373
+ * as if that instance was rendered instead.
374
+ *
375
+ * Subclasses that override this method should make sure to invoke
376
+ * `ReactComponent.Mixin.receiveComponent.call(this, ...)`.
377
+ *
378
+ * @param {object} nextComponent Next set of properties.
379
+ * @param {ReactReconcileTransaction} transaction
380
+ * @internal
381
+ */
382
+ receiveComponent: function(nextComponent, transaction) {
383
+ ("production" !== process.env.NODE_ENV ? invariant(
384
+ this.isMounted(),
385
+ 'receiveComponent(...): Can only update a mounted component.'
386
+ ) : invariant(this.isMounted()));
387
+ this._pendingProps = nextComponent.props;
388
+ this._performUpdateIfNecessary(transaction);
389
+ },
390
+
391
+ /**
392
+ * Call `_performUpdateIfNecessary` within a new transaction.
393
+ *
394
+ * @param {ReactReconcileTransaction} transaction
395
+ * @internal
396
+ */
397
+ performUpdateIfNecessary: function() {
398
+ var transaction = ReactComponent.ReactReconcileTransaction.getPooled();
399
+ transaction.perform(this._performUpdateIfNecessary, this, transaction);
400
+ ReactComponent.ReactReconcileTransaction.release(transaction);
401
+ },
402
+
403
+ /**
404
+ * If `_pendingProps` is set, update the component.
405
+ *
406
+ * @param {ReactReconcileTransaction} transaction
407
+ * @internal
408
+ */
409
+ _performUpdateIfNecessary: function(transaction) {
410
+ if (this._pendingProps == null) {
411
+ return;
412
+ }
413
+ var prevProps = this.props;
414
+ this.props = this._pendingProps;
415
+ this._pendingProps = null;
416
+ this.updateComponent(transaction, prevProps);
417
+ },
418
+
419
+ /**
420
+ * Updates the component's currently mounted representation.
421
+ *
422
+ * @param {ReactReconcileTransaction} transaction
423
+ * @param {object} prevProps
424
+ * @internal
425
+ */
426
+ updateComponent: function(transaction, prevProps) {
427
+ var props = this.props;
428
+ // If either the owner or a `ref` has changed, make sure the newest owner
429
+ // has stored a reference to `this`, and the previous owner (if different)
430
+ // has forgotten the reference to `this`.
431
+ if (props.__owner__ !== prevProps.__owner__ ||
432
+ props.ref !== prevProps.ref) {
433
+ if (prevProps.ref != null) {
434
+ ReactOwner.removeComponentAsRefFrom(
435
+ this, prevProps.ref, prevProps.__owner__
436
+ );
437
+ }
438
+ // Correct, even if the owner is the same, and only the ref has changed.
439
+ if (props.ref != null) {
440
+ ReactOwner.addComponentAsRefTo(this, props.ref, props.__owner__);
441
+ }
442
+ }
443
+ },
444
+
445
+ /**
446
+ * Mounts this component and inserts it into the DOM.
447
+ *
448
+ * @param {string} rootID DOM ID of the root node.
449
+ * @param {DOMElement} container DOM element to mount into.
450
+ * @param {boolean} shouldReuseMarkup If true, do not insert markup
451
+ * @final
452
+ * @internal
453
+ * @see {ReactMount.renderComponent}
454
+ */
455
+ mountComponentIntoNode: function(rootID, container, shouldReuseMarkup) {
456
+ var transaction = ReactComponent.ReactReconcileTransaction.getPooled();
457
+ transaction.perform(
458
+ this._mountComponentIntoNode,
459
+ this,
460
+ rootID,
461
+ container,
462
+ transaction,
463
+ shouldReuseMarkup
464
+ );
465
+ ReactComponent.ReactReconcileTransaction.release(transaction);
466
+ },
467
+
468
+ /**
469
+ * @param {string} rootID DOM ID of the root node.
470
+ * @param {DOMElement} container DOM element to mount into.
471
+ * @param {ReactReconcileTransaction} transaction
472
+ * @param {boolean} shouldReuseMarkup If true, do not insert markup
473
+ * @final
474
+ * @private
475
+ */
476
+ _mountComponentIntoNode: function(
477
+ rootID,
478
+ container,
479
+ transaction,
480
+ shouldReuseMarkup) {
481
+ var markup = this.mountComponent(rootID, transaction, 0);
482
+ ReactComponent.mountImageIntoNode(markup, container, shouldReuseMarkup);
483
+ },
484
+
485
+ /**
486
+ * Checks if this component is owned by the supplied `owner` component.
487
+ *
488
+ * @param {ReactComponent} owner Component to check.
489
+ * @return {boolean} True if `owners` owns this component.
490
+ * @final
491
+ * @internal
492
+ */
493
+ isOwnedBy: function(owner) {
494
+ return this.props.__owner__ === owner;
495
+ },
496
+
497
+ /**
498
+ * Gets another component, that shares the same owner as this one, by ref.
499
+ *
500
+ * @param {string} ref of a sibling Component.
501
+ * @return {?ReactComponent} the actual sibling Component.
502
+ * @final
503
+ * @internal
504
+ */
505
+ getSiblingByRef: function(ref) {
506
+ var owner = this.props.__owner__;
507
+ if (!owner || !owner.refs) {
508
+ return null;
509
+ }
510
+ return owner.refs[ref];
511
+ }
512
+ })
513
+ };
514
+
515
+ module.exports = ReactComponent;