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