react 0.6.3 → 0.9.0-rc1

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