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,41 @@
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 ExecutionEnvironment
17
+ */
18
+
19
+ /*jslint evil: true */
20
+
21
+ "use strict";
22
+
23
+ var canUseDOM = typeof window !== 'undefined';
24
+
25
+ /**
26
+ * Simple, lightweight module assisting with the detection and context of
27
+ * Worker. Helps avoid circular dependencies and allows code to reason about
28
+ * whether or not they are in a Worker, even if they never include the main
29
+ * `ReactWorker` dependency.
30
+ */
31
+ var ExecutionEnvironment = {
32
+
33
+ canUseDOM: canUseDOM,
34
+
35
+ canUseWorkers: typeof Worker !== 'undefined',
36
+
37
+ isInWorker: !canUseDOM // For now, this is true - might change in the future.
38
+
39
+ };
40
+
41
+ module.exports = ExecutionEnvironment;
@@ -0,0 +1,46 @@
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 LinkedStateMixin
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var ReactLink = require("./ReactLink");
23
+ var ReactStateSetters = require("./ReactStateSetters");
24
+
25
+ /**
26
+ * A simple mixin around ReactLink.forState().
27
+ */
28
+ var LinkedStateMixin = {
29
+ /**
30
+ * Create a ReactLink that's linked to part of this component's state. The
31
+ * ReactLink will have the current value of this.state[key] and will call
32
+ * setState() when a change is requested.
33
+ *
34
+ * @param {string} key state key to update. Note: you may want to use keyOf()
35
+ * if you're using Google Closure Compiler advanced mode.
36
+ * @return {ReactLink} ReactLink instance linking to the state.
37
+ */
38
+ linkState: function(key) {
39
+ return new ReactLink(
40
+ this.state[key],
41
+ ReactStateSetters.createStateKeySetter(this, key)
42
+ );
43
+ }
44
+ };
45
+
46
+ module.exports = LinkedStateMixin;
@@ -0,0 +1,68 @@
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 LinkedValueMixin
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var invariant = require("./invariant");
23
+
24
+ /**
25
+ * Provide a linked `value` attribute for controlled forms. You should not use
26
+ * this outside of the ReactDOM controlled form components.
27
+ */
28
+ var LinkedValueMixin = {
29
+ _assertLink: function() {
30
+ ("production" !== process.env.NODE_ENV ? invariant(
31
+ this.props.value == null && this.props.onChange == null,
32
+ 'Cannot provide a valueLink and a value or onChange event. If you ' +
33
+ 'want to use value or onChange, you probably don\'t want to use ' +
34
+ 'valueLink'
35
+ ) : invariant(this.props.value == null && this.props.onChange == null));
36
+ },
37
+
38
+ /**
39
+ * @return {*} current value of the input either from value prop or link.
40
+ */
41
+ getValue: function() {
42
+ if (this.props.valueLink) {
43
+ this._assertLink();
44
+ return this.props.valueLink.value;
45
+ }
46
+ return this.props.value;
47
+ },
48
+
49
+ /**
50
+ * @return {function} change callback either from onChange prop or link.
51
+ */
52
+ getOnChange: function() {
53
+ if (this.props.valueLink) {
54
+ this._assertLink();
55
+ return this._handleLinkedValueChange;
56
+ }
57
+ return this.props.onChange;
58
+ },
59
+
60
+ /**
61
+ * @param {SyntheticEvent} e change event to handle
62
+ */
63
+ _handleLinkedValueChange: function(e) {
64
+ this.props.valueLink.requestChange(e.target.value);
65
+ }
66
+ };
67
+
68
+ module.exports = LinkedValueMixin;
@@ -0,0 +1,63 @@
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 MobileSafariClickEventPlugin
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var EventConstants = require("./EventConstants");
23
+
24
+ var emptyFunction = require("./emptyFunction");
25
+
26
+ var topLevelTypes = EventConstants.topLevelTypes;
27
+
28
+ /**
29
+ * Mobile Safari does not fire properly bubble click events on non-interactive
30
+ * elements, which means delegated click listeners do not fire. The workaround
31
+ * for this bug involves attaching an empty click listener on the target node.
32
+ *
33
+ * This particular plugin works around the bug by attaching an empty click
34
+ * listener on `touchstart` (which does fire on every element).
35
+ */
36
+ var MobileSafariClickEventPlugin = {
37
+
38
+ eventTypes: null,
39
+
40
+ /**
41
+ * @param {string} topLevelType Record from `EventConstants`.
42
+ * @param {DOMEventTarget} topLevelTarget The listening component root node.
43
+ * @param {string} topLevelTargetID ID of `topLevelTarget`.
44
+ * @param {object} nativeEvent Native browser event.
45
+ * @return {*} An accumulation of synthetic events.
46
+ * @see {EventPluginHub.extractEvents}
47
+ */
48
+ extractEvents: function(
49
+ topLevelType,
50
+ topLevelTarget,
51
+ topLevelTargetID,
52
+ nativeEvent) {
53
+ if (topLevelType === topLevelTypes.topTouchStart) {
54
+ var target = nativeEvent.target;
55
+ if (target && !target.onclick) {
56
+ target.onclick = emptyFunction;
57
+ }
58
+ }
59
+ }
60
+
61
+ };
62
+
63
+ module.exports = MobileSafariClickEventPlugin;
@@ -0,0 +1,113 @@
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 PooledClass
17
+ */
18
+
19
+ "use strict";
20
+
21
+ /**
22
+ * Static poolers. Several custom versions for each potential number of
23
+ * arguments. A completely generic pooler is easy to implement, but would
24
+ * require accessing the `arguments` object. In each of these, `this` refers to
25
+ * the Class itself, not an instance. If any others are needed, simply add them
26
+ * here, or in their own files.
27
+ */
28
+ var oneArgumentPooler = function(copyFieldsFrom) {
29
+ var Klass = this;
30
+ if (Klass.instancePool.length) {
31
+ var instance = Klass.instancePool.pop();
32
+ Klass.call(instance, copyFieldsFrom);
33
+ return instance;
34
+ } else {
35
+ return new Klass(copyFieldsFrom);
36
+ }
37
+ };
38
+
39
+ var twoArgumentPooler = function(a1, a2) {
40
+ var Klass = this;
41
+ if (Klass.instancePool.length) {
42
+ var instance = Klass.instancePool.pop();
43
+ Klass.call(instance, a1, a2);
44
+ return instance;
45
+ } else {
46
+ return new Klass(a1, a2);
47
+ }
48
+ };
49
+
50
+ var threeArgumentPooler = function(a1, a2, a3) {
51
+ var Klass = this;
52
+ if (Klass.instancePool.length) {
53
+ var instance = Klass.instancePool.pop();
54
+ Klass.call(instance, a1, a2, a3);
55
+ return instance;
56
+ } else {
57
+ return new Klass(a1, a2, a3);
58
+ }
59
+ };
60
+
61
+ var fiveArgumentPooler = function(a1, a2, a3, a4, a5) {
62
+ var Klass = this;
63
+ if (Klass.instancePool.length) {
64
+ var instance = Klass.instancePool.pop();
65
+ Klass.call(instance, a1, a2, a3, a4, a5);
66
+ return instance;
67
+ } else {
68
+ return new Klass(a1, a2, a3, a4, a5);
69
+ }
70
+ };
71
+
72
+ var standardReleaser = function(instance) {
73
+ var Klass = this;
74
+ if (instance.destructor) {
75
+ instance.destructor();
76
+ }
77
+ if (Klass.instancePool.length < Klass.poolSize) {
78
+ Klass.instancePool.push(instance);
79
+ }
80
+ };
81
+
82
+ var DEFAULT_POOL_SIZE = 10;
83
+ var DEFAULT_POOLER = oneArgumentPooler;
84
+
85
+ /**
86
+ * Augments `CopyConstructor` to be a poolable class, augmenting only the class
87
+ * itself (statically) not adding any prototypical fields. Any CopyConstructor
88
+ * you give this may have a `poolSize` property, and will look for a
89
+ * prototypical `destructor` on instances (optional).
90
+ *
91
+ * @param {Function} CopyConstructor Constructor that can be used to reset.
92
+ * @param {Function} pooler Customizable pooler.
93
+ */
94
+ var addPoolingTo = function(CopyConstructor, pooler) {
95
+ var NewKlass = CopyConstructor;
96
+ NewKlass.instancePool = [];
97
+ NewKlass.getPooled = pooler || DEFAULT_POOLER;
98
+ if (!NewKlass.poolSize) {
99
+ NewKlass.poolSize = DEFAULT_POOL_SIZE;
100
+ }
101
+ NewKlass.release = standardReleaser;
102
+ return NewKlass;
103
+ };
104
+
105
+ var PooledClass = {
106
+ addPoolingTo: addPoolingTo,
107
+ oneArgumentPooler: oneArgumentPooler,
108
+ twoArgumentPooler: twoArgumentPooler,
109
+ threeArgumentPooler: threeArgumentPooler,
110
+ fiveArgumentPooler: fiveArgumentPooler
111
+ };
112
+
113
+ module.exports = PooledClass;
package/lib/React.js ADDED
@@ -0,0 +1,71 @@
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 React
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var ReactComponent = require("./ReactComponent");
22
+ var ReactCompositeComponent = require("./ReactCompositeComponent");
23
+ var ReactCurrentOwner = require("./ReactCurrentOwner");
24
+ var ReactDOM = require("./ReactDOM");
25
+ var ReactDOMComponent = require("./ReactDOMComponent");
26
+ var ReactDefaultInjection = require("./ReactDefaultInjection");
27
+ var ReactInstanceHandles = require("./ReactInstanceHandles");
28
+ var ReactMount = require("./ReactMount");
29
+ var ReactMultiChild = require("./ReactMultiChild");
30
+ var ReactPerf = require("./ReactPerf");
31
+ var ReactPropTypes = require("./ReactPropTypes");
32
+ var ReactServerRendering = require("./ReactServerRendering");
33
+ var ReactTextComponent = require("./ReactTextComponent");
34
+
35
+ ReactDefaultInjection.inject();
36
+
37
+ var React = {
38
+ DOM: ReactDOM,
39
+ PropTypes: ReactPropTypes,
40
+ initializeTouchEvents: function(shouldUseTouch) {
41
+ ReactMount.useTouchEvents = shouldUseTouch;
42
+ },
43
+ createClass: ReactCompositeComponent.createClass,
44
+ constructAndRenderComponent: ReactMount.constructAndRenderComponent,
45
+ constructAndRenderComponentByID: ReactMount.constructAndRenderComponentByID,
46
+ renderComponent: ReactPerf.measure(
47
+ 'React',
48
+ 'renderComponent',
49
+ ReactMount.renderComponent
50
+ ),
51
+ renderComponentToString: ReactServerRendering.renderComponentToString,
52
+ unmountComponentAtNode: ReactMount.unmountComponentAtNode,
53
+ unmountAndReleaseReactRootNode: ReactMount.unmountAndReleaseReactRootNode,
54
+ isValidClass: ReactCompositeComponent.isValidClass,
55
+ isValidComponent: ReactComponent.isValidComponent,
56
+ __internals: {
57
+ Component: ReactComponent,
58
+ CurrentOwner: ReactCurrentOwner,
59
+ DOMComponent: ReactDOMComponent,
60
+ InstanceHandles: ReactInstanceHandles,
61
+ Mount: ReactMount,
62
+ MultiChild: ReactMultiChild,
63
+ TextComponent: ReactTextComponent
64
+ }
65
+ };
66
+
67
+ // Version exists only in the open-source version of React, not in Facebook's
68
+ // internal version.
69
+ React.version = '0.8.0';
70
+
71
+ module.exports = React;
@@ -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;