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
package/README.md CHANGED
@@ -1,227 +1,25 @@
1
- # React.js
1
+ # react
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/jeffbski/react.png?branch=master)](http://travis-ci.org/jeffbski/react)
3
+ An npm package to get you immediate access to [React](http://facebook.github.io/react/),
4
+ without also requiring the JSX transformer. This is especially useful for cases where you
5
+ want to [`browserify`](https://github.com/substack/node-browserify) your module using
6
+ `React`.
4
7
 
5
- React is a javascript module to make it easier to work with asynchronous code, by reducing boilerplate code and improving error and exception handling while allowing variable and task dependencies when defining flow. This project is applying the concepts of Reactive programming or Dataflow to controlling application flow.
8
+ ## The `react` npm package has recently changed!
6
9
 
7
- This async flow control module is initially designed to work with Node.js but is planned to be extended to browser and other environments.
10
+ If you're looking for jeffbski's [React.js](https://github.com/jeffbski/react) project, it's now in `npm` as `autoflow` rather than `react`.
8
11
 
9
- React gets its name from similarities with how "chain reactions" work in the physical world. You start the reaction and then it cascades and continues until complete.
12
+ ## Example Usage
10
13
 
11
- Also "Reactive Programming" or "Dataflow" describe defining flow which reacts to the data similar to how a spreadsheet updates cells. These are good examples of how React controls flow based on when data is available
14
+ ```js
12
15
 
13
- - Reactive programming - <http://en.wikipedia.org/wiki/Reactive_programming>
14
- - Dataflow programming - <http://en.wikipedia.org/wiki/Dataflow>
15
- - Dataflow Programming: Handling Huge Data Loads Without Adding Complexity (Dr. Dobb's Sept 19, 2011) - <http://drdobbs.com/database/231400148>
16
+ // Previously, you might access React with react-tools.
17
+ var React = require('react-tools').React;
16
18
 
17
- It takes inspiration from several projects including:
19
+ // Now you can access React directly with react-core.
20
+ var React = require('react');
18
21
 
19
- - Tim Caswell and Elijah Insua's [conductor](https://github.com/creationix/conductor) - [Article](http://howtonode.org/step-of-conductor)
20
- - Caolan McMahon's [async](https://github.com/caolan/async)
21
-
22
-
23
- ## Goals
24
-
25
- - Minimize boilerplate code needed for working with asynchronous functions
26
- - Minimize the need to customize your code simply to use async flow control. The use of a flow control module ideally should not affect the way you write your code, it should only help take over some of the burden.
27
- - Improved error and exception handling
28
- - Provide useful stack traces and context information for easier debugging
29
- - Make code more readable and easier to understand which should translate to less defects
30
- - Provide the right level of abstraction to make it easier to refactor code, without being too magical
31
- - Allow the mixing of pure functions, method calls, and callback style functions in the flow
32
-
33
- ## Supports
34
-
35
- - async node-style callback(err, arg...) functions
36
- - sync functions which directly return value
37
- - object instance method calls
38
- - class method calls
39
- - selectFirst flow where the first task that returns defined, non-null value is used
40
- - promise style functions - also automatic resolution of promise inputs (optionally loaded with `react.resolvePromises();`)
41
- - use of resulting flow function as callback style or promise style (if no callback provided) (provided via plugin corresponding to the promise library used) See https://github.com/jeffbski/react-deferred
42
- - (planned) iteration on arrays, streams, sockets
43
- - (planned) event emitter integration
44
-
45
- The tasks can be mixed, meaning you can use async, sync, object method calls, class method calls, etc in the same flow.
46
-
47
- ## Concept
48
-
49
- Borrowing heavily from Tim and Elijah's ideas for conductor, this async flow control module provides a way to construct a flow from a
50
- collection of rules based on functions or methods (referred to as _tasks_ in this module). It allows dependencies to be defined between the tasks so they can run in parallel as their dependencies are satisfied. React can us both variable dependencies and task dependencies.
51
-
52
- As tasks complete, React watches the dependencies and kicks off additional tasks that have all their dependencies met and are ready to execute. This allows the flow to run at maximum speed without needing to arbitrarily block tasks into groups of parallel and serial flow.
53
-
54
- To reduce the boilerplate code needed and improve error handling, React automatically provides callback functions for your asynchronous code. These React-provided callback functions perform these steps:
55
-
56
- 1. check for error and handle by calling outer callback function with this error after augmenting it with additional context information for easier debugging
57
- 2. save the callback variables into a context for future reference
58
- 3. call back into React (and it will kick off additional tasks that are now ready to go)
59
- 4. Using the dependencies specified for each
60
-
61
- ## Design
62
-
63
- - Parse and validate DSL rules at module load time creating AST
64
- - Validate the flow AST at module load time - determine if dependencies can all be met as defined
65
- - Execute the flow AST by calling the function with arguments
66
-
67
- ## Installing
68
-
69
- npm install react
70
-
71
- OR
72
-
73
- Pull from github - http://github.com/jeffbski/react
74
-
75
- ## Examples
76
-
77
- <a name="defaultDSL"/>
78
- ### Example using default DSL interface
79
-
80
- - Simple example showing flow definition of two async functions feeding a
81
- synchronous function.
82
-
83
- - First two async functions inputs are satisfied by the flow inputs, so
84
- they will both run immediately in parallel.
85
-
86
- - The last function waits for the outputs of the previous ones, then
87
- executes synchronously.
88
-
89
- - Finally the flow calls the callback with the output values once all
90
- the tasks have completed.
91
-
92
- ```javascript
93
- // in your foobar module
94
- var react = require('react');
95
-
96
- // some normal async and sync functions
97
- function loadFoo(fooPath, cb) {
98
- setTimeout(function () {
99
- cb(null, [fooPath, 'data'].join(':'));
100
- }, 10);
101
- }
102
-
103
- function loadBar(barPath, barP2, cb) {
104
- setTimeout(function () {
105
- cb(null, [barPath, barP2, 'data'].join(':'));
106
- }, 10);
107
- }
108
-
109
- function render(foo, bar) {
110
- return ['<html>', foo, '/', bar, '</html>'].join('');
111
- }
112
-
113
- // define fn, glue together with react, it will parallelize
114
- // starts with name and in/out params, then the tasks
115
- var loadRender = react('loadRender', 'fooPath, barPath, barP2, cb -> err, renderedOut',
116
- loadFoo, 'fooPath, cb -> err, foo', // async cb function
117
- loadBar, 'barPath, barP2, cb -> err, bar', // async cb function
118
- render, 'foo, bar -> renderedOut' // sync function using outputs from first two
119
- );
120
-
121
- exports.loadRender = loadRender; // is a normal fn created by react
122
-
123
-
124
- // in a different module far far away, use this as any other node function
125
- var foobar = require('foobar');
126
- foobar.loadRender('foo.txt', 'bar.txt', 'BBB', function (err, renderedOut) {
127
- // tasks in loadRender were parallelized based on their input dependencies
128
- console.error('results:', renderedOut);
129
- });
130
- ```
131
-
132
- Below is a graph of how the dependencies are mapped by React which
133
- also indicates how the tasks will be executed. This was generated by the
134
- react plugin [react-graphviz](https://github.com/jeffbski/react-graphviz)
135
- which you can use to also graph your flows.
136
-
137
- ![simple.png](https://github.com/jeffbski/react/raw/master/doc/simple.png)
138
-
139
-
140
-
141
- ## User API
142
-
143
- The main function returned from require('react') can be used to define the AST used for the processing of the rules or flow.
144
-
145
- It takes the following arguments to define a flow function:
146
-
147
- ```javascript
148
- var fn = react('loadRender', 'fooPath, barPath, barP2, cb -> err, renderedOut',
149
- loadFoo, 'fooPath, cb -> err, foo',
150
- loadBar, 'barPath, barP2, cb -> err, bar',
151
- render, 'foo, bar -> renderedOut'
152
- );
22
+ // You can also access ReactWithAddons.
23
+ var React = require('react/addons');
153
24
  ```
154
25
 
155
- ![color-def](https://github.com/jeffbski/react/raw/master/doc/color-def.png)
156
-
157
- 1. **flow/function name** - string - represents the name of the flow or function that will be created. React will use the name when generating events so you can monitor progress and performance and also when errors occur.
158
- 2. **in/out flow parameter definition** - string - the inputs and outputs for the flow function. The parameters are specified in one single string for easy typing, separated by commas. The output follows the input after being separated by a `->`. Use the parameter name `cb` or `callback` to specify the Node style callback and `err` to represent the error parameter as the first output parameter of the callback. Literal values can also be specified directly (true, false, numbers, this, null). Literal strings can simply be quoted using single or double quotes.
159
- 3. **optional flow options** - object - If an object is provided immediately after the in/out flow def, then these options will be provided to react to customize the flow. This is reserved for future use.
160
- 4. **function reference or method string** - Specify the function to be called for this task, or if calling a method off of an object being passed in or returned by a task, use a string to specify like `'obj.method'`. These can be asynchronous Node-style callback `cb(err, ...)` functions or synchronous functions which simply return values directly.
161
- 5. **in/out task parameter definition** - string - similar to the in/out flow parameter definition above, these are the inputs and outputs that are passed to a task function and returned from a task function. The inputs will need to match either those from the flow inputs or outputs from other tasks that will run before this task. React will use the inputs as dependencies, so it will invoke and wait for response from the tasks that provide the dependent inputs. So simply by specifying inputs and outputs for the tasks, React will prioritize and parallelize tasks to run as fast as possible. Use `cb` or `callback` along with `err` to specify asynchronous Node style `cb(err, ...)` task, or omit both to specify a synchronous task.A synchronous task can only have a single return parameter.
162
- 6. **optional task options** - object - if an object is provided this can be used to specify additional options for this task. Currently the valid options for a task are:
163
- - **name** - string - specifies a name for a task, otherwise React will try to use the function name or method string if it is unique in the flow. If a name is not unique subsequent tasks will have `_index` (zero based index of the task) added to create unique name. If you specify a name, you will also want to indicate a unique name for within the flow otherwise it will get a suffix as well. Example: `{ name: 'myTaskName' }`
164
- - **after** - string, function reference, or array of string or function refs - specify additional preconditions that need to be complete before this task can run. In addition to the input dependencies being met, wait for these named tasks to complete before running. The preconditions are specified using the name of the task or if the task function was only used once and is a named function (not anonymous), you can just provide the function reference and it will determine name from it. Example: `{ after: 'foo' }` or `{ after: ['foo', 'bar'] }`
165
- 7. **repeat 4-6** - repeat steps 4-6 to specify additional tasks in this flow. As dependencies are met for tasks, React will invoke additional tasks that are ready to run in the order they are defined in this flow definition. So while the order does have some influence on the execution, it is primarily defined by the input dependencies and any other additonal preconditions specified with the `after` option. If you want to guarantee that something only runs after something else completes, then it will need to use an output from that task or specify the dependency with an `after`.
166
-
167
-
168
- The flow function created by react from the input definition is a normal Node-style function which can be used like any other. These flow functions can be defined in a module and exported, they can be passed into other functions, used as methods on objects (the `this` context is passed in and available).
169
-
170
- ### Debugging React
171
-
172
- React has a built-in plugin which can be loaded that will enable logging of tasks and flow as it executes very useful for debugging. For full details see [Advanced React - LogEvents](https://github.com/jeffbski/react/blob/master/doc/advanced.md#LogEvents) along with the other plugins and an explanation of the AST React uses.
173
-
174
- ```javascript
175
- var react = require('react');
176
- react.logEvents(); // turn on flow and task logging for all react functions
177
- ```
178
-
179
- ### Advanced React
180
-
181
- React has many additional plugins and features which enable logging, monitoring, promise resolution, etc.
182
-
183
- See the [Advanced React](https://github.com/jeffbski/react/blob/master/doc/advanced.md) for details on the AST React uses for processing and other plugins that are available.
184
-
185
-
186
-
187
- ## Status
188
-
189
- - 2012-09-12 - Upgrade RequireJS@2.0.6, mocha@1.4.2, chai@1.2.0, jake@0.3.16. Update travis config to include Node 0.8 (v0.6.2)
190
- - 2012-04-25 - Browser compatibility issue with process check, (v0.6.1)
191
- - 2012-04-05 - Remove dependency on sprint, use util.format
192
- - 2012-03-28 - Make react AMD-enabled and compatible with ES5 browsers and node.js, provide single file dist and min, add browser tests (v0.6.0)
193
- - 2012-03-24 - Add Travis-CI, remove promised-io since failing to install in travis-ci for node 0.6/0.7, switch from tap to mocha/chai
194
- - 2012-03-12 - Pass ast.define events to process (v0.5.2)
195
- - 2012-01-18 - Remove old DSL interfaces, improve plugin loading, log flow name with task name, ast.defined event, test with node 0.7.0 (v0.5.1)
196
- - 2012-01-17 - Additional documentation (v0.3.5)
197
- - 2012-01-16 - Refine events and create logging plugin (v0.3.3)
198
- - 2012-01-13 - Add promise tasks, promise resolution, refactor alternate DSL interfaces as optional requires (v0.3.0)
199
- - 2012-01-11 - Provide warning/error when name is skipped in default DSL, literal check in validate (v0.2.5)
200
- - 2012-01-10 - Create default DSL for react(), create error for missing variables, list remaining tasks when flow won't complete
201
- - 2011-12-21 - Refactor from ground up with tests, changes to the interfaces
202
- - 2011-10-26 - React is in active development and interface may change frequently in these early stages. Current code is functional but does not perform validation yet. Additional interfaces are planned to make it easy to define flows in a variety of ways. Documentation and examples forthcoming.
203
-
204
- ## Test Results
205
-
206
- [![Build Status](https://secure.travis-ci.org/jeffbski/react.png?branch=master)](http://travis-ci.org/jeffbski/react)
207
-
208
- ```bash
209
- mocha
210
-
211
- 178 tests complete
212
- ```
213
-
214
- ## License
215
-
216
- - [MIT license](http://github.com/jeffbski/react/raw/master/LICENSE)
217
-
218
- ## Contributors
219
-
220
- - Author: Jeff Barczewski (@jeffbski)
221
-
222
- ## Contributing
223
-
224
- - Source code repository: http://github.com/jeffbski/react
225
- - Ideas and pull requests are encouraged - http://github.com/jeffbski/react/issues
226
-
227
- - You may contact me at @jeffbski or through github at http://github.com/jeffbski
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ var copyProperties = require('./lib/copyProperties');
4
+
5
+ var WARNING_MESSAGE = (
6
+ 'It looks like you\'re trying to use jeffbski\'s React.js project.\n' +
7
+ 'The `react` npm package now points to the React JavaScript library for ' +
8
+ 'building user interfaces, not the React.js project for managing asynchronous ' +
9
+ 'control flow. If you\'re looking for that library, please npm install autoflow.'
10
+ );
11
+
12
+ function error() {
13
+ throw new Error(WARNING_MESSAGE);
14
+ }
15
+
16
+ // Model the React.js project's public interface exactly.
17
+
18
+ function ReactJSShim() {
19
+ error();
20
+ }
21
+
22
+ ReactJSShim.logEvents = error;
23
+ ReactJSShim.resolvePromises = error;
24
+ ReactJSShim.trackTasks = error;
25
+ ReactJSShim.createEventCollector = error;
26
+
27
+ // These could throw using defineProperty() but supporting older browsers will
28
+ // be painful. Additionally any error messages around this will contain the string
29
+ // so I think this is sufficient.
30
+ ReactJSShim.options = WARNING_MESSAGE;
31
+ ReactJSShim.events = WARNING_MESSAGE;
32
+
33
+ var ReactJSErrors = {
34
+ wrap: function(module) {
35
+ copyProperties(ReactJSShim, module);
36
+ return ReactJSShim;
37
+ }
38
+ };
39
+
40
+ module.exports = ReactJSErrors;
package/addons.js ADDED
@@ -0,0 +1,4 @@
1
+ module.exports = require('./lib/ReactWithAddons');
2
+ if ('production' !== process.env.NODE_ENV) {
3
+ module.exports = require('./ReactJSErrors').wrap(module.exports);
4
+ }
package/lib/$.js ADDED
@@ -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 $
17
+ * @typechecks
18
+ */
19
+
20
+ var ge = require("./ge");
21
+ var ex = require("./ex");
22
+
23
+ /**
24
+ * Find a node by ID.
25
+ *
26
+ * If your application code depends on the existence of the element, use $,
27
+ * which will throw if the element doesn't exist.
28
+ *
29
+ * If you're not sure whether or not the element exists, use ge instead, and
30
+ * manually check for the element's existence in your application code.
31
+ *
32
+ * @param {string|DOMDocument|DOMElement|DOMTextNode|Comment} id
33
+ * @return {DOMDocument|DOMElement|DOMTextNode|Comment}
34
+ */
35
+ function $(id) {
36
+ var element = ge(id);
37
+ if (!element) {
38
+ throw new Error(ex(
39
+ 'Tried to get element with id of "%s" but it is not present on the page.',
40
+ id
41
+ ));
42
+ }
43
+ return element;
44
+ }
45
+
46
+ module.exports = $;
package/lib/CSSCore.js ADDED
@@ -0,0 +1,114 @@
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 CSSCore
17
+ * @typechecks
18
+ */
19
+
20
+ var invariant = require("./invariant");
21
+
22
+ /**
23
+ * The CSSCore module specifies the API (and implements most of the methods)
24
+ * that should be used when dealing with the display of elements (via their
25
+ * CSS classes and visibility on screeni. It is an API focused on mutating the
26
+ * display and not reading it as no logical state should be encoded in the
27
+ * display of elements.
28
+ */
29
+
30
+ /**
31
+ * Tests whether the element has the class specified.
32
+ *
33
+ * Note: This function is not exported in CSSCore because CSS classNames should
34
+ * not store any logical information about the element. Use DataStore to store
35
+ * information on an element.
36
+ *
37
+ * @param {DOMElement} element the element to set the class on
38
+ * @param {string} className the CSS className
39
+ * @returns {boolean} true if the element has the class, false if not
40
+ */
41
+ function hasClass(element, className) {
42
+ if (element.classList) {
43
+ return !!className && element.classList.contains(className);
44
+ }
45
+ return (' ' + element.className + ' ').indexOf(' ' + className + ' ') > -1;
46
+ }
47
+
48
+ var CSSCore = {
49
+
50
+ /**
51
+ * Adds the class passed in to the element if it doesn't already have it.
52
+ *
53
+ * @param {DOMElement} element the element to set the class on
54
+ * @param {string} className the CSS className
55
+ * @return {DOMElement} the element passed in
56
+ */
57
+ addClass: function(element, className) {
58
+ ("production" !== process.env.NODE_ENV ? invariant(
59
+ !/\s/.test(className),
60
+ 'CSSCore.addClass takes only a single class name. "%s" contains ' +
61
+ 'multiple classes.', className
62
+ ) : invariant(!/\s/.test(className)));
63
+
64
+ if (className) {
65
+ if (element.classList) {
66
+ element.classList.add(className);
67
+ } else if (!hasClass(element, className)) {
68
+ element.className = element.className + ' ' + className;
69
+ }
70
+ }
71
+ return element;
72
+ },
73
+
74
+ /**
75
+ * Removes the class passed in from the element
76
+ *
77
+ * @param {DOMElement} element the element to set the class on
78
+ * @param {string} className the CSS className
79
+ * @return {DOMElement} the element passed in
80
+ */
81
+ removeClass: function(element, className) {
82
+ ("production" !== process.env.NODE_ENV ? invariant(
83
+ !/\s/.test(className),
84
+ 'CSSCore.removeClass takes only a single class name. "%s" contains ' +
85
+ 'multiple classes.', className
86
+ ) : invariant(!/\s/.test(className)));
87
+
88
+ if (className) {
89
+ if (element.classList) {
90
+ element.classList.remove(className);
91
+ } else if (hasClass(element, className)) {
92
+ element.className = element.className
93
+ .replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)', 'g'), '$1')
94
+ .replace(/\s+/g, ' ') // multiple spaces to one
95
+ .replace(/^\s*|\s*$/g, ''); // trim the ends
96
+ }
97
+ }
98
+ return element;
99
+ },
100
+
101
+ /**
102
+ * Helper to add or remove a class from an element based on a condition.
103
+ *
104
+ * @param {DOMElement} element the element to set the class on
105
+ * @param {string} className the CSS className
106
+ * @param {*} bool condition to whether to add or remove the class
107
+ * @return {DOMElement} the element passed in
108
+ */
109
+ conditionClass: function(element, className, bool) {
110
+ return (bool ? CSSCore.addClass : CSSCore.removeClass)(element, className);
111
+ }
112
+ };
113
+
114
+ module.exports = CSSCore;