Compare commits

..

839 Commits

Author SHA1 Message Date
Paul O’Shannessy
36796348f2 v15.0.0-rc.1 2016-03-07 17:02:10 -08:00
Paul O’Shannessy
e61e6dd4ed Revert "Change release to multi task"
This reverts commit c77f0b2fc5.
2016-03-07 17:02:10 -08:00
Paul O’Shannessy
340b344b20 Merge pull request #6201 from zpao/docs-babel-6
[docs] Upgrade to work with babel 6, fetch remote babel-browser for now
2016-03-07 11:43:26 -08:00
Paul O’Shannessy
dc93efaf11 Merge pull request #6200 from cpojer/master
Update to jest 0.9.0.
2016-03-07 10:46:22 -08:00
Paul O’Shannessy
56f8321559 [docs] Upgrade to work with babel 6, fetch remote babel-browser for now 2016-03-07 10:37:06 -08:00
Paul O’Shannessy
f3738d2cd0 Merge pull request #5781 from ara4n/master
support onLoad synthetic event attribute on 'object' tags
2016-03-06 18:57:37 -08:00
cpojer
626bb81241 Update to jest 0.9.0. 2016-03-06 17:35:53 -08:00
Jim
2b0f730081 Merge pull request #6199 from jquense/patch-4
Reset Jest to use Jasmine1 so tests pass again
2016-03-06 12:49:05 -08:00
Jason Quense
6a5866f286 Reset Jest to use Jasmine1 so Tests pass again
fixes #6198
2016-03-06 15:16:50 -05:00
Paul O’Shannessy
f430c47467 Merge pull request #6185 from zpao/fbjs-upgrade
Upgrade fbjs, fbjs-scripts
2016-03-06 12:12:48 -08:00
Jim
10f9476f3a Merge pull request #6121 from raineroviir/rainer
Fix #6114 - Calling setState inside getChildContext should warn
2016-03-05 08:24:39 -08:00
rainer oviir
9c1916dedb Fix #6114 - Calling setState inside getChildContext should warn 2016-03-04 23:20:29 -08:00
Jim
3b86cb10c4 Merge pull request #6177 from yuanyan/patch-1
Remove dead code.
2016-03-04 22:07:17 -08:00
Paul O’Shannessy
4e2a0d14a9 Upgrade fbjs, fbjs-scripts 2016-03-04 16:07:20 -08:00
Jim
1dc705aa0b Merge pull request #6180 from camjc/master
Update PureRenderMixin docs, adding ES6 example
2016-03-04 16:06:31 -08:00
Cameron Chamberlain
9fff1693f6 Update PureRenderMixin docs, adding ES6 example 2016-03-05 11:04:14 +11:00
Paul O’Shannessy
8b22a82162 Merge pull request #6189 from zpao/sythetic-events-fix
Fix issue with SyntheticEvents and Proxies
2016-03-04 14:25:14 -08:00
Paul O’Shannessy
f707ee53e2 Extend the correct object in the SyntheticEvent proxy 2016-03-04 13:59:51 -08:00
Jim
25c2bfcd52 Merge pull request #6183 from jimfb/rec-update
Fixed typo in reconciliation docs.
2016-03-04 13:13:23 -08:00
Dan Abramov
36798f7395 Merge pull request #6184 from gaearon/fix-svg-warning
Warn about deprecated SVG attributes only once
2016-03-04 18:14:35 +00:00
Jim
0ba1073e17 Fixed typo in reconciliation docs. 2016-03-04 10:01:35 -08:00
Dan Abramov
8a9ab75261 Warn about SVG attributes once
This fixes a missing check in #5714
2016-03-04 16:26:49 +00:00
Paul O’Shannessy
b89e7d25d5 Merge pull request #6175 from zpao/eslintrc-fixes
ESLint upgrade & fixes
2016-03-03 10:18:53 -08:00
Paul O’Shannessy
093bb22030 Update lint config, dependencies, fix issues
This also fixes messages from new synthetic events warnings
2016-03-03 10:16:02 -08:00
yuanyan
45a321d686 Remove dead code. 2016-03-03 23:08:47 +08:00
Paul O’Shannessy
b271efb7d3 Convert to .eslintrc.js 2016-03-02 23:52:20 -08:00
Jim
f8046f2dc2 Merge pull request #6172 from mgmcdermott/master
Fixed linting warnings and some mis-spacing in SyntheticEvent warnings
2016-03-02 18:54:27 -08:00
Michael McDermott
18af9bc91e Fixed some linting warnings and some mis-spacing in SyntheticEvent warnings. 2016-03-02 18:40:23 -05:00
Jim
09666ad486 Merge pull request #6159 from mxstbr/move-jsx-comment
Move no-jsx note in ReactElement tests
2016-03-02 11:00:20 -08:00
Dan Abramov
4bbd8d25e1 Merge pull request #6164 from gaearon/fix-svg
Don't set children attribute on SVG nodes
2016-03-02 11:02:50 +00:00
Dan Abramov
5eab1bbe29 Don't interpret reserved props as attributes for SVG elements
This fixes a bug introduced in #5714.
The code paths are now similar to web components where we worked around the same issue in #5093.

Additionally, we also skip dangerouslySetInnerHTML and suppressContentEditableWarning.
2016-03-02 02:48:57 +00:00
Max
32b0c62214 Copy and paste no-jsx note from top of file to places where it's used
Closes #6157
2016-03-01 20:06:20 +01:00
Jim
56c423afd6 Merge pull request #6152 from jimfb/fix-blog-code-fragment
Updated code fragment for correctness.
2016-02-29 21:03:18 -08:00
Paul O’Shannessy
4da7e7ef9c Merge pull request #6151 from zpao/docs-external-sidebar-followup
Docs external sidebar followup
2016-02-29 19:28:30 -08:00
jim
aec8a9b4fe Updated code fragment for correctness. 2016-02-29 17:52:43 -08:00
Paul O’Shannessy
e0442f6915 Add redirect layout (again) and use it 2016-02-29 16:48:09 -08:00
Paul O’Shannessy
ab6041bad6 Don't add class="" if we don't need to 2016-02-29 16:30:03 -08:00
Jim
8f2b7d8e71 Merge pull request #6090 from joecritch/docs-external-link-icon
[Docs] Added icon for external links in nav
2016-02-29 15:19:25 -08:00
Paul O’Shannessy
a026b35626 Merge pull request #6140 from NogsMPLS/removeBabelBrowser
[Docs] Remove babel-browser link
2016-02-29 10:03:21 -08:00
Paul O’Shannessy
730e5ac2e6 Merge pull request #6132 from chicoxyzzy/use_object_is_in_oneof_validate_method
Using Object.is implementation when compare values inside React.PropTypes.oneOf
2016-02-29 09:59:09 -08:00
chico
03925f4f06 Using Object.is implementation when compare values inside React.PropTypes.oneOf 2016-02-29 18:46:19 +03:00
Jim
4045747af6 Merge pull request #6141 from wikinee/master
Update 10.2-form-input-binding-sugar.zh-CN.md
2016-02-29 04:56:44 -08:00
Nee
132a291747 Update 10.2-form-input-binding-sugar.zh-CN.md
translation other English Party to Chinese.
2016-02-29 17:28:47 +08:00
Ben Alpert
96eb7ffdda Merge pull request #6139 from mxstbr/fix-rendertostaticmarkup-invariant
Fix renderToStaticMarkup() invariant
2016-02-28 22:27:02 -08:00
Nathan Smith
7dc8910373 remove babel-browser link 2016-02-28 18:03:05 -06:00
Max
4d1bfcc8e1 Fix renderToStaticMarkup invariant 2016-02-28 22:33:23 +01:00
Paul O’Shannessy
5696ccfcd7 Merge pull request #6005 from milesj/synthetic-transition
Added support for synthetic animation/transition events.
2016-02-28 11:09:30 -08:00
Paul O’Shannessy
adc9104d84 Merge pull request #6133 from stevenvachon/patch-1
support standard "cssFloat" css property
2016-02-28 10:59:49 -08:00
Steven Vachon
f68325f5d7 support standard "cssFloat" css property
For tools that compile CSS may have already converted the name.

More info:
https://npmjs.com/camelcase-css
https://npmjs.com/postcss-js
2016-02-27 01:13:15 -05:00
Paul O’Shannessy
5bb4303f9d Merge pull request #6113 from kittens/babel-6
Update to Babel 6
2016-02-26 18:36:55 -08:00
Sebastian McKenzie
1365498b81 Update to Babel 6 2016-02-26 16:49:32 -08:00
Dan Abramov
4c804361e0 Fix the lint issue introduced in #6129 2016-02-26 21:57:16 +00:00
Dan Abramov
1e5bb2e9e4 Merge pull request #6129 from gaearon/syranide-lessvpm
Disable ViewportMetrics unless MouseEvent lacks support for pageX/pageY
2016-02-26 20:56:38 +00:00
Andreas Svensson
471b4af2c8 Disable ViewportMetrics unless MouseEvent lacks support for pageX/pageY 2016-02-26 20:35:48 +00:00
Jim
13871886ba Merge pull request #6127 from jimfb/LinkedInput-to-packages
Moved LinkedInput from addons to packages.
2016-02-26 11:02:52 -08:00
Dan Abramov
92530b4ddc Merge pull request #6068 from gaearon/react-instrumentation
Add ReactInstrumentation
2016-02-26 17:18:19 +00:00
Ben Alpert
74070e5838 Merge pull request #6082 from spicyj/nq-set-props
Remove unused enqueueSetProps methods
2016-02-26 00:39:48 -08:00
Ben Alpert
5b13cbc0e8 Merge pull request #5877 from spicyj/mount-class-error
Clarify error when passing class to render()
2016-02-26 00:26:11 -08:00
Ben Alpert
895fab782b Clarify error when passing class to render() 2016-02-26 00:26:02 -08:00
Miles Johnson
260353e977 Added support for synthetic animation/transition events. 2016-02-25 23:52:32 -08:00
jim
8ab15c1d84 Moved LinkedInput from addons to packages. 2016-02-25 17:49:35 -08:00
Paul O’Shannessy
e2866ae412 Merge pull request #6123 from changhw01/patch-1
Clarify a step in the quick start
2016-02-25 14:52:25 -08:00
Huang-Wei Chang
040e94b7f5 Clarify a step in the quick start
I propose to add a sentence to indicate the page is ready, and the next step (Separate File) is optional. IMMO, the quick-start guide should be really short so that readers can see the result asap. Furthermore, the "Separate File" might not work for readers using Chrome anyway.
2016-02-25 13:17:07 -08:00
Jim
dff05beeff Merge pull request #5947 from koba04/add-warning-for-adding-synthetic-event-property
Add a warning for adding a property in the SyntheticEvent object
2016-02-24 13:30:49 -08:00
Jim
7a3009c2b4 Merge pull request #6112 from mxstbr/surpressContentEditableWarning
Add suppressContentEditableWarning
2016-02-24 13:02:12 -08:00
Max
f7276b304c Add suppressContentEditableWarning
See #5837
2016-02-24 20:41:07 +01:00
Jim
308badbc03 Merge pull request #6094 from AprilArcus/cite-attribute
add "cite" attribute to whitelist for <blockquote> elements
2016-02-24 11:15:37 -08:00
April Arcus
39c597f523 add "cite" attribute to whitelist for <blockquote> elements (fixes #6084) 2016-02-22 20:58:17 -08:00
Joe Critchley
8886cee285 Added icon for external links in Docs nav and unlinked Complementary Tools and Examples in favor of this icon 2016-02-23 02:18:20 +00:00
Jim
de09e0acd8 Merge pull request #6092 from dpercy/patch-2
Fix inverted definition of Controlled component
2016-02-22 15:59:20 -08:00
David Percy
8011112cc1 Fix inverted definition of Controlled component 2016-02-22 18:45:36 -05:00
Jim
fb75341769 Merge pull request #6085 from srph/patch-1
Add ReactLink deprecation notice
2016-02-22 14:49:01 -08:00
Paul O’Shannessy
5652c710c0 Merge pull request #6089 from chromakey/bb-fix-htmltojsx-script-link
Fix script source HTTPS error in html-jsx.md doc
2016-02-22 14:37:26 -08:00
Bill Blanchard
6ec8f078f1 Change script src for htmltojsx.min.js to referral target to fix https error 2016-02-22 16:20:23 -05:00
Kier Borromeo
01b3196896 Add deprecation notice. 2016-02-23 01:24:23 +08:00
Jim
5ebb784be5 Merge pull request #6071 from nakazye/fix_highlight
fix sample code highlight
2016-02-22 07:08:54 -08:00
nakazye
ccfd1ffb30 Replace the code sample in all the languages.
Replace the code sample in all the languages.

But I leave below sample code because of wording relation.

* tutorial6:see 25ef456
* from tutorial16:see 3812b95
2016-02-23 00:05:26 +09:00
Ben Alpert
cf4255445e Remove unused enqueueSetProps methods 2016-02-21 14:30:23 -08:00
Jim
70b5eda83e Merge pull request #5997 from truongduy134/clone-element
Fix #5929. Resolve to default props when config key is set to undefined in cloneElement
2016-02-19 14:53:38 -08:00
Sebastian Markbåge
dcc86b63dc Merge pull request #6074 from sebmarkbage/versionpost
Clarify what the current version scheme is
2016-02-19 12:02:57 -08:00
Sebastian Markbage
a080d863c5 Clarify what the current version scheme is
In case you don't remember what version we're currently on.

Also, clarify that this is semver and that v1.0 comes with preconceived
notions.
2016-02-19 12:02:26 -08:00
Ben Alpert
628a16c84d Hashrockets 2016-02-19 11:39:42 -08:00
Sebastian Markbåge
b3335f371f Merge pull request #6073 from sebmarkbage/versionpost
Versioning Blog Post
2016-02-19 11:34:01 -08:00
Sebastian Markbage
559fed7988 Versioning Blog Post 2016-02-19 11:31:01 -08:00
Ben Alpert
98d3327a5d Merge pull request #6070 from spicyj/server-text
Fix build for useCreateElement: false, run Travis
2016-02-19 09:48:37 -08:00
Ben Alpert
81e5dd0a29 Fix build for useCreateElement: false, run Travis
It's important that we keep these code paths working because they're the only comprehensive test of adopting server-rendered HTML that we have right now. This is terrible and hacky but I am hopeful that it will at least catch stuff.
2016-02-19 09:48:06 -08:00
Ben Alpert
e8fb8c7870 Fix text component rendering with server markup
These weren't caught by CI in #5753 because we don't automatically test that yet... fixing that next.
2016-02-19 09:48:05 -08:00
Dan Abramov
3863330524 Add ReactInstrumentation
This adds `ReactInstrumentation` for the isomorphic package that uses the same approach as `ReactDOMInstrumentation`. Currently it is gated behind `__DEV__` but we will likely change this later to a runtime flag determined by whether there are any active listeners.

The first few events we add here should be sufficient for React DevTools, as determined by the `hook.emit()` calls in d90c432016/backend/attachRenderer.js.

These events will also be useful for reconstructing the parent tree in the ReactPerf rewrite in #6046.
2016-02-18 22:52:22 +00:00
Ben Alpert
684ef3e320 Merge pull request #5753 from mwiencek/no-text-span-2
Don't wrap text in <span> elements
2016-02-18 12:02:17 -08:00
Paul O’Shannessy
f818fa38b4 [docs] Use consistent formatting for headers 2016-02-18 11:53:47 -08:00
Michael Wiencek
203850013a Don't wrap text in <span> elements
Instead, use opening and closing comment nodes to delimit text data.
2016-02-18 13:49:14 -06:00
Jim
5d7cd93b0e Merge pull request #6064 from jimfb/provide-msunsafe-wrapper
Create ms-unsafe functions in one place, simplifies code.
2016-02-18 11:14:47 -08:00
Jim
efa8624eb9 Merge pull request #6059 from jimfb/tutorial-children-callback
Clearify callback text in the tutorial
2016-02-18 11:14:24 -08:00
Toru Kobayashi
decff26e81 Add a warning for adding some properties in the SyntheticEvent object if Proxy is supported 2016-02-18 19:26:32 +09:00
Jim
6454bfb9de Merge pull request #6065 from benjycui/fix-comments
Update comments for EventPluginHub.js
2016-02-18 00:31:50 -08:00
Benjy Cui
c54249c868 Update comments for EventPluginHub.js 2016-02-18 16:23:00 +08:00
Jim
e8e56e8723 Merge pull request #5940 from kentcdodds/pr/warn-event-pool-access
Add warning when reading from event which has been returned to the pool
2016-02-17 21:51:40 -08:00
Kent C. Dodds
6312852688 warn(SyntheticEvent): Warn when accessing or setting properties on released syntheticEvents
Closes #5939
2016-02-17 22:46:12 -07:00
jim
51d16473b0 Create ms-unsafe functions in one place, simplifies code. 2016-02-17 21:10:20 -08:00
Jim
5879c9e1a4 Merge pull request #6063 from Andrew8xx8/master
Wrap insertBefore in Windows 8 apps
2016-02-17 20:28:27 -08:00
Andreww8xx8
8d08f3f00a Wrap insertBefore in Windows 8 apps 2016-02-18 06:12:29 +03:00
Ben Alpert
3a4e1dbb5b Fix merge conflict in #4940 2016-02-17 17:20:37 -08:00
jim
5ffd1db570 Clearify callback text in the tutorial 2016-02-17 16:30:11 -08:00
Ben Alpert
62e9531023 Merge pull request #4940 from spicyj/no-construct
Remove "construct" call except on composites
2016-02-17 15:53:25 -08:00
Ben Alpert
acb49363d5 Remove "construct" call except on composites
This is a little simpler (and a teeny tiny bit faster). The one in ReactCompositeComponent stays because of the way we create ReactCompositeComponentWrapper inside instantiateReactComponent.
2016-02-17 15:48:24 -08:00
Jim
c9e0fc766f Merge pull request #5720 from edmellum/master
Fix #4963 - SVG <use> swallows click events
2016-02-17 07:01:50 -08:00
David Ed Mellum
2fdaba49c7 Fix #4963 - SVG <use> swallows click events 2016-02-17 15:25:45 +01:00
Christoph Pojer
50c28fa9c4 Merge pull request #6052 from cpojer/master
Update to jest-cli 0.9.
2016-02-17 15:44:28 +09:00
cpojer
383e2f938d Update to jest-cli 0.9. 2016-02-17 13:01:14 +09:00
Jim
73ad44567c Merge pull request #6039 from mxstbr/convert-docs-to-stateless
Update documentation to stateless components
2016-02-16 12:25:39 -08:00
Jim
356fa4e8c0 Merge pull request #6048 from mxstbr/update-tutorial-versions
Update jQuery and marked versions in tutorial docs
2016-02-16 12:10:06 -08:00
Max
d26ec08cf1 Update jQuery and marked versions in tutorial 2016-02-16 12:07:03 -08:00
Paul O’Shannessy
41dea65abf Merge pull request #6017 from zpao/docs-sri-task
Generate SRI hashes for docs
2016-02-16 11:50:31 -08:00
Jim
3bee2d962a Merge pull request #5744 from prometheansacrifice/warn-if-user-accesses-key-ref-props
Warns on access of `props.key` and `props.ref`
2016-02-16 10:11:28 -08:00
Manas
c3980a6d08 Warns on access of props.key and props.ref 2016-02-16 22:04:32 +05:30
Jim
ee64241e90 Merge pull request #6044 from bellanchor/master
Fix typo in Chinese tutorial
2016-02-16 03:11:34 -08:00
liudongsheng
5b80f9009f Fix typo in Chinese tutorial 2016-02-16 18:24:07 +08:00
Max
ec41af0557 Update documentation to stateless components
Ref #5949 @jimfb
2016-02-15 10:24:04 -08:00
Jim
2410dc7f15 Merge pull request #6028 from sambev/issue/6027-uncaught-type-error
Fix for issue/6027.
2016-02-13 13:19:11 -08:00
Sam Beveridge
57d59ea344 Remove check for _wrapperState.pendingUpdate.
We can just set it to true regardless.
2016-02-13 12:01:49 -07:00
Paul O’Shannessy
8aacf1e850 Merge pull request #6032 from saiichihashimoto/allow-profile-attr
Allow Profile attr
2016-02-13 09:26:20 -08:00
Paul O’Shannessy
175d0978cc Merge pull request #6031 from jontewks/update-docs
Add npm install instructions to readme
2016-02-13 09:24:04 -08:00
Saiichi Hashimoto
0b87d7f56f Update HTMLDOMPropertyConfig.js 2016-02-13 00:42:47 -08:00
Jon Tewksbury
17c9dffed4 Add npm install instructions to readme 2016-02-12 23:20:52 -08:00
Jim
d684b1598d Merge pull request #5864 from TheBlasfem/master
Warn when an input switches between controlled and uncontrolled
2016-02-12 16:34:55 -08:00
Ben Alpert
b3eaab9f75 Merge pull request #6030 from facebook/vjeux-patch-1
Add thanks for the react org
2016-02-12 15:00:27 -08:00
Christopher Chedeau
5ce1fea75a Add thanks for the react org 2016-02-12 14:50:37 -08:00
Sam Beveridge
385cadf8e3 Forgot to 'not' the pendingUpdate condition. 2016-02-12 14:32:47 -07:00
Sam Beveridge
c4a2425eca Fix for issue/6027.
ReactDOMSelect's _handleChange function tries to set
this._wrapperState.pendingUpdate = true after executing the onChange
function. However, if the select was removed as a result of said
fuction, this._wrapperState would be null. Resulting in an
Uncaught TypeError: Cannot set property 'pendingUpdate' of null.
2016-02-12 14:00:15 -07:00
Jim
bbd5a78efa Merge pull request #6009 from jimfb/error-boundaries-initial-render-componentWillUnmount
Errors in componentWillUnmount should be caught by error boundary on initial render.
2016-02-11 18:11:35 -08:00
jim
dd390b3e36 Errors in componentWillUnmount should be caught by error boundary on initial render. 2016-02-11 17:44:35 -08:00
Jim
293dc75584 Merge pull request #6008 from jimfb/module-pattern
Enable module pattern.
2016-02-11 17:26:46 -08:00
jim
428ef03bbb Enable module pattern. 2016-02-11 12:59:25 -08:00
Ben Alpert
3e41da767f Merge pull request #5892 from ianobermiller/children-map-key-slash
ReactChildren.map: only add slash if new child has key
2016-02-10 16:53:59 -08:00
Paul O’Shannessy
b560fea08d Merge pull request #5909 from rajatsehgal/patch-1
Use const instead of var (ES6 best practices)
2016-02-10 13:32:21 -08:00
Paul O’Shannessy
e5b304ebe3 Merge pull request #6016 from zpao/rm-batched-updates-addons
Remove React.addons.batchedUpdates
2016-02-10 12:23:55 -08:00
Paul O’Shannessy
fcfbcf79a0 [docs] Reformat script tags on download page 2016-02-10 12:13:01 -08:00
Paul O’Shannessy
3ce7e91946 [docs] Automate SRI hash generation with rake task 2016-02-10 12:11:45 -08:00
Paul O’Shannessy
bd3979980f Merge pull request #6004 from TheBlasfem/sri-links
Included SRI hashes for fb.me links on download page
2016-02-10 11:40:08 -08:00
Paul O’Shannessy
6fe495a5ab Remove React.addons.batchedUpdates 2016-02-10 11:20:50 -08:00
Julio Lopez
0509950e74 Included SRI hashes for fb.me links on download page 2016-02-08 22:40:57 -05:00
Nguyen Truong Duy
48ded230fc Resolve default prop values in cloneElement
In cloneElement, when key in input config is set to undefined, the associated
prop value should be resolved to default prop values
2016-02-09 09:02:07 +07:00
Paul O’Shannessy
4a1b0b7dfa Merge pull request #5977 from jfairbank/remove-new-call
Remove instance of invoking ReactElement with new operator
2016-02-08 14:14:50 -08:00
Paul O’Shannessy
9d22ce8440 Merge pull request #6000 from shinnn/process
Do not get `process` object by using `require`
2016-02-08 11:33:15 -08:00
Paul O’Shannessy
08c7b1aa40 Update jsdelivr url 2016-02-08 11:26:46 -08:00
Jim
1e85460909 Merge pull request #5999 from shinnn/https
Use HTTPS protocol for jsdelivr.com URL
2016-02-08 10:22:57 -08:00
Shinnosuke Watanabe
38bf3583cb Do not get process object by using require
Because `process` object is globally available in Node.js.
2016-02-09 01:41:24 +09:00
Shinnosuke Watanabe
a90344a9c1 Use HTTPS protocol for jsdelivr.com URL 2016-02-09 01:00:51 +09:00
Jim
725a723e27 Merge pull request #5992 from pra85/patch-1
[docs] Fix typo in blog
2016-02-05 22:00:54 -08:00
Prayag Verma
e4b463f921 [docs] Fix typo in blog
Found a spelling mistake -
writting > writing
2016-02-06 11:21:40 +05:30
Paul O’Shannessy
886044312c Merge pull request #5986 from zpao/fix-lint
Fix lint
2016-02-05 10:57:57 -08:00
Paul O’Shannessy
a1dab9edbf Fix lint
- Upgrade babel-eslint
- Ignore coverage
- Fix actual lint warning
2016-02-05 10:56:51 -08:00
Jim
81e41ae1b1 Merge pull request #5982 from jimfb/error-boundaries-composite-unmount
Error boundries should not unmount composite components which were not mounted.
2016-02-04 17:20:09 -08:00
jim
86305fba41 Error boundries should not unmount composite components which were not mounted. 2016-02-04 17:10:18 -08:00
Jim
220b4b6b50 Merge pull request #4437 from gajus/patch-1
Improve definition of the controlled and uncontrolled input
2016-02-04 08:34:30 -08:00
Julio Lopez
b38b39a696 warn when an input switches between controlled and uncontrolled
added controlled key to DEV

warn for checkbox inputs

warn for radio inputs

compute controlled instead of value

displaying owner name in warning

displaying input type in warnings
2016-02-04 09:31:41 -05:00
Gajus Kuizinas
97e0fe5d91 Improve definition of the controlled and uncontrolled input. 2016-02-04 12:02:53 +00:00
Jeremy Fairbank
dbb54b1990 Remove instance of invoking ReactElement with new operator 2016-02-03 21:03:32 -05:00
Jim
f2bb01506a Merge pull request #5965 from karczk/issue-5957
Fix for #5957: Bug on resolving default props (HTMLAllCollection)
2016-02-03 14:39:11 -08:00
karczk
ef2b1f26ef Unnecessary type comparisons have been changed to value comparison 2016-02-02 19:35:58 +01:00
krystian.karczewski
8c7d743361 Fix for #5957: Bug on resolving default props (HTMLAllCollection) 2016-02-02 11:51:31 +01:00
Jim
292f2b7608 Merge pull request #5961 from MarkMurphy/issue-5959
Fixes #5959 - jquery-bootstrap example uses handleHidden which does not exist
2016-02-01 22:06:01 -08:00
Mark Murphy
0bd65aa028 Fixes #5959 - jquery-bootstrap example uses which does not exist
1. Add a handleHidden method to the BootstrapModal component.
2. Add an event listener for 'hidden.bs.modal' on the modal root
3. Add a new onHidden prop to the BootstrapModal component.
4. Add a new 'handleModalDidClose' method to the Example component to be used as the onHidden prop of it's modal component.
2016-02-01 21:54:56 -04:00
Jim
2981bef075 Merge pull request #5953 from davidvgalbraith/dont-redundantly-set
test: get rid of 'should be 1' comment
2016-02-01 13:07:46 -08:00
Dave
1beae0c4ff test: get rid of 'should be 1' comment
This should not be 1, since boolean properties always get set.
2016-02-01 12:53:25 -08:00
Jim
823966ef33 Merge pull request #5955 from pekeq/patch-docs-1
Add note in "Fetching from the server" section.
2016-02-01 11:54:27 -08:00
Hideo Matsumoto
d136d28f55 Add note in "Fetching from the server" section. 2016-02-01 23:19:08 +09:00
Jim
1ccec8b711 Merge pull request #5946 from tjfryan/fix-docs-css
Fixes highlight issue for code blocks with overflow (css)
2016-01-29 17:33:44 -08:00
John Ryan
cded0c5c23 Fixes highlight issue for code blocks with overflow 2016-01-29 16:46:16 -08:00
Jim
188e8cde2f Merge pull request #5884 from jimfb/component-extends-react-component
Enable null return values in plain functions
2016-01-29 15:05:08 -08:00
Jim
9d5825cf4b Merge pull request #3372 from jonhester/void-elements
ReactDOMComponent should throw error when provided children for void elements
2016-01-29 13:27:35 -08:00
Jim
67e1291ef7 Merge pull request #1510 from syranide/propattr
Use removeAttribute to forcefully remove properties from the DOM
2016-01-29 12:48:25 -08:00
Rajat Sehgal
a0c32cb629 Use const instead of var (ES6 best practices) 2016-01-29 00:47:43 -05:00
Paul O’Shannessy
9c3f595597 Merge pull request #5923 from puppybits/patch-1
Update 12-context.md
2016-01-28 20:06:09 -08:00
Bobby
6986fdd6bd Update 12-context.md
Context was missing info on how to update the context after the initial render. Added a simple blurb and an example.

[Docs] 12-context.md code review changes
2016-01-28 16:47:56 -08:00
Scott Feeney
c569b329e9 Update website for 0.14.7
(cherry picked from commit e48343bd03)
2016-01-28 12:28:25 -08:00
Scott Feeney
6ecf06ce60 Update CHANGELOG.md and README.md
(cherry picked from commit 741124548d)
2016-01-28 12:28:18 -08:00
Paul O’Shannessy
e9636b1f6a Merge pull request #5903 from zpao/rm-build-deps
Clean up ununsed devDeps
2016-01-28 10:29:03 -08:00
Paul O’Shannessy
4b2b7b0d3e Merge pull request #5911 from Mathieuu/patch-1
Fix broken guide example in "Motivation: Separation of Concerns"
2016-01-28 10:22:33 -08:00
Paul O’Shannessy
fc547e8380 Merge pull request #5928 from scjody/patch-1
Add a link to the list of supported events
2016-01-27 15:47:57 -08:00
Jody McIntyre
01f10eb7ba Add a link to the list of supported events 2016-01-27 18:09:47 -05:00
Paul O’Shannessy
ed40119db8 Merge pull request #5922 from zpao/package-empty-deps
Add empty dependencies for packages
2016-01-27 11:05:21 -08:00
Paul O’Shannessy
a92bc51e0a Add empty dependencies for packages
This ensures that broken npm versions won't crash when doing install --production
2016-01-26 08:37:30 -08:00
Paul O’Shannessy
6f5e619fae Merge pull request #5912 from chrisbolin/patch-1
Small copy changes to TestUtils and Perf summaries
2016-01-25 16:09:57 -08:00
Chris Bolin
edaf5b43b4 Small copy changes to TestUtils and Perf summaries 2016-01-25 19:02:21 -05:00
Paul O’Shannessy
ea79138156 Merge pull request #5917 from zeke/homepage-urls
Fix homepage URLs in package.json files
2016-01-25 12:58:32 -08:00
Zeke Sikelianos
0ce28c6e88 fix homepage URLs in package.json files 2016-01-25 14:44:17 -06:00
Mathieu Savy
e1b7c3aa0c Fix broken guide example in "Motivation: Separation of Concerns"
The code example in `Motivation: Separation of Concerns` now fetches the `Engineering` facebook page instead of the user `pwh`.

With the current version of the graph api, it is impossible to fetch the user picture from an username. However it is still doable for public pages.
2016-01-24 17:04:17 -08:00
Paul O’Shannessy
096115c5c9 Merge pull request #5904 from sercaneraslan/master
Overflow problem fixed
2016-01-22 11:30:06 -08:00
Sercan Eraslan
080ff5ad73 Overflow problem fixed 2016-01-22 20:51:15 +02:00
Paul O’Shannessy
7c52b802b4 Clean up ununsed devDeps
Also removed object-assign. We only support building with node v4+ which has Object.assign.
2016-01-22 10:17:30 -08:00
Paul O’Shannessy
4c03bafa4e Merge pull request #5891 from zpao/vendor-semi
Add semicolon for react-dom source files.
2016-01-21 17:06:48 -08:00
Jim
1aa7fd0d24 Merge pull request #5900 from tmysz/ja-doc
Fix mistranslation "never write to this.props."
2016-01-21 10:53:29 -08:00
tmysz
7e779a9d44 Fix mistranslation "never write to this.props." 2016-01-22 01:41:39 +09:00
Paul O’Shannessy
b41f5a1cdf v0.15.0-alpha.1 2016-01-20 20:07:37 -08:00
Ian Obermiller
30f7641873 ReactChildren.map: only add slash if new child has key
See the new test for the scenario I am trying to fix; if you clone an
element in React.cloneElement, vs just returning it directly, you will
get a different key (with a slash in front) even though the two
children are identical.
2016-01-20 19:20:22 -08:00
Ian Obermiller
76da1f8599 Merge remote-tracking branch 'facebook/master' 2016-01-20 14:50:30 -08:00
jim
757756f682 Enable null return values in plain functions 2016-01-20 14:11:41 -08:00
Paul O’Shannessy
e9e70365c3 Add semicolon for react-dom source files. 2016-01-20 13:35:03 -08:00
Jim
af43d06e97 Merge pull request #5887 from natejlee/patch-1
Fixup missing semi-colon
2016-01-20 00:56:29 -08:00
Nate Lee
7f98dc897d Fixup missing semi-colon
an inconsistency with a missing semi-colon on a variable
2016-01-19 21:35:10 -08:00
Ben Alpert
e420edda36 Merge pull request #5886 from goatslacker/cant-dangerouslysetinnerhtml-for-option
Only add children in ReactDOMOption when there are children
2016-01-19 15:12:09 -08:00
Josh Perez
3da6e2889b Only add children when there are children 2016-01-19 14:48:47 -08:00
Jim
7cee5022f8 Merge pull request #5885 from knpwrs/patch-1
Clarify stateless function component optimizations.
2016-01-19 13:50:41 -08:00
Ken Powers
49fa7d139d Clarify stateless function component optimizations.
As discussed on Discord.
2016-01-19 16:46:00 -05:00
Paul O’Shannessy
31d3bfa763 Merge pull request #5811 from jontewks/warn-nan-style
Warn when a style object has NaN for a value
2016-01-18 17:06:19 -08:00
Paul O’Shannessy
ae5ff24da6 Merge pull request #5865 from leeyoungalias/master
update react example basic-jsx-precompile comand line
2016-01-17 19:42:32 -08:00
Jim
c7808cac69 Merge pull request #5872 from SimenB/patch-1
Fix example from #5870 to avoid double rendering
2016-01-17 14:31:27 -08:00
Simen Bekkhus
f5a9a26a43 Fix example from #5870 to avoid double rendering 2016-01-17 23:25:29 +01:00
Jim
e09dfe1e0e Merge pull request #5870 from SimenB/patch-1
Remove the recommendation to use `isMounted` from beginner docs
2016-01-17 12:08:50 -08:00
Simen Bekkhus
1186cb9ab4 Remove the recommendation to use isMounted from beginner docs 2016-01-17 20:53:20 +01:00
Jon Tewksbury
7a6000c093 Add warning for NaN in style object 2016-01-16 11:10:50 -08:00
leeyoungalias
aedfa3011e update react example basic-jsx-precompile comand line on markdown file,new version of babel needed a react presets dependency. 2016-01-16 22:53:24 +08:00
Jim
2f792d5a60 Merge pull request #5859 from jimfb/clonewithprops
Removed cloneWithProps addon.
2016-01-15 17:25:24 -08:00
jim
accd0d874d Removed cloneWithProps addon. 2016-01-15 17:17:36 -08:00
Paul O’Shannessy
422b4e105c Merge pull request #5840 from koba04/release-event-target-on-destructor
Release syntheticEvent.target on the destructor
2016-01-15 16:38:42 -08:00
Paul O’Shannessy
909cba2254 Merge pull request #5724 from iamchenxin/docs122315
Update zh-docs with 4865ddf(v0.14.3+)
2016-01-15 11:18:35 -08:00
iamchenxin
209b7522d9 update zh-docs14.3 ,fixed confliction 2016-01-14 18:38:07 +08:00
Toru Kobayashi
be0551d01e Release syntheticEvent.target on the destructor 2016-01-14 15:09:56 +09:00
Paul O’Shannessy
f1c1544401 Merge pull request #5849 from david0178418/master
Added additional detail to "props-in-getInitialState" anti-pattern doc
2016-01-13 21:32:33 -08:00
David Granado
fb5cd2f7ae Added additional detail to "props-in-getInitialState" anti-pattern doc
While seemingly self-explanatory, this clarifies the reasons props usage in getInitialState might be considered an antipattern.
2016-01-13 23:22:52 -06:00
Jim
fcc63e1fff Merge pull request #5832 from jimfb/cleanup-top-level-dom-api
Remove DOM functions from top-level isomorphic API
2016-01-13 15:41:03 -08:00
Jim
7334fece2c Merge pull request #5718 from jimfb/linked-input
Added LinkedInput addon.
2016-01-13 15:40:46 -08:00
Jim
689efd1abf Merge pull request #5833 from jimfb/remove-getDOMNode
Removed getDOMNode from react classes.
2016-01-13 15:40:12 -08:00
jim
0acdb7b56a Added LinkedInput addon. 2016-01-13 12:29:00 -08:00
Paul O’Shannessy
1da992a0ab Merge pull request #5735 from cody/refs
[docs] Small fixes to "more about refs"
2016-01-12 13:02:27 -08:00
Stefan Dombrowski
ad4e31c312 [docs] Small fixes to "more about refs"
* Add a null check to "A Complete Example".
* Fix outdated comment. (Found by @mjomble)
* Replace short dash - with longer dash –.
* Remove backticks from state, because it is not code.
2016-01-12 19:07:35 +01:00
Ben Alpert
fdd7fabd12 Merge pull request #5728 from spicyj/input-gc
Remove now-unused instancesByReactID in DOMInput
2016-01-12 10:00:43 -08:00
Paul O’Shannessy
9494ec80c2 Merge pull request #5732 from iamchenxin/en-docs
[docs] deleting some unecessary newline
2016-01-12 09:57:32 -08:00
Ben Alpert
dd93eb7f40 Merge pull request #5834 from spicyj/no-ie8
blog post: Discontinuing IE 8 Support in React DOM
2016-01-12 10:27:46 -07:00
Ben Alpert
1b3adff1ca blog post: Discontinuing IE 8 Support in React DOM 2016-01-12 10:27:30 -07:00
Jim
da1fcd0fbf Merge pull request #5836 from koba04/fixup-jsdoc-for-syntheticevent
Fixup jsdoc for SyntheticEvent
2016-01-12 09:11:31 -08:00
Jim
70097ea27c Merge pull request #5826 from jacenko/master
Fixed typo in shouldComponentUpdate.png
2016-01-12 08:45:38 -08:00
Toru Kobayashi
6f976dfbbe Fixup jsdoc for SyntheticEvent 2016-01-13 00:52:59 +09:00
jim
2e1fb4b529 Remove DOM functions from top-level isomorphic API 2016-01-11 23:57:08 -08:00
jim
e8af100849 Removed getDOMNode from react classes. 2016-01-11 23:32:22 -08:00
Ben Alpert
ee03c19b3b Remove references to IE 8 in docs 2016-01-11 23:32:29 -07:00
Paul O’Shannessy
b60e8c255d Merge pull request #5829 from zpao/style-followup
Fixup style for long lines
2016-01-11 20:55:56 -08:00
Paul O’Shannessy
26f53de4a6 Fixup style for long lines 2016-01-11 17:27:37 -08:00
Jim
171305f7e2 Merge pull request #5823 from mgmcdermott/master
Warn when value and defaultValue props are both specified on input or textarea.
2016-01-11 15:33:43 -08:00
Michael McDermott
f2b62e9d90 Warn when both value and defaultValue or both check and defaultChecked props are specified on input, textarea, or select elements 2016-01-11 18:09:37 -05:00
Deniss Jacenko
d51a1d4ec1 Fixed typo in shouldComponentUpdate.png
Reconciiation -> Reconciliation
2016-01-11 17:29:40 -05:00
Paul O’Shannessy
f7850dd3d7 Merge pull request #5686 from vitorbal/master
Improve documentation for using React with Webpack
2016-01-11 12:25:26 -08:00
Paul O’Shannessy
67e85df1fa Merge pull request #5814 from zpao/docs-update-attrs-0.14.6
[docs] Updated supported attrs
2016-01-11 10:37:33 -08:00
Andreas Svensson
77a137adf9 Use removeAttribute to forcefully remove properties from the DOM, drop MUST_USE_ATTRIBUTE and manage all regular properties as attributes instead 2016-01-09 11:55:56 +01:00
Jim
ea0ac61945 Merge pull request #5813 from graue/tips-unneeded-finddomnode
[docs] remove unnecessary findDOMNode from example
2016-01-08 20:30:25 -08:00
Paul O’Shannessy
708e1b3f03 Sort attrs in HTMLDOMPropertyConfig 2016-01-08 17:23:25 -08:00
Scott Feeney
0c6b909322 [docs] remove unnecessary findDOMNode from example
This call is not needed anymore due to https://facebook.github.io/react/blog/2015/10/07/react-v0.14.html#dom-node-refs
2016-01-08 17:19:28 -08:00
Paul O’Shannessy
3574e60867 [docs] Updated supported attrs 2016-01-08 17:17:59 -08:00
Jim
23167f287e Merge pull request #5806 from Zhangjd/master
Update thinking-in-react.zh-CN.md
2016-01-08 10:03:47 -08:00
Zhangjd
a3ec1c34d6 Update thinking-in-react.zh-CN.md 2016-01-08 17:58:23 +08:00
Jim
a1584053cc Merge pull request #5790 from jimfb/componentWillReceiveProps-blogPost
Blog post explains to verify prop mutations in componentWillReceiveProps
2016-01-07 16:21:03 -08:00
Paul O’Shannessy
31fc7fd627 Merge pull request #5801 from zpao/docs-bigger-embeds
[docs] Bigger jsfiddle embeds
2016-01-07 15:08:57 -08:00
Paul O’Shannessy
c3cea365e7 [docs] Bigger jsfiddle embeds 2016-01-07 11:44:25 -08:00
jim
70938de9ae Blog post explains to verify prop mutations in componentWillReceiveProps 2016-01-07 11:11:54 -08:00
Paul O’Shannessy
a7f7ef6ac3 Update website for 0.14.6
(cherry picked from commit d5bf8c553f)
2016-01-07 10:11:21 -08:00
Paul O’Shannessy
5597873d7c Changelog & Readme for v0.14.6
(cherry picked from commit 06cad05d49)
(cherry picked from commit 44e90c040d)
2016-01-07 10:10:38 -08:00
Paul O’Shannessy
19db8e13bc Upgrade to fbjs@^0.6.1
(cherry picked from commit f305deb065)
2016-01-07 10:10:14 -08:00
Jim
78be6f45cc Merge pull request #5799 from gmcquistin/patch-1
[docs] Fix typo in ref-08-reconciliation.md
2016-01-07 09:13:32 -08:00
Gavin McQuistin
d3e315193a Fix typo in ref-08-reconciliation.md 2016-01-07 14:40:44 +00:00
Jim
9b679ab56a Merge pull request #5787 from milesj/receive-props-context-fix
Trigger componentWillReceiveProps when context changes
2016-01-06 15:54:38 -08:00
Miles Johnson
f4c5b2c00b Updated ReactCompositeComponent to trigger componentWillReceiveProps when either props or context change. Fixes issue #5756 2016-01-06 15:49:47 -08:00
Jim
2751e8179d Merge pull request #5784 from jimfb/getNativeNode
Add getNativeNode back, so we can get the native node when performing reorderings (instead of relyin
2016-01-05 15:32:24 -08:00
jim
4e3d38ed27 Removed note explaining why the logic is there, since the justification is now different. 2016-01-05 15:30:00 -08:00
Ben Alpert
0e8db6ba42 Merge pull request #5782 from spicyj/img
Move nodes around by reference instead of by index
2016-01-05 15:13:25 -08:00
Ben Alpert
eb00290673 Remove now-unused prepareToManageChildren
This was a temporary hook needed for the DOM implementation. We no longer need it because we now necessarily load every node into cache (via calling getNativeNode on it) before manipulating any of its siblings.
2016-01-05 15:08:42 -08:00
Ben Alpert
27926572f6 Move nodes around by reference instead of by index
This makes things easier if we ever want to use more than one DOM node for a component. Notably, this is more convenient if we want to remove the wrappers around text components (since text nodes can be split and joined however a browser feels like) or if we want to support returning more than one element from render (#2127).

I left the old indexes so that implementations aren't forced to use the node/image if they prefer indices, because I'm not sure yet whether the changes corresponding to my rewrite of DOMChildrenOperations are easy or hard yet in React Native. (The tests pass with and without the DOMChildrenOperations changes here.)
2016-01-05 15:08:42 -08:00
Ben Alpert
0ebc7b60e1 Revert "Merge pull request #5689 from jimfb/cleanup-5151"
This reverts commit 067547c1d1, reversing
changes made to 102cd29189.
2016-01-05 15:08:15 -08:00
Jim
067547c1d1 Merge pull request #5689 from jimfb/cleanup-5151
Get rid of getNativeNode()
2016-01-05 14:42:05 -08:00
Matthew Hodgson
7f322b5a46 support onLoad synthetic event attribute on 'object' tags - useful for telling when SVGs embedded as objects have loaded 2016-01-05 02:28:25 +00:00
Jim
102cd29189 Merge pull request #5775 from facebook/fix-checkbox-wording
Fix wording to make it more clear that checkbox (input) supports defaultChecked
2016-01-04 13:34:20 -08:00
Jim
a8c2c80fdc Fix wording to make it more clear that checkbox (input) supports defaultChecked
Fix some confusion about why `input` would support `defaultChecked` (it's because you can have an input of type checkbox).  This has come up a couple of times (https://github.com/facebook/react/pull/5633, https://github.com/facebook/react/pull/5774) but both those PRs were wrong and it was just easier to fix it myself.
2016-01-04 13:19:22 -08:00
Paul O’Shannessy
bdcb69f43d Merge pull request #5767 from yhagio/patch-2
Update 10.4-test-utils.md
2016-01-03 13:45:26 -08:00
Yuichi Hagio
c035179ef8 Update 10.4-test-utils.md
Added `var renderer = ReactTestUtils.createRenderer();` (Line 235) to clarify where `renderer` (Line 236) comes from.
2016-01-01 23:15:37 -05:00
Paul O’Shannessy
3b96650e39 Merge pull request #5748 from rickbeerendonk/year-agnostic-copyright
Year-agnostic copyright message, like React Native uses, to prevent the need for yearly changes.
2015-12-29 23:24:24 -08:00
Ben Alpert
2a042a3060 Website for 0.14.5
(cherry picked from commit fb6b3b05f4)
2015-12-29 14:43:30 -08:00
Ben Alpert
e15e059d73 Readme for 0.14.5
(cherry picked from commit d6a0a083e4)
2015-12-29 14:43:30 -08:00
Ben Alpert
dd2dbd0a5c Changelog for 0.14.5
(cherry picked from commit e7b178390d)
2015-12-29 14:43:30 -08:00
Ben Alpert
6dc7f13343 Upgrade fbjs to 0.6 in npm package too
(cherry picked from commit a9732ba548)
2015-12-29 14:43:30 -08:00
Ben Alpert
2a64098271 0.14.4 blog post 2015-12-29 14:19:18 -08:00
Ben Alpert
7cc6738061 Update a few changelog things forgotten in 3f355d99
(cherry picked from commit 0d5d0b2688)
2015-12-29 14:11:45 -08:00
Ben Alpert
8f720f8cd9 update website for 0.14.4
(cherry picked from commit c8398491d8)
2015-12-29 14:11:45 -08:00
Ben Alpert
a58cde6c79 Update readme for 0.14.4
(cherry picked from commit 0516e74473)
2015-12-29 14:11:45 -08:00
Ben Alpert
53920e7c38 Changelog for 0.14.4
(cherry picked from commit 3f355d99c5)
2015-12-29 14:11:45 -08:00
Ben Alpert
99dc2a73f6 Upgrade fbjs to 0.6
(counterpart to a29b4938a8)
2015-12-29 14:11:33 -08:00
Ben Alpert
62c9d999be Merge pull request #5749 from spicyj/lib-native
Add shim files for RN in npm package
2015-12-29 13:34:55 -08:00
Ben Alpert
c29642d6ed Add shim files for RN in npm package 2015-12-29 12:14:22 -08:00
Rick Beerendonk
bef45b0b1a Year-agnostic copyright message, like React Native uses, to prevent the need for yearly changes. 2015-12-29 20:20:32 +01:00
Paul O’Shannessy
51295bf7d0 Merge pull request #5741 from mziwisky/patch-1
Remove extraneous comment
2015-12-29 00:21:24 -08:00
Michael Ziwisky
a0d6a98cbf Remove extraneous comment
This little guy should have been removed in 6bd6ef208b
2015-12-28 19:28:41 -06:00
Dan Abramov
713401f2eb Merge pull request #5736 from gaearon/document-svg-passthrough
Document changes in #5714
2015-12-26 03:09:13 +00:00
Dan Abramov
feb4c487be Document changes in #5714 2015-12-25 18:51:09 +00:00
Dan Abramov
53dabe748c Merge pull request #5714 from gaearon/passthrough-svg-attributes
Pass all SVG attributes through
2015-12-25 13:53:33 +00:00
Dan Abramov
98a7100930 Use JSX in the new tests 2015-12-25 13:50:10 +00:00
Dan Abramov
f27e3aa750 Move the specific else if clause up 2015-12-25 13:48:13 +00:00
Dan Abramov
251d6c30b5 Move SVG attribute deprecation warnings into a devtool
In #5590 a new system was introduced for tracking dev-time warnings.
This commit uses it for reporting SVG attribute deprecation warnings.
2015-12-24 17:50:46 +00:00
Dan Abramov
232a47ad04 Pass SVG attributes through
All attributes defined on SVG elements will now be passed directly regardless of the whitelist. The casing specified by user will be preserved, and setAttribute() will be used.

In the future we will remove support for the camel case aliases to the hyphenated attributes. For example, we currently map `strokeWidth` to `stroke-width` but this is now deprecated behind a warning. When we remove support for this we can remove some of the code paths introduced in this commit.

The purpose of this change is to stop maintaining a separate SVG property config. The config still exists for two purposes:

* Allow a migration path for deprecated camelcased versions of hyphenated SVG attributes
* Track special namespaced attributes (they still require a whitelist)

However it is no longer a blocker for using new non-namespaced SVG attributes, and users don't have to ask us to add them to the whitelist.

Fixes #1657
2015-12-24 17:18:33 +00:00
iamchenxin
6e0a023572 deleting some unecessary newline 2015-12-24 14:57:30 +08:00
iamchenxin
badc15e3c0 update zh-docs (v0.14.3+) 2015-12-24 13:57:07 +08:00
Jim
82fe64a456 Merge pull request #5590 from jimfb/use-devtool-for-unknown-property-warning
Use devtool for unknown property warning
2015-12-23 19:02:58 -08:00
Ben Alpert
edf1952421 Merge pull request #5730 from spicyj/input-type-value
Add another test for #5729
2015-12-23 17:55:08 -08:00
Ben Alpert
432578ef03 Add another test for #5729 2015-12-23 16:25:35 -08:00
Ben Alpert
5043b89d5e Merge pull request #5729 from spicyj/input-type-value
Set input .type before .value always
2015-12-23 15:49:32 -08:00
Ben Alpert
07c0bc6166 Set input .type before .value always
In IE11 (and below), if you run

```
var input = document.createElement('input');
input.value = 'wat';
input.type = 'radio';
console.log(input.value);
```

you get the string "on" logged. Because that makes sense.

So we set the type first.
2015-12-23 15:44:33 -08:00
Ben Alpert
d9dabac48d Remove now-unused instancesByReactID in DOMInput 2015-12-23 15:14:13 -08:00
Paul O’Shannessy
0d5312559a Merge pull request #5725 from RochesterinNYC/patch-1
Clarify React class constructor comments
2015-12-23 11:53:12 -08:00
Paul O’Shannessy
a0741ab468 Merge pull request #5716 from jwworth/pull-request-1450816256
Fix typos in posts
2015-12-23 11:50:08 -08:00
Paul O’Shannessy
56365f4eda Merge pull request #5721 from jdalton/fast-finish
Remove fast_finish in travis.yml.
2015-12-23 11:35:56 -08:00
James Wen
6ff96441da Clarify React class constructor comments
- The constructor is not always overridden by mocks. Makes viewing this constructor during debugging less confusing.
2015-12-23 12:58:18 -05:00
Jake Worth
35e1908bb4 Fix typos in posts 2015-12-23 07:47:17 -05:00
John-David Dalton
f0a15b993c Remove fast_finish in travis.yml. 2015-12-23 00:24:20 -06:00
Jim
4865ddf7ea Merge pull request #5712 from dortonway/master
Fix misunderstanding in tutorial
2015-12-22 16:04:09 -08:00
dortonway
109c9a91e2 Fix misunderstanding in tutorial 2015-12-23 03:01:02 +03:00
Ben Alpert
bae0f19543 Merge pull request #5308 from spicyj/rep
Import ResponderEventPlugin changes from RN
2015-12-22 15:53:11 -08:00
Ben Alpert
bb11639e25 Import ResponderEventPlugin changes from RN 2015-12-22 15:45:51 -08:00
Paul O’Shannessy
89a0ef4ff9 Update badges to include coverage
Also switch to use a different badge provider for consistent styling
2015-12-22 15:41:28 -08:00
Paul O’Shannessy
85e646015d Ensure build directory works when running jest:coverage on its own 2015-12-22 14:36:27 -08:00
Paul O’Shannessy
1d8b816496 Merge pull request #5711 from iamchenxin/docs122215
[docs] Update zh-docs with 7e2a7f0
2015-12-22 14:10:41 -08:00
Paul O’Shannessy
8fa1dfaa8c Merge pull request #5713 from zpao/jest-coverage-followups
Followups to get test coverage reporting to coveralls
2015-12-22 14:07:13 -08:00
Paul O’Shannessy
39c24bf6a6 Addjust travis for jest coverage 2015-12-22 11:47:14 -08:00
Paul O’Shannessy
e68e17503e Remove coverage options from package.json
They don't provide any value and since one of them isn't a valid config usage,
it blurs the line. Instead just store these pieces in the tasks and write them
to the temp config.
2015-12-22 11:14:44 -08:00
Paul O’Shannessy
f3dbc40261 Split jest task into two
This ensures that we don't make jest do the additional tracking it needs to make coverage work.
2015-12-22 10:25:34 -08:00
Paul O’Shannessy
bbef2958b2 Merge pull request #5707 from jdalton/coveralls
Add coveralls support.
2015-12-22 10:07:36 -08:00
Paul O’Shannessy
5b98152a3d Merge pull request #5709 from zpao/youtubenocookie
[docs] fixup other broken youtube-nocookie uses
2015-12-22 10:00:47 -08:00
iamchenxin
a9a4c9d9d0 Update zh-docs with 7e2a7f0 2015-12-23 00:54:48 +08:00
John-David Dalton
9b0ef9244d Add coveralls. 2015-12-22 06:48:33 -06:00
Paul O’Shannessy
82ed8fb0cd [docs] fixup other broken youtube-nocookie uses 2015-12-22 00:54:04 -08:00
Jim
7e2a7f0ce6 Merge pull request #5706 from kchia/patch-3
Capitalizes first letter of first word in the Step 1 instruction
2015-12-21 17:26:10 -08:00
Jim
88ce0fc95f Merge pull request #5708 from kchia/patch-4
Corrects grammatical errors in tutorial
2015-12-21 16:28:34 -08:00
Hou Chia
c465c2ab77 Corrects grammatical errors 2015-12-21 15:03:09 -08:00
Hou Chia
744b1175f3 Capitalizes first letter of first word in the Step 1 instruction
This proposed change makes the documentation formatting more consistent.
2015-12-21 14:51:10 -08:00
Dan Abramov
14d8593102 Fix a minor typo in Contributing 2015-12-21 21:23:07 +00:00
Dan Abramov
d872c25739 Fix the incorrect Jest watch command in Contributing 2015-12-21 21:07:20 +00:00
Paul O’Shannessy
ac20cb2d8c Merge pull request #5705 from facebook/gaearon-patch-1
Mention how to run specific tests in Jest
2015-12-21 12:57:18 -08:00
Jim
9c57c30049 Merge pull request #5699 from jwworth/pull-request-1450702663
Fix typo (duplicate word)
2015-12-21 12:55:55 -08:00
Dan Abramov
cd0c62ef74 Mention how to run specific tests in Jest 2015-12-21 20:54:16 +00:00
Dan Abramov
50af034108 Merge pull request #5695 from gaearon/patch-2
Fix children to be a prop in the blog post example
2015-12-21 20:04:52 +00:00
Dan Abramov
dae1152e66 Merge pull request #5702 from gaearon/patch-3
Mention that Jest can be used directly in Contributing
2015-12-21 19:18:42 +00:00
Dan Abramov
ca31e9f3f7 Remove mention of grunt test --debug from README
It isn't supported anymore.
2015-12-21 19:18:23 +00:00
Dan Abramov
dc9b3fedb2 Mention that Jest can be used directly in Contributing 2015-12-21 19:14:26 +00:00
Jim
8d0efaf980 Merge pull request #5701 from cesarwbr/patch-1
Fix typo in youtube url for video in blog post.
2015-12-21 10:29:09 -08:00
Cesar William Alvarenga
a8b953327a Fix typo
Fix the conference talk youtube url.
2015-12-21 16:02:53 -02:00
Jake Worth
a067949c99 Fix typo 2015-12-21 06:57:52 -06:00
Paul O’Shannessy
aad8024d09 Merge pull request #5697 from kolodny/stricter-update-tests
improved react-addons-update tests
2015-12-20 21:11:29 -08:00
Paul O’Shannessy
1b85c9a6c4 Merge pull request #5698 from facebook/Daniel15-patch-1
Remove smart quotes from code snippet in blog post
2015-12-20 21:09:00 -08:00
Daniel Lo Nigro
abddb558ec Remove smart quotes from code snippet
"Smart" quotes aren't actually very smart.
2015-12-21 15:53:30 +11:00
Moshe Kolodny
7c0189fbad improved react-addons-update tests 2015-12-20 22:01:54 -05:00
Dan Abramov
89538d44a9 Fix minor typos in the blog post 2015-12-18 23:24:07 +00:00
Dan Abramov
421d177dd2 Fix children to be a prop in the blog post example 2015-12-18 21:32:32 +00:00
Ben Alpert
5563771ace Merge pull request #5694 from spicyj/div-html-nesting
Make sure div > html nesting is considered invalid
2015-12-18 12:53:27 -08:00
Ben Alpert
40d5692980 Make sure div > html nesting is considered invalid
See #5128.
2015-12-18 12:49:54 -08:00
Paul O’Shannessy
bdca170d2a Merge pull request #5693 from gaearon/elements-post
Added post about components, elements, and instances
2015-12-18 12:42:33 -08:00
Paul O’Shannessy
9a6c5deeb6 Merge pull request #5692 from zpao/small-style-fixups
A couple small style fixups that were missed in recent PRs
2015-12-18 12:23:54 -08:00
Dan Abramov
f56b28c07a Added post about components, elements, and instances 2015-12-18 20:22:24 +00:00
Paul O’Shannessy
7a1d87bd33 A couple small style fixups that were missed in recent PRs 2015-12-18 11:27:49 -08:00
jim
8eabf84204 Get rid of getNativeNode() 2015-12-17 19:04:27 -08:00
Vitor Balocco
a3d6553a30 Improve documentation for using React with Webpack
Fixes #5679
2015-12-17 17:22:56 +01:00
jim
26f3785a8c Use duck typing instead of allocating event objects 2015-12-16 19:32:55 -08:00
Paul O’Shannessy
83328d4923 Merge pull request #5683 from zpao/build-no-vendor
Don't build vendor files into build/modules
2015-12-16 18:57:14 -08:00
Paul O’Shannessy
b8315fdd59 Don't build vendor files into build/modules 2015-12-16 18:08:26 -08:00
Ben Alpert
963b3cacab Merge pull request #5346 from prometheansacrifice/warn-immutable-props
Warns when mutated props are passed.
2015-12-16 16:09:33 -08:00
Jim
c9c3c339b7 Merge pull request #5216 from nLight/number-in-data-attrs-2329
Allow numbers after `data-` in custom attributes fixes #2329
2015-12-16 15:37:41 -08:00
Jim
ab37776cc2 Merge pull request #5599 from zramaekers/shallow-compare-docs
Add documentation for shallowCompare addon
2015-12-16 15:34:04 -08:00
Jim
0c15b01c38 Merge pull request #5602 from jimfb/error-boundaries
Error boundaries
2015-12-16 13:04:45 -08:00
Jim
3afced6a75 Error boundaries. 2015-12-16 12:15:26 -08:00
Paul O’Shannessy
a15293704a Merge pull request #5673 from DJCordhose/reactelement-doc-fix
fixed docs on ReactElement that were out of sync with code
2015-12-16 11:50:36 -08:00
Jim
ccb97d8e59 Merge pull request #5587 from jimfb/ismounted-alternatives
Added post about upgrading your code to avoid isMounted()
2015-12-16 05:54:55 -08:00
Oliver Zeigermann
20e5a95fe3 fixed docs on ReactElement that were out of sync with code 2015-12-16 11:26:32 +01:00
Jim
bec238a7c9 Added post about upgrading your code to avoid isMounted() 2015-12-15 16:25:07 -08:00
Paul O’Shannessy
6c8cbcae8f Merge pull request #5663 from jonathanp/fix-code-comment
Rephrase comment to better describe use of `warning()`
2015-12-15 14:32:40 -08:00
jpersson
13080f99ba Rephrase comment to better describe use of warning() 2015-12-14 23:27:37 -05:00
Jim
30ef056731 Moved unknown-prop warning into a devtool 2015-12-14 16:29:04 -08:00
Jim
a55ab282fa Initial outline for new devtools api 2015-12-14 16:29:02 -08:00
Ben Alpert
33217f0fb9 Merge pull request #4888 from spicyj/ssr-no-queue
Don't build up mount-ready queue for server side rendering
2015-12-14 14:46:04 -08:00
Ben Alpert
3997164418 Merge pull request #5550 from spicyj/cc-speed
Make createClass 10-15% faster on complex specs
2015-12-14 14:45:44 -08:00
Paul O’Shannessy
eee5d466a6 Merge pull request #5623 from freddyrangel/autocorrect_autocapitalize
Autocorrect and autocapitalize should not be property
2015-12-14 14:11:15 -08:00
Paul O’Shannessy
b6a01d7733 Merge pull request #5658 from applegrain/clarify-dependency-installation
Clarify dependency installation
2015-12-14 11:20:54 -08:00
Lovisa Svallingson
2ff1b2e9e3 Clarify dependency installation
Split browserify and webpack to separate sections.
Remove `babelify` from the webpack section since it's only for browserify
2015-12-14 09:28:20 -07:00
Freddy Rangel
db37deb17c Autocorrect and autocapitalize should not be property
Fixes facebook/react#5436
2015-12-13 23:37:29 -08:00
Jim
55bd203310 Merge pull request #5655 from adraeth/patch-1
Correct highlight in tutorial7.js snippet
2015-12-13 13:13:44 -08:00
Jim
83ee3c38a4 Merge pull request #5654 from jutaz/bugfix/typos
Bugfix - Typos
2015-12-13 10:43:50 -08:00
adraeth
682d61537d Correct highlight in tutorial7.js snippet 2015-12-13 17:38:30 +01:00
Justas Brazauskas
0886273438 Fix few typos in React docs and comments 2015-12-13 16:39:07 +02:00
Jim
410cc30bf9 Merge pull request #5605 from thekevlau/patch-1
Adding class->className as a JSX gotcha
2015-12-11 12:13:48 -08:00
Kevin Lau
fcf74fe9da Finalized wording 2015-12-11 12:05:05 -08:00
Jim
f282710072 Merge pull request #5644 from AndrewHenderson/patch-1
Helps avoid a common Issue when following tutorial
2015-12-11 10:56:01 -08:00
Andrew Henderson
ef32927eb5 Helps avoid a common Issue when following tutorial
https://github.com/reactjs/react-tutorial/issues/87
2015-12-10 22:44:36 -08:00
Jim
eeee272268 Merge pull request #5643 from koh-taka/patch-1
Fix wrong script name (showdown -> marked)
2015-12-10 18:27:17 -08:00
koh-taka
94325ea3ef Fix wrong script name (showdown -> marked)
jp: チュートリアル内のshowdown を marked に修正
2015-12-11 11:23:56 +09:00
Jim
bb084eba24 Merge pull request #5609 from vitorbal/patch-1
Clarify usage of `.propTypes` when using functional components
2015-12-10 15:21:55 -08:00
Vitor Balocco
b1964ad8a7 Clarify usage of .propTypes and .defaultProps when using stateless functional components
I've seen some people unaware about the fact that you can still specify `.propTypes` and `.defaultProps` when you are defining a functional component by setting them as properties of the function.
I thought clarifying this in the docs could help!
2015-12-10 23:21:59 +01:00
Ben Alpert
4f7a2766e4 Merge pull request #5640 from spicyj/no-typechecks
Remove @typechecks
2015-12-10 11:30:40 -08:00
Ben Alpert
46f5251c66 Remove @typechecks
These don't really do anything.

```
codemod.py -d src --extensions js -m '\s* \* @typechecks.*?\n' '\n'
```

with "yes to all".
2015-12-10 11:26:45 -08:00
Jim
be964561ed Merge pull request #5610 from yangshun/change-devtools-message
Change devtools install message on file: URLs
2015-12-10 08:55:57 -08:00
Tay Yang Shun
3deca65a89 Change devtools install message on file: URLs 2015-12-11 00:48:53 +08:00
Kevin Lau
0130a04f05 added nuance about identifiers used in custom elements 2015-12-09 00:33:25 -08:00
Ben Alpert
c65ff201fc Merge pull request #5614 from mark-rushakoff/avoid-negative-lookahead
Avoid negative lookahead in regular expression
2015-12-06 20:27:03 -08:00
Mark Rushakoff
86b44349de Avoid negative lookahead in regular expression
I'm trying to use React with otto
(https://github.com/robertkrimen/otto), which is implemented in Go and
does not support lookaheads or backreferences in regular expressions.
(Unfortunately that *does* mean that otto isn't fully compatible with
the ECMA5 spec; but since this is the only lookahead I am aware of in
the React codebase, this change makes React once again compatible with
otto, and any other JS implementation that may not be fully compliant on
regular expressions).

As far as I can tell, the previous code replaced a sequence of slash
characters with one more slash than before. The new code avoids the
negative lookahead by matching any sequence of slash characters and then
using the special `$&` placeholder to replace the matched sequence with
the original sequence, plus one more slash.
2015-12-06 13:46:16 -08:00
Jim
178fe648de Merge pull request #5611 from dittos/irc-remove-2ndarg
Clean up caller sites of instantiateReactComponent
2015-12-06 05:01:15 -08:00
Taeho Kim
14725ba768 Clean up caller sites of instantiateReactComponent
The 2nd argument was removed since #4139.
2015-12-06 17:31:30 +09:00
Kevin Lau
1d3ff2a159 Adding class->className as a JSX gotcha
It's mentioned as a note in "JSX in Depth" however I think for clarity and ease of look-up, it would be a good idea to also include it in the JSX Gotchas list?
2015-12-04 16:51:38 -08:00
Paul O’Shannessy
856eb72b4f Merge pull request #5593 from zwhitchcox/patch-3
Remove dead code
2015-12-04 15:57:27 -08:00
zwhitchcox
b15c80696c Remove dead code
This isn't used anywhere in React
2015-12-04 18:28:37 -05:00
Paul O’Shannessy
3faf9569d4 [blog] Diversity Scholarship 2016 2015-12-04 14:51:12 -08:00
Paul O’Shannessy
67663ba2c9 Merge pull request #5603 from henryw4k/patch-3
chore(ReactComponentWithPureRenderMixin.js): made "Mixin" lowercase
2015-12-04 13:08:58 -08:00
Paul O’Shannessy
4f9d8c31b8 Merge pull request #5600 from zwhitchcox/patch-4
Change release to multi task
2015-12-04 13:08:08 -08:00
Ben Alpert
2f77367863 Merge pull request #5595 from remko/select-bug
Fix single select incorrectly updating
2015-12-04 11:12:23 -08:00
Henry Wong
4a971c2d1c chore(ReactComponentWithPureRenderMixin.js): made "Mixin" lowercase
When referring to mixin, the rest of the comment is in lowercase; see line 36 and line 37. 
This change helps with the consistency of the usage of "mixin", and not to confuse it with a variable name.
2015-12-04 11:12:07 -08:00
zwhitchcox
c77f0b2fc5 Change release to multi task
More concise and consistent with the other multitasks
2015-12-04 13:29:58 -05:00
Zach Ramaekers
ad54e49f0c adding documentation pages for shallowCompare addon 2015-12-04 08:53:33 -06:00
Remko Tronçon
7d699f4063 Fix single select incorrectly updating
Closes #5592
2015-12-04 11:21:02 +01:00
Jim
f4744f3a70 Merge pull request #5588 from jimfb/setprops-replaceprops-deprecated
Increase severity of setprops and replaceprops deprecations, since their removal is now imminent.
2015-12-03 10:29:20 -08:00
jim
8c7603311a Increase severity of setprops and replaceprops deprecations, since their removal is now imminent. 2015-12-03 04:08:53 -08:00
Jim
526d5c0edc Merge pull request #5589 from wrakky/fix-minlength-docs
Rename minlength to minLength in the tags and attributes documentation page
2015-12-03 04:04:45 -08:00
Peter Newnham
31253c251f Rename minlength to minLength in the tags and attributes documentation page 2015-12-03 09:35:08 +00:00
Jim
50c7b1792c Merge pull request #5570 from jimfb/remove-setprops-replaceprops
Remove setProps and replaceProps.
2015-12-02 19:09:19 -08:00
Paul O’Shannessy
0be7786e1c Merge pull request #5559 from shogunsea/docs-add-marked
[docs]Add marked source in tutorial doc
2015-12-02 11:30:49 -08:00
Paul O’Shannessy
3ca15b0090 Merge pull request #5584 from zwhitchcox/patch-2
Update ref-10-glossary.md
2015-12-02 11:14:22 -08:00
zwhitchcox
b0ae955977 Update ref-10-glossary.md 2015-12-02 08:52:51 -05:00
Scott Feeney
8557cc0d67 Merge pull request #5561 from graue/setstate-cwm
shallow render: fix setState in componentWillMount
2015-12-01 19:49:15 -08:00
Scott Feeney
9c21e2f3c4 shallow render: fix setState in componentWillMount 2015-12-01 19:43:52 -08:00
Ben Alpert
6b3ee0e74d Merge pull request #5576 from spicyj/log-top-level
Log top-level renders with console.time
2015-12-01 11:34:40 -08:00
Ben Alpert
a0f88d29df Log top-level renders with console.time
Behind a flag.
2015-12-01 11:29:13 -08:00
Paul O’Shannessy
f5840e685e Merge pull request #5581 from yuyokk/patch-1
Update 08.1-more-about-refs.md
2015-12-01 11:03:59 -08:00
Iurii Kucherov
36dfe62f68 Update 08.1-more-about-refs.md 2015-12-01 19:28:34 +01:00
Paul O’Shannessy
13c398bef6 Merge pull request #5536 from zpao/keys-on-prototypes
Don't use `key` when defined on String, Number prototypes
2015-11-30 23:33:26 -08:00
xxin
25ef456b13 add marked source in tutorial doc
update wording of later section

no first, no next

more on wording
2015-11-30 19:08:11 -06:00
jim
fbf81a8435 Remove setProps and replaceProps. 2015-11-30 11:46:07 -08:00
Jim
940a75b1fe Merge pull request #5564 from jackiewung/master
Fix file reference typo in starter
2015-11-30 09:34:15 -08:00
Jackie Wung
f1d3f78334 Fix file reference typo in starter 2015-11-29 18:07:31 -08:00
Paul O’Shannessy
34fbcf20d8 Merge pull request #5526 from yangshun/todo-app-id
[docs] Use id for TodoApp example
2015-11-28 11:58:20 -08:00
Paul O’Shannessy
f48bb3a274 Merge pull request #5520 from mhujer/docs-spread-fix-babel
Docs: Transform rest and spread properties using Babel 6
2015-11-28 11:47:30 -08:00
Paul O’Shannessy
6b641de6b8 Merge pull request #5546 from cody/singlechild
[docs] Single Child
2015-11-28 11:46:47 -08:00
Paul O’Shannessy
d54b151bc2 Merge pull request #5556 from timuric/patch-1
Avoid mutating state in the example code
2015-11-28 11:30:35 -08:00
Timur Carpeev
1e98c78541 Avoid mutating state in the example code
According to react documentation it is advised to: 
NEVER mutate this.state directly, as calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable.
https://facebook.github.io/react/docs/animation.html

In this particular case it is probably doesn't matter since setState is called directly after mutation, but it does provide a bad example of state mutation.

Another way of removing an item from an array can be `newItems = this.state.slice(0,i).concat(this.state.slice(i+1))` however the meaning can be less obvious to some.
2015-11-27 12:33:57 +01:00
Martin Hujer
ed8727ade7 Transform rest and spread properties using Babel 6
> Out of the box Babel doesn't do anything. In order to actually do
> anything to your code you need to enable plugins.
> (https://babeljs.io/docs/plugins/)
2015-11-26 09:17:01 +01:00
Ben Alpert
50c81d5fe6 Make createClass 10-15% faster on complex specs 2015-11-25 18:24:46 -08:00
Ben Alpert
ba0792e72b Add createClass stress test
Running this is left as an exercise for the reader, since my measure.py isn't designed for this at present. But something like this might work:

```diff
diff --git a/scripts/bench/measure.py b/scripts/bench/measure.py
index 4cedf47..627ec97 100755
--- a/scripts/bench/measure.py
+++ b/scripts/bench/measure.py
@@ -79,15 +79,12 @@ def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
             if (typeof React !== 'object') throw new Error('React not laoded');
             report('factory_ms', END - START);

-            globalEval(readFile(ENV.bench_path));
-            if (typeof Benchmark !== 'function') {
-              throw new Error('benchmark not loaded');
-            }
+            globalEval("bm = (function(){" + readFile("bench-createclass-madman.js") + "})");
+            bm();
             var START = now();
-            var html = React.renderToString(React.createElement(Benchmark));
-            html.charCodeAt(0);  // flatten ropes
+            bm();
             var END = now();
-            report('ssr_' + ENV.bench_name + '_cold_ms', END - START);
+            report('cc_' + ENV.bench_name + '_cold_ms', END - START);

             var warmup = ENV.measure_warm ? 80 : 0;
             var trials = ENV.measure_warm ? 40 : 0;
@@ -119,7 +116,7 @@ def _main():
         return 1
     react_path = sys.argv[1]

-    trials = 30
+    trials = 60
     sys.stderr.write("Measuring SSR for PE benchmark (%d trials)\n" % trials)
     for i in range(trials):
         for engine in [
@@ -132,7 +129,7 @@ def _main():
         sys.stderr.flush()
     sys.stderr.write("\n")

-    trials = 3
+    trials = 0#3
     sys.stderr.write("Measuring SSR for PE with warm JIT (%d slow trials)\n" % trials)
     for i in range(trials):
         for engine in [
```
2015-11-25 18:24:46 -08:00
Ben Alpert
8248470bd9 Merge pull request #5547 from spicyj/mc-noq
Kill global queue in ReactMultiChild
2015-11-25 13:13:01 -08:00
Ben Alpert
418ba27485 Kill global queue in ReactMultiChild
As we move away from using HTML for updates, this becomes less useful.
2015-11-25 12:59:02 -08:00
Ben Alpert
08499f9938 Turn on useCreateElement by default
Facebook has been running with this on for a couple weeks now with no ill effects.
2015-11-25 12:59:01 -08:00
Ben Alpert
3722616349 Merge pull request #5543 from spicyj/rt103
Clarify wording in the tutorial
2015-11-25 09:37:28 -08:00
Stefan Dombrowski
c6025da952 [docs] Single Child
* Single Child belongs to Prop Validation, so it was moved there.
* "throw" was changed to "warn".
2015-11-25 17:34:40 +01:00
Paul O’Shannessy
54e6057b1a Merge pull request #5523 from hejld/add-selection-and-composition-events-on-reference-page
[docs] Add missing sections to events reference page in IT and CN
2015-11-24 09:44:49 -08:00
Paul O’Shannessy
e95d3dd812 Merge pull request #5539 from matthewlooi/addCodeHighlightToTutorialDoc
Add highlight to a line of code to tutorial21.js
2015-11-24 09:44:03 -08:00
Ben Alpert
58901af7a6 Clarify wording in the tutorial
reactjs/react-tutorial#103
2015-11-24 09:30:33 -08:00
hejld
18a3a3979e Add missing sections to events reference page in IT and CN 2015-11-24 15:56:58 +01:00
Matthew
e02bd0543f add highlight to a line of code to tutorial20.js (all languages included) 2015-11-24 01:23:55 -05:00
Paul O’Shannessy
f44a0778e3 Don't use key when defined on String, Number prototypes 2015-11-23 15:33:34 -08:00
Paul O’Shannessy
d01188133e Merge pull request #5533 from kryogenic/patch-1
Use null instead of '' in ternary expression
2015-11-23 12:12:14 -08:00
Kale
b74e53c3ca Use null instead of '' in ternary expression
A blank string ('') resolves to <span></span> which produces a warning when place inside a <tr>
2015-11-23 06:38:08 -07:00
Paul O’Shannessy
7ea1d15197 Merge pull request #5524 from chenglou/woohoo-its-me
Remove unreachable return from shouldUpdateReactComponent
2015-11-22 18:54:17 -08:00
Tay Yang Shun
bf4bd19101 [docs] Use id for TodoApp example 2015-11-22 11:54:39 +08:00
Cheng Lou
60af7d1c3d Remove unreachable return from shouldUpdateReactComponent
Eslint didn't catch this (we do have this rule turned on) because it's a
big. There are no other locations I think. Detected that when I minified
some code.
2015-11-21 18:00:40 -05:00
Paul O’Shannessy
c5867ea401 Merge pull request #5518 from mhujer/docs-spread-fix
Docs: Rest and Spread Properties - ECMAScript
2015-11-20 11:30:02 -08:00
Ben Alpert
812e1a877f Merge pull request #5500 from hejld/master
Update DOM_OPERATION_TYPES mappings for ReactDefaultPerfAnalysis
2015-11-20 11:21:06 -08:00
Sebastian Markbåge
64f795e5ef Merge pull request #5411 from simonewebdesign/master
ReactShallowRenderer.render returns the rendered output
2015-11-20 11:20:37 -08:00
Martin Hujer
23edc0d274 Rest/Spread Properties may not be part of ES7
According to the http://www.2ality.com/2015/11/tc39-process.html it is
not a good idea to guess target ES version until the proposal reaches
later phases.

Even the proposal repository now states
  > It is a Stage 2 proposal for ECMAScript. <
(it has been changed in e9813ac78a)
2015-11-20 19:36:29 +01:00
Ben Alpert
acabb22a1d Merge pull request #5503 from spicyj/measure-analyze
benchmarking: measure and analyze scripts
2015-11-19 17:01:53 -08:00
Ben Alpert
907dee2b5d Merge pull request #5451 from spicyj/empty-comments
Use comment nodes for empty components
2015-11-19 16:56:23 -08:00
Paul O’Shannessy
1cdbff26ab Merge pull request #5511 from KeweiCodes/patch-1
Typo
2015-11-19 15:56:25 -08:00
Paul O’Shannessy
aa1e58a41b Merge pull request #5508 from yangshun/patch-1
Add in missing closing </li> for docs template
2015-11-19 13:57:37 -08:00
Kewei Jiang
179263c72f Typo 2015-11-20 10:01:29 +13:00
Jim
22a3f6724a Merge pull request #5510 from jimfb/useless-find-dom-nodes
Removed unnecessary variables/assertions.
2015-11-19 12:14:05 -08:00
jim
1d071c20e8 Removed unnecessary variables/assertions. 2015-11-19 11:32:51 -08:00
Jim
c643ecd7c7 Merge pull request #5495 from jimfb/remove-public-dom-instance
Remove legacy dom node/ref stuff.
2015-11-19 11:27:24 -08:00
Tay Yang Shun
ab6892956d Add in missing closing </li> for docs template 2015-11-20 00:56:25 +08:00
Paul O’Shannessy
0440de9f89 update website for 0.14.3
(cherry picked from commit 3f2f763dea)
2015-11-18 22:39:49 -08:00
Paul O’Shannessy
399a6cfd1c Update readme for 0.14.3
(cherry picked from commit 1cef6ebabf)
2015-11-18 22:39:49 -08:00
Paul O’Shannessy
b40221973c v0.14.3 blog post
(cherry picked from commit f92a630737)
2015-11-18 22:39:49 -08:00
Paul O’Shannessy
fd03270372 Changelog for 0.14.3
(cherry picked from commit 55b6839684)
2015-11-18 22:39:49 -08:00
Ben Alpert
844ca8b6b2 benchmarking: measure and analyze scripts
This uses wall-clock time (for now) so it's noisier than alternatives
(cachegrind, CPU perf-counters), but it's still valuable. In a future diff we
can make it use those.

`measure.py` outputs something that `analyze.py` can understand, but you can use `analyze.py` without `measure.py` too. The file format is simple:

```
$ cat measurements.txt
factory_ms_jsc_jit 13.580322265625
factory_ms_jsc_jit 13.659912109375
factory_ms_jsc_jit 13.67919921875
factory_ms_jsc_nojit 12.827880859375
factory_ms_jsc_nojit 13.105224609375
factory_ms_jsc_nojit 13.195068359375
factory_ms_node 40.4891400039196
factory_ms_node 40.6669420003891
factory_ms_node 43.52413299679756
ssr_pe_cold_ms_jsc_jit 43.06005859375
...
```

(The lines do not need to be sorted.)

Comparing 0.14.0 vs master:

```
$ ./measure.py react-0.14.0.min.js >014.txt
Measuring SSR for PE benchmark (30 trials)
..............................
Measuring SSR for PE with warm JIT (3 slow trials)
...
$ ./measure.py react.min.js >master.txt
Measuring SSR for PE benchmark (30 trials)
..............................
Measuring SSR for PE with warm JIT (3 slow trials)
...
$ ./analyze.py 014.txt master.txt
Comparing 014.txt (control) vs master.txt (test)
Significant differences marked by ***
% change from control to test, with 99% CIs:

* factory_ms_jsc_jit
    % change:  -0.56% [ -2.51%,  +1.39%]
    means: 14.037 (control), 13.9593 (test)
* factory_ms_jsc_nojit
    % change:  +1.23% [ -1.18%,  +3.64%]
    means: 13.2586 (control), 13.4223 (test)
* factory_ms_node
    % change:  +3.53% [ +0.29%,  +6.77%]  ***
    means: 42.0529 (control), 43.54 (test)
* ssr_pe_cold_ms_jsc_jit
    % change:  -6.84% [ -9.04%,  -4.65%]  ***
    means: 44.2444 (control), 41.2187 (test)
* ssr_pe_cold_ms_jsc_nojit
    % change: -11.81% [-14.66%,  -8.96%]  ***
    means: 52.9449 (control), 46.6953 (test)
* ssr_pe_cold_ms_node
    % change:  -2.70% [ -4.52%,  -0.88%]  ***
    means: 96.8909 (control), 94.2741 (test)
* ssr_pe_warm_ms_jsc_jit
    % change: -17.60% [-22.04%, -13.16%]  ***
    means: 13.763 (control), 11.3439 (test)
* ssr_pe_warm_ms_jsc_nojit
    % change: -20.65% [-22.62%, -18.68%]  ***
    means: 30.8829 (control), 24.5074 (test)
* ssr_pe_warm_ms_node
    % change:  -8.76% [-13.48%,  -4.03%]  ***
    means: 30.0193 (control), 27.3964 (test)
$
```
2015-11-18 16:26:01 -08:00
Paul O’Shannessy
d1eba1f78c Merge pull request #5501 from zpao/release-react-dom-server
Make sure react-dom-server is shipped in release process
2015-11-18 13:16:57 -08:00
Paul O’Shannessy
5a80b20017 Make sure react-dom-server is shipped in release process
Also removed some duplicated code to simplify a bit
2015-11-18 13:08:44 -08:00
hejld
a3779421a1 Update DOM_OPERATION_TYPES mappings for ReactDefaultPerfAnalysis 2015-11-18 20:58:32 +01:00
Ben Alpert
1a6d1e74e0 Merge pull request #5330 from laskos/fix-shallow-rendering-function-refs
Fix shallow renderer with ref as function
2015-11-17 23:53:00 -08:00
Paul O’Shannessy
e7a5a98044 Merge pull request #5417 from zpao/ol-reversed
Support reversed for <ol>s
2015-11-17 23:24:27 -08:00
Paul O’Shannessy
904e9e3ea6 Merge pull request #5445 from yangshun/controlled-components-in-tutorial
Use controlled components in tutorial
2015-11-17 22:59:40 -08:00
Tay Yang Shun
3812b95450 [docs] Use controlled components for tutorial 2015-11-18 14:43:03 +08:00
Paul O’Shannessy
c4f134883d Support reversed for <ol>s 2015-11-17 22:42:01 -08:00
Paul O’Shannessy
60cba8fcf7 Merge pull request #5496 from zpao/reactdomserverfollowup
Followup to #5381
2015-11-17 21:57:51 -08:00
Paul O’Shannessy
7729d51726 Followup to #5381
- Export to the right variable
- Simplify lintignore
- Fix cURL command for TravisCI
2015-11-17 17:57:43 -08:00
Paul O’Shannessy
c07b304c76 Merge pull request #5381 from kevinrobinson/react-dom-server-package
Add additional secret property to build artifact for react-dom-server
2015-11-17 16:48:08 -08:00
jim
538d0b08f2 Remove legacy dom node/ref stuff. 2015-11-17 15:30:35 -08:00
Ben Alpert
e03df26e62 Merge pull request #5493 from spicyj/gh-4589
Finish comment in ReactDOMComponentTree
2015-11-17 09:54:23 -08:00
Ben Alpert
6c89857cdc Finish comment in ReactDOMComponentTree 2015-11-17 09:41:24 -08:00
Ben Alpert
892352e95d Merge pull request #5489 from hejld/master
Fix typos and redundant words
2015-11-17 09:37:43 -08:00
hejld
ba8c987391 Fix typos and redundant words 2015-11-17 12:39:29 +01:00
Ben Alpert
85a3142f04 Merge pull request #5481 from hejld/master
Fixed typo
2015-11-16 11:24:04 -08:00
Jim
80bcc519d7 Merge pull request #2774 from jimfb/webcomponents
Added info (example+doc) about react with webcomponents
2015-11-16 11:19:26 -08:00
hejld
94504c3767 Remove rendundant 'the'; keep iff (if and only if) 2015-11-16 20:05:37 +01:00
Jim
7a453646be Added info (example+doc) about react with webcomponents 2015-11-13 20:22:24 -08:00
Paul O’Shannessy
96549a1f48 Merge pull request #5458 from chicoxyzzy/update_deps
Update deps
2015-11-12 16:45:27 -08:00
Paul O’Shannessy
034cfc96c7 [docs] Properly fix Korean docs 2015-11-12 15:57:17 -08:00
Paul O’Shannessy
72d9a8bc15 [docs] Use updated Korean translation
See #5456 for details
2015-11-12 14:23:52 -08:00
Paul O’Shannessy
09b7ff1fc4 Merge pull request #5444 from zpao/tutorial-ids-for-data
[tutorial] Use ids in comments data
2015-11-12 14:22:00 -08:00
Paul O’Shannessy
3bcb0d63f0 [tutorial] Use ids in comments data 2015-11-12 14:20:54 -08:00
chico
dbe8212974 update deps 2015-11-13 01:15:23 +03:00
Manas
593a234c1e Warns when mutated props are passed. 2015-11-13 01:15:38 +05:30
Paul O’Shannessy
2d5612913f Merge pull request #5456 from hugo-agbonon/fix-classname-manipulation-doc
Revert class name manipulation doc to english
2015-11-12 09:57:55 -08:00
Dmitriy Rozhkov
a2b471e098 Allow all characters (except astral) specified in XML specs. fixes #2329 2015-11-12 16:21:34 +01:00
Hugo Agbonon
47253733d3 Revert class name manipulation doc to english 2015-11-12 11:32:08 +01:00
Ben Alpert
ea31f924b8 Merge pull request #5368 from spicyj/adler32
adler32: Properly break loop into 4096-char blocks
2015-11-11 22:21:22 -08:00
Paul O’Shannessy
8104262043 Merge pull request #5390 from chicoxyzzy/arrayof-objectof-tests
Add validation for arrayOf and objectOf in ReactPropTypes
2015-11-11 16:48:33 -08:00
Sebastian Markbåge
951f3b6ba8 Merge pull request #5406 from acdlite/better-error-message-for-setState-in-constructor
Updates the warning that is displayed when `setState` is called within either `render` or a component constructor.
2015-11-11 16:45:12 -08:00
Paul O’Shannessy
12a20b184c Merge pull request #5387 from MattijsKneppers/master
updated Basic Example with External JSX instructions
2015-11-11 10:31:01 -08:00
Ben Alpert
358140679c Use comment nodes for empty components
This makes more sense and avoids DOM nesting problems.

![image](https://cloud.githubusercontent.com/assets/6820/11098713/952348ca-885b-11e5-9757-e4a76467b0b8.png)

(ReactSimpleEmptyComponent isn't used here but React Native can use it as it currently does.)
2015-11-11 10:04:14 -08:00
Mattijs
1220ccc805 update instructions of the following examples: basic-commonjs, basic-jsx-external and basic-jsx-precompile 2015-11-11 10:51:47 +01:00
Paul O’Shannessy
fc245226f9 Merge pull request #5431 from zpao/license-in-packages
Ensure license and patents files are packaged for npm
2015-11-10 15:22:34 -08:00
Jim
4cb210a9da Merge pull request #5412 from yangshun/document-next-context
Add more documentation to Context page
2015-11-10 15:12:08 -08:00
Tay Yang Shun
7d0ee24514 Add more documentation to Context page 2015-11-11 07:06:56 +08:00
Paul O’Shannessy
575d1a5093 Merge pull request #5442 from nickclaw/patch-1
Allow nonce attribute
2015-11-10 14:43:57 -08:00
Paul O’Shannessy
eecd2953cd Merge pull request #5416 from bbrooks/undo-optimistic-update-on-error
Reset state if comment submit fails
2015-11-10 14:42:28 -08:00
Nicholas Clawson
e39f51429b Allow nonce attribute 2015-11-10 10:46:30 -08:00
Jim
d6a547f793 Merge pull request #5403 from yuyokk/patch-1
Clarify note about stable keys
2015-11-10 10:28:49 -08:00
Iurii Kucherov
30ca6619dc State that Math.random() is not a good way to generate keys 2015-11-10 19:02:50 +01:00
Ben Alpert
b4b1adddda Merge pull request #5434 from spicyj/two-reconcile
Handle multiple DOM updates without interference
2015-11-09 17:38:11 -08:00
Ben Alpert
4b80ea23a1 Merge pull request #5433 from spicyj/unmount-children-order
Unmount children before unsetting DOM node info
2015-11-09 17:38:06 -08:00
Ben Alpert
f9a8bdcafe Handle multiple DOM updates without interference
This test failed before! How embarrassing.
2015-11-09 15:22:23 -08:00
Ben Alpert
586653935c Unmount children before unsetting DOM node info 2015-11-09 15:04:57 -08:00
Paul O’Shannessy
10edb83166 Ensure license and patents files are packaged for npm 2015-11-09 12:47:22 -08:00
Jim
95da62765e Merge pull request #5430 from jimfb/changelog-broken-links
Fixed broken links in changelog
2015-11-09 11:28:15 -08:00
jim
5bdb808a46 Fixed broken links in changelog 2015-11-09 11:11:05 -08:00
Jim
a88c39be86 Merge pull request #5424 from stowball/animation-docs-whitespace
Removed unnecessary whitespace before closing bracket
2015-11-09 09:12:49 -08:00
Matt Stow
bc0dc86ae6 Removed unnecessary whitespace before closing bracket 2015-11-09 15:10:01 +11:00
Simone Vittori
c8b8c818b5 ReactShallowRenderer.render returns the rendered output 2015-11-08 13:07:07 +00:00
Ben Brooks
240d7c82cc Reset state if comment submit fails 2015-11-07 13:26:17 -05:00
Ben Alpert
99fbde54a1 Merge pull request #5287 from benhalpern/patch-1
Updated conference page
2015-11-05 13:58:46 -08:00
benhalpern
00eddc2060 Fixed ReactEurope date 2015-11-05 15:33:52 -05:00
Jim
2f7f1a9d45 Merge pull request #5405 from yangshun/inconsistent-error-messages
More consistent error message for findRenderedDOMComponentWithX
2015-11-05 12:03:05 -08:00
Andrew Clark
5fec308d60 Updates the warning that is displayed when setState is called
within either `render` or a component constructor.

Follow up to #5343
2015-11-05 11:12:58 -08:00
Tay Yang Shun
d16754125f More consistent error message for findRenderedDOMComponentWithX 2015-11-06 03:05:08 +08:00
Jim
59dd7b33ee Merge pull request #5391 from zjjw/transition_timeouts
Clear transition timeouts when component unmounts. Fixes #4876
2015-11-05 10:32:18 -08:00
jj
73b496db95 Clear transition timeouts when component unmounts. Fixes #4876 2015-11-05 10:23:15 -08:00
Jim
22b8952fbf Merge pull request #5231 from davidkpiano/patch-1
Updating "JSX Gotchas" docs for Custom Attributes
2015-11-05 09:43:36 -08:00
Jon Hester
aca4ccda35 ReactDOMComponent should throw error when provided children for void elements 2015-11-05 01:52:54 -05:00
Paul O’Shannessy
6d5fe44c86 Merge pull request #5396 from zpao/packagejsons
Improve npm packages' metadata
2015-11-04 21:29:35 -08:00
Paul O’Shannessy
88584a96b7 Generate better readmes for addons npm packages 2015-11-04 21:25:28 -08:00
Paul O’Shannessy
2f6fb746b9 Make sure npm packages have repo and keywords set 2015-11-04 21:25:28 -08:00
chico
a86d25d584 update error messages 2015-11-05 06:12:27 +03:00
Paul O’Shannessy
9b7cc43330 Merge pull request #5352 from chicoxyzzy/eslint-upgrade
remove eslint-disable when possible and update babel-eslint version
2015-11-04 18:17:23 -08:00
chico
b9fd77a4bd update eslint and eslint-plugin-react 2015-11-05 05:14:51 +03:00
chico
4a7456a136 review fixes 2015-11-05 05:11:39 +03:00
chico
8987522a2a remove eslint-disable when possible and update eslint version 2015-11-05 05:11:39 +03:00
Ben Alpert
e131357c23 Merge pull request #5394 from spicyj/tu-shallow-ref
Revert #4993 with an added test for refs
2015-11-04 18:00:27 -08:00
Ben Alpert
9419976e51 Revert #4993 with an added test for refs
We were shallow-rendering a component that used refs at FB so this can't go in as-is. It's a little unclear what we _should_ do though, since there is nothing to hold a ref to (since we're shallowly rendering) and we generally promise that child refs are resolved before a parent's componentDidMount. Also, changing shallow rendering to use the original `_renderValidatedComponent` (instead of `_renderValidatedComponentWithoutOwnerOrContext`) breaks tests because now the `_owner` field doesn't match up for `toEqual` (non-null in `getRenderOutput` but null if constructed in a test).
2015-11-04 17:53:40 -08:00
Paul O’Shannessy
578312e267 Update website for 0.14.2
(cherry picked from commit fdf6f6bbb0)
2015-11-04 17:38:31 -08:00
Paul O’Shannessy
76bbd9e660 Update readme for 0.14.2
(cherry picked from commit 01622a4442)
2015-11-04 17:38:31 -08:00
Paul O’Shannessy
e2fdcb1990 Blog post for 0.14.2
(cherry picked from commit a4fd08973b)
2015-11-04 17:38:31 -08:00
Paul O’Shannessy
cd7387c465 Changelog for 0.14.2
(cherry picked from commit c2dd57c6a6)
2015-11-04 17:38:31 -08:00
Paul O’Shannessy
80af7c7be4 Merge pull request #5353 from chicoxyzzy/patch-1
add Node 5 to devEngines
2015-11-04 15:02:26 -08:00
Jim
4fae036269 Merge pull request #5385 from marocchino/update-korean
Update korean translation to 84af306
2015-11-04 13:57:00 -08:00
Arkist
1c14477a47 Update Korean translation to 84af306 2015-11-05 06:56:48 +09:00
chico
7ae67916cc Adding validation for arrayOf and objectOf in ReactPropTypes 2015-11-05 00:20:33 +03:00
Ben Alpert
35962a0008 Merge pull request #5205 from spicyj/cotree-num
Use incrementing numerical IDs to identify DOM components
2015-11-04 11:41:38 -08:00
Ben Alpert
c193d1a0c2 Don't put IDs in the DOM in createElement mode 2015-11-04 11:39:44 -08:00
Ben Alpert
b80f676d27 Add hooks back for devtools 2015-11-04 11:39:44 -08:00
Ben Alpert
35543c6312 Remove unused modules
- Remove last references to ReactInstanceHandles (still used in responder unit test)
- Remove ClientReactRootIndex/ServerReactRootIndex
2015-11-04 11:39:44 -08:00
Ben Alpert
3cebadaa6b Remove now-unused _rootNodeID from composites 2015-11-04 11:39:44 -08:00
Ben Alpert
e48c8be556 Use incrementing numerical IDs to identify DOM components 2015-11-04 11:39:44 -08:00
Ben Alpert
f06ddf7905 Turn ReactInstanceHandles-test into ReactDOMTreeTraversal-test
This test relied on the fact that ReactDOMComponent still produced hierarchical IDs -- although this module could be used standalone, we're replacing it completely so it makes more sense to just move the tests over to test ReactDOMTreeTraversal.
2015-11-04 11:39:44 -08:00
Ben Alpert
663c4b7d2e Stop relying on hierarchical IDs in ReactDefaultPerf 2015-11-04 11:39:43 -08:00
Ben Alpert
5d94d7d43c Perf: Static children count for wasted time 2015-11-04 11:39:43 -08:00
Ben Alpert
4ba0e95a96 Kill ReactMount.getNode/getID/purgeID with fire 2015-11-04 11:39:43 -08:00
Ben Alpert
796f8c353c put/deleteListener take an instance, not an ID
This removes SimpleEventPlugin's dependency on ReactMount.getID.
2015-11-04 11:39:43 -08:00
Ben Alpert
d11ccd6956 Propagate events based on component tree, not IDs 2015-11-04 11:39:43 -08:00
Ben Alpert
f470cb88f8 Events: Pass native instances up until propagation
Next step: take advantage of having the native instances in EventPropagators instead of converting right back to IDs.
2015-11-04 11:39:43 -08:00
Ben Alpert
6d20556c78 Add functions to find the instance given a node 2015-11-03 17:03:40 -08:00
Ben Alpert
ce528457a4 ReactDOMComponentTree
New module! With this, we have a new module that uses the component tree to store DOM nodes. Most of the logic in this file relates to markup adoption -- if we were to drop that (along with server rendering) this file could just be a `return inst._nativeNode;`.

This works with useCreateElement only because we need to reference each node as it's created.

Events is now the only thing using ReactMount.getNode -- I'll introduce pointers back from the DOM nodes (and a `ReactDOMComponentTree.getInstanceFromNode`) and make that work.
2015-11-03 17:03:40 -08:00
Ben Alpert
5a7c273a1b Always do useCreateElement for updates
Initial render can still be a markup string.
2015-11-03 17:03:40 -08:00
Ben Alpert
276ef737fe Make ReactDOMComponent-test pass with useCreateElement 2015-11-03 17:03:40 -08:00
Ben Alpert
5becbe3f08 Remove obsolete tests with new tree-walking 2015-11-03 17:03:40 -08:00
Ben Alpert
19e2cf5ad5 Make ReactEmptyComponent-test not swallow logs 2015-11-03 17:03:40 -08:00
Kevin Robinson
45c612ed7a Add additional secret property and build for react-dom-server
Update eslintrc, travis build and add task to Gruntfile
2015-11-03 16:39:58 -05:00
Jim
84af306044 Merge pull request #5372 from csbok/patch-1
Update getting-started.ko-KR.md
2015-11-03 03:44:31 -08:00
Ben Alpert
2858bca2e3 Merge pull request #5361 from ali/warn-on-missing-event-handlers
Warn on missing event handler properties
2015-11-02 20:23:20 -08:00
Ali Ukani
9ad4be0316 Warn on missing event handler properties
Fixes #3548. Warns on properties that are case-insensitive matches for
registered event names (e.g. "onclick" instead of "onClick").
2015-11-02 23:13:20 -05:00
Ben Alpert
a4b5f2fffa Merge pull request #5376 from spicyj/gh-4993
Test fixups after #4993
2015-11-02 18:27:25 -08:00
Ben Alpert
c802e9ede9 Test fixups after #4993 2015-11-02 18:26:52 -08:00
Ben Alpert
d2888798f0 Merge pull request #4993 from jsdf/shallow-render-lifecycle
Run all component lifecycle methods when shallow rendering
2015-11-02 18:16:55 -08:00
Ben Alpert
17289020f7 Merge pull request #5356 from rpominov/patch-1
fix shallowRenderer.getRenderOutput() return type in docs
2015-11-02 17:27:08 -08:00
Ben Alpert
5724fca7ae Merge pull request #5358 from conorhastings/invariant-testutils-simulate-shallow-render
#5284 - Show a friendly error when using TestUtils.Simulate with shallow rendering
2015-11-02 17:22:07 -08:00
conorhastings
fbb8d2fe2d Show a friendly error when using TestUtils.Simulate with shallow rendering 2015-11-02 20:14:26 -05:00
Paul O’Shannessy
b9371bc216 Merge pull request #5370 from zpao/babel6docs
Update docs for Babel 6
2015-11-02 16:58:17 -08:00
csbok
2b54e5417d Update getting-started.ko-KR.md
correcting misspelled words
2015-11-03 09:56:41 +09:00
Paul O’Shannessy
bc3b32c968 [docs] Update tooling integration for more babel 6 2015-11-02 13:10:40 -08:00
Paul O’Shannessy
db7ea058e7 [docs] Update Getting Started for babel 6 2015-11-02 12:56:30 -08:00
Paul O’Shannessy
dbab71bbf4 Merge pull request #5350 from ludovicofischer/master
Correct Babel 6 command line usage instructions.
2015-11-02 11:42:44 -08:00
Ben Alpert
ff6714064f adler32: Properly break loop into 4096-char blocks
I believe this was lost in translation in #4400. Can't say I fully understand why this is significant at all though...
2015-11-02 11:29:48 -08:00
Paul O’Shannessy
72a11421d2 Merge pull request #5367 from spicyj/haste-manifest
Add package.json for react-haste package
2015-11-02 11:15:28 -08:00
Paul O’Shannessy
a82400faa2 Merge pull request #5366 from zpao/react-dom-peer-dep
Make React a peerDep of react-dom
2015-11-02 11:14:29 -08:00
Ben Alpert
d44c45f8a5 Add package.json for react-haste package
This will probably go away in a release or two.
2015-11-02 11:03:18 -08:00
Paul O’Shannessy
3c1c02394e Make React a peerDep of react-dom 2015-11-02 10:19:04 -08:00
Roman Pominov
e9f931653d fix shallowRenderer.getRenderOutput() return type in docs 2015-11-01 16:54:41 +03:00
Sergey Rubanov
57b0c8efd0 add Node 5 to devEngines 2015-11-01 04:55:33 +03:00
Ludovico Fischer
6e1f642273 Correct Babel 6 command line usage instructions.
The user should install the babel-cli package, see http://babeljs.io/docs/usage/cli/.
2015-11-01 00:17:16 +01:00
Paul O’Shannessy
88bae3fb73 Merge pull request #5348 from hzoo/patch-2
add docs for babel 6
2015-10-31 12:11:26 -07:00
Henry Zhu
41fc5f21e5 add docs for babel 6 2015-10-31 14:34:20 -04:00
Jim
bbffc36534 Merge pull request #5344 from chicoxyzzy/update-rcc
maskedContext should not be instantiated as null
2015-10-30 18:23:55 -07:00
chico
8a9039891b maskedContext should not be instantiated as null 2015-10-31 04:05:44 +03:00
Ben Alpert
c525732147 Merge pull request #5023 from spicyj/jsc-perf
Add rudimentary jsc perf-counters runner
2015-10-30 17:06:30 -07:00
Paul O’Shannessy
b5d90f8c6b Merge pull request #5331 from tbroadley/typescript-test-windows
Fix for TypeScript test on Windows
2015-10-30 15:45:51 -07:00
Thomas Broadley
d77e161f99 use path library to normalize filepath 2015-10-31 07:38:47 +09:00
Jim
a2d26c82ea Merge pull request #5093 from jimfb/avoid-children-to-string-coercion
Should not coerce children prop on custom elements to a string.  Fixes #5088
2015-10-30 13:42:05 -07:00
Jim
0c790baf31 Merge pull request #5341 from zpao/domprop-integrity
Add integrity to HTML property config
2015-10-30 13:39:17 -07:00
Paul O’Shannessy
68eb1a6fb6 Add integrity to HTML property config 2015-10-30 13:35:51 -07:00
Jim
86fc94750a Should not coerce children prop on custom elements to a string. Fixes #5088 2015-10-30 13:33:21 -07:00
Paul O’Shannessy
bd6417e24e Merge pull request #5293 from chicoxyzzy/update-deps
update dependancies
2015-10-30 13:25:31 -07:00
Paul O’Shannessy
3d75a4234d Merge pull request #5339 from jimfb/contributing-first-bug
Added a note about finding a good-first-bug
2015-10-30 12:10:22 -07:00
Jim
6fd7892a4d Added a note about finding a good-first-bug 2015-10-30 11:05:49 -07:00
chico
38b80b5b37 update deps 2015-10-30 16:34:39 +03:00
Paul O’Shannessy
761921499c Merge pull request #5049 from xelad1/patch-1
Fixed unclear wording in comment
2015-10-29 23:21:05 -07:00
Alex Dajani
aa6fcf902c Fixed unclear wording in comment
Perhaps not understanding what "key a set a fragment..." is supposed to mean.  Hopefully I'm not misreading this as a typo.
2015-10-29 23:20:18 -07:00
Paul O’Shannessy
c35b4384f7 Merge pull request #5235 from wincent/update-blog-syntax
Update syntax in older Relay blog post that may be causing confusion
2015-10-29 23:14:19 -07:00
Paul O’Shannessy
f02584d807 Merge pull request #5300 from zpao/lint-eqeqeq
[lint] Make eqeqeq a failure
2015-10-29 23:06:44 -07:00
Jim
0ef5112e89 Merge pull request #5334 from facebook/revert-5320-overwrite_props
Revert "Overwriting of mutated props in constructor"
2015-10-29 22:47:35 -07:00
Sebastian Markbåge
d914f15c0e Revert "Overwriting of mutated props in constructor" 2015-10-29 22:36:38 -07:00
Christoph Pojer
1384d43f53 Merge pull request #5321 from cpojer/update-tests
Update tests
2015-10-29 18:42:12 -07:00
Thomas Broadley
d80710b0ae fix for TypeScript test on Windows 2015-10-30 10:22:50 +09:00
Jim
d15e2fcd8e Merge pull request #5320 from drdelambre/overwrite_props
Overwriting of mutated props in constructor
2015-10-29 18:15:52 -07:00
Alex Boatwright
cc09ed940f classes in the tests when can 2015-10-29 18:11:28 -07:00
Paul O’Shannessy
12c214a992 Merge pull request #5328 from zpao/non-native-event-name-dispatch
Use a custom event type for our event dispatching in ReactErrorUtils
2015-10-29 17:54:18 -07:00
Sławomir Laskowski
f00d45d65f Fix shallow renderer with ref as function 2015-10-30 00:23:24 +01:00
cpojer
ac17bdaaba Remove generateFromMetadata and getMetadata usage. 2015-10-29 15:45:30 -07:00
Paul O’Shannessy
606aa61209 Merge pull request #5327 from zpao/definepropgetter
Use a getter for canDefineProperty check.
2015-10-29 15:41:02 -07:00
Paul O’Shannessy
29523d0113 Use a custom event type for our event dispatching in ReactErrorUtils
It turns out that IE doesn't like when native events types are used. There may
have been more involved at play but this fixes the issue.
2015-10-29 15:39:14 -07:00
Paul O’Shannessy
d95a2239a8 Use a getter for canDefineProperty check.
This ensures that we treat es5-sham as a broken implementation of defineProperty and we won't try to use it.
2015-10-29 15:17:50 -07:00
Paul O’Shannessy
b8f502b224 Merge pull request #5326 from tbroadley/grunt-lint-windows
Fix for 'grunt lint' on Windows
2015-10-29 14:51:21 -07:00
Thomas Broadley
c0f0d12f96 'grunt lint' now works on Windows 2015-10-30 06:43:43 +09:00
cpojer
2ecfc4f8fb Codemod old APIs away. 2015-10-29 12:40:52 -07:00
cpojer
9d25303d89 Update jest. 2015-10-29 12:40:52 -07:00
Alex Boatwright
c341269ab2 simple fix to prevent overwriting of mutated props 2015-10-28 23:37:29 -07:00
Jim
01341480c2 Merge pull request #5317 from nickbalestra/patch-1
Update 02.1-jsx-in-depth.md
2015-10-28 22:13:57 -07:00
Jim
fbf4cbbae6 Merge pull request #5316 from Third9/master
update Korean docs to 0.14
2015-10-28 21:43:16 -07:00
Nick Balestra
2257d8aa76 Update 02.1-jsx-in-depth.md
Update 02.1-jsx-in-depth.md
2015-10-28 20:14:02 -07:00
KwonH
afc118e3c4 update Korean docs to 0.14
Update getting-started in Korean
2015-10-29 11:51:52 +09:00
Paul O’Shannessy
ee06df1ac5 Bring over updates for 0.14.1 release
Update changelog for 0.14.1

(cherry picked from commit aaf8f870cb)

Update readme for 0.14.1

(cherry picked from commit c2dde8df0b)

0.14.1 blog post

(cherry picked from commit 6e2450e8f2)

Update website for 0.14.1

(cherry picked from commit f0782e2b2e)
2015-10-28 14:43:56 -07:00
Ben Alpert
a65a4851c6 Merge pull request #5309 from spicyj/bench
Add a simple initial-render benchmark test case
2015-10-28 13:58:50 -07:00
Ben Alpert
e849819cb6 Add a simple initial-render benchmark test case 2015-10-28 13:14:24 -07:00
Paul O’Shannessy
2c176da7e8 Merge pull request #5304 from evanvosberg/master
Add non-standard property for supporting Safari mask-icon.
2015-10-28 10:28:21 -07:00
Evan Vosberg
f8b4affb87 Add non-standard property for supporting Safari mask-icon.
See also: https://developer.apple.com/library/prerelease/mac/releasenotes/General/WhatsNewInSafari/Articles/Safari_9.html#//apple_ref/doc/uid/TP40014305-CH9-SW20
2015-10-28 17:35:43 +01:00
Paul O’Shannessy
ad00a6e672 [lint] Make eqeqeq a failure 2015-10-27 15:39:54 -07:00
Ben Alpert
b0a7a00dba Merge pull request #5237 from spicyj/gh-5125
Make sure top-level callback has correct context
2015-10-27 13:26:45 -07:00
Ben Alpert
7f205e9c1b Make sure top-level callback has correct context
Closes #5125 -- incorporates essentially the same fix with a much simpler test case. Thanks @yiminghe for reporting!
2015-10-27 13:11:45 -07:00
Ben Alpert
65b9ceb4f8 Merge pull request #5209 from antoaravinth/5189
Don't instrument listeners for ReactDefaultPerf
2015-10-27 11:59:02 -07:00
Paul O’Shannessy
517872817f Merge pull request #5297 from quadrupleslap/master
Mangle __html in prop validation.
2015-10-27 09:40:29 -07:00
Ram Kaniyur
ad654ceb66 Took keyOf outside the function. 2015-10-28 00:48:54 +11:00
Ram Kaniyur
e26666fb1e Mangle __html in prop validation. 2015-10-28 00:18:00 +11:00
Ants
59db07c4f9 Fix for the issue #5189
Fix for lint issues

Added the test cases for the issue 5189

Removing empty space

Removing the Eventplugin instrumentation code

Removing unwanted white space
2015-10-27 16:33:22 +05:30
Ben Alpert
e603644255 Merge pull request #5291 from spicyj/afu-cycle
Fix cycle in AutoFocusUtils
2015-10-26 15:03:15 -07:00
Ben Alpert
f558b95584 Fix cycle in AutoFocusUtils
In 5c5d2ec182 I accidentally introduced a dependency cycle:

AutoFocusUtils -> findDOMNode -> ReactDOMComponent -> AutoFocusUtils

This breaks some tools internally. We're not actually using findDOMNode in AutoFocusUtils any more so we can just delete it.
2015-10-26 14:52:23 -07:00
Paul O’Shannessy
0f76873ebb Merge pull request #5289 from jonathanp/patch-1
Update 2015-05-01-graphql-introduction.md
2015-10-26 14:19:48 -07:00
jpersson
e2267613ac Update 2015-05-01-graphql-introduction.md 2015-10-26 17:14:11 -04:00
Jonathan Persson
924cddc505 Update 2015-05-01-graphql-introduction.md 2015-10-26 16:32:11 -04:00
benhalpern
a51ef94384 Updated conference info 2015-10-26 16:20:57 -04:00
Ben Alpert
055ecd7f14 Merge pull request #5266 from spicyj/lt-fix-2
Three more fixes for document.createElement mode
2015-10-26 11:41:27 -07:00
Paul O’Shannessy
d17ad0f0c0 Merge pull request #5089 from thomasp9/patch-1
Create 01-why-react.de-DE.md
2015-10-26 10:14:16 -07:00
Patrick
0508a07446 Create 01-why-react.de-DE.md
Translation of 01-why-react.de-DE.md to German
2015-10-26 10:13:45 -07:00
Paul O’Shannessy
0ddc0817e4 Merge pull request #5252 from zpao/eslintlock
[lint] Lock eslint version
2015-10-26 10:12:52 -07:00
Paul O’Shannessy
11919b6d90 Merge pull request #5286 from translucens/add_reactdom_js
Add react-dom.js to tutorials
2015-10-26 09:24:54 -07:00
translucens
73ec3713b3 Add react-dom.js to tutorials 2015-10-26 22:23:50 +09:00
Ben Alpert
22a240fd39 Avoid lastProps[key] lookup in initial render
This makes both Firefox and IE 15-20% faster in initial render (!!). On my PE benchmark, createElement is now on par with HTML in Firefox and faster in IE11 (before, it was slower).
2015-10-24 12:19:30 -07:00
Paul O’Shannessy
56c91248fd Merge pull request #5274 from SpartaSixZero/master
Corrected highlighted line in tutorial example in tutorial7.js
2015-10-24 12:19:28 -07:00
Mark Sun
2f48cc4327 Corrected highlighted line in tutorial example in tutorial7.js 2015-10-24 15:01:14 -04:00
Jim
75e9045719 Merge pull request #5268 from dnshi/update-readme
Update README's example
2015-10-24 06:29:06 -10:00
Dean Shi
2b136a4f84 Update README's example
According to current React version, when I use `React.render`, console shows `React.render is deprecated. Please use ReactDOM.render from require('react-dom') instead.`.

So this PR is a tiny update for the README example.
2015-10-24 00:59:05 -07:00
Ben Alpert
6269ef62cf Two more fixes for document.createElement mode
Is this all of them? I hope so.

- Set text content after creating hierarchy, like the text is a child. I should've done this originally but I guessed it wouldn't matter. I was wrong (~20% perf difference in IE11).
- IE throws when setting an enum-like property to an invalid value. I tried setting every property to the string 'a' and changed the ones that threw to be MUST_USE_ATTRIBUTE. I think these are all correct -- encType is the most suspicious one based on the existing comments but I tested in IE8 and it works fine as an attribute.
2015-10-23 22:46:02 -07:00
Ben Alpert
8aaa66c292 Merge pull request #5263 from spicyj/npmreactreadme
Update addons paths in npm react README
2015-10-23 17:36:23 -07:00
Ben Alpert
3a0ab000bf Update addons paths in npm react README 2015-10-23 17:31:01 -07:00
Ben Alpert
4106251316 Merge pull request #5261 from spicyj/dom-null-undef
Bug fixes for createElement mode
2015-10-23 15:56:21 -07:00
Ben Alpert
939c7596ad Merge pull request #5253 from spicyj/dt-lazy
Perf: Insert nodes top-down in IE and Edge
2015-10-23 15:56:08 -07:00
Ben Alpert
b447b40958 Use attributes to set .type
According to the internet, this should work and it appears to work fine on all the browsers I tested.
2015-10-23 12:08:10 -07:00
Ben Alpert
7221e1b2e9 Don't set DOM props when switching between unset/undefined/null 2015-10-23 11:52:29 -07:00
Ben Alpert
263ca4792e Perf: Insert nodes top-down in IE and Edge 2015-10-23 10:59:27 -07:00
Paul O’Shannessy
4d41cf740a Merge pull request #5250 from conorhastings/track-default-property
add default attribute for use with track element
2015-10-22 20:20:44 -07:00
Paul O’Shannessy
a79fcd7a7f [lint] Lock eslint version
The automatic updating really sucks here as bugs are fixed / behavior of rules changes. Local versions are updated, cached versions on Travis aren't. It's messy. Now we must explicitly update for any thing to change.
2015-10-22 20:15:25 -07:00
Paul O’Shannessy
be6bd3404e Merge pull request #5236 from spicyj/eslint-17
Fix lint for eslint 1.7
2015-10-22 19:59:26 -07:00
conorhastings
bb3a326ecd add default attribute for use with track element 2015-10-22 22:47:17 -04:00
Ben Alpert
b106e96864 Fix lint for eslint 1.7 2015-10-21 14:48:47 -07:00
Ben Alpert
7b97d8d58f Merge pull request #5233 from yiminghe/fix-typo
fix wrong method name
2015-10-21 14:33:38 -07:00
Greg Hurrell
1bcd6804f3 Update syntax in older Relay blog post that may be causing confusion
Just seen on Stack Overflow a question that suggests people may be
confused if they run across some of the old syntax in one of our old
blog posts:

http://stackoverflow.com/questions/33261751/why-does-relay-ql-result-in-unterminated-string-constant-error/

Ideally people would consult the (up-to-date) documentation instead, and
we don't want to have to maintain old blog posts, but in this case the
cost of updating the syntax was low so I just went ahead and did it.
2015-10-21 11:53:22 -07:00
Jim
1dafac9e0c Merge pull request #5230 from kohashi/patch-1
Fix tutorial.ja-JP.md
2015-10-21 07:46:17 -10:00
yiminghe
85fc28624c fix wrong method name 2015-10-22 00:29:22 +08:00
David Khourshid
29939b7270 Updating "JSX Gotchas" docs for Custom Attributes
Adds note that custom attributes are supported on custom elements.
2015-10-21 08:18:48 -04:00
kohashi85
ce002e61b1 Update tutorial.ja-JP.md 2015-10-21 17:04:08 +09:00
Paul O’Shannessy
a468eed33f Merge pull request #5217 from zpao/rm-react-codemod
Move react-codemod to standalone repo
2015-10-20 15:46:49 -07:00
Paul O’Shannessy
8848984c46 Update blog posts linking to react-codemod 2015-10-19 14:39:40 -07:00
Paul O’Shannessy
caece8b4b7 Remove react-codemod 2015-10-19 14:31:31 -07:00
Paul O’Shannessy
5bd04cf259 Merge pull request #5154 from cmatheson/master
add npm 3.x to devengines
2015-10-19 13:52:20 -07:00
Paul O’Shannessy
fc96f31fad Merge pull request #5185 from yungsters/invariant
Remove "Invariant Violation: " from Invariant Error Messages
2015-10-19 12:07:59 -07:00
Paul O’Shannessy
244dd5da4c Merge pull request #5214 from benigeri/patch-1
small edit on reactiflux blog post
2015-10-19 12:03:01 -07:00
Paul Benigeri
7aac368253 small edit on reactiflux blog post 2015-10-19 12:01:47 -07:00
Ben Alpert
3d7def0b48 Merge pull request #5213 from spicyj/gh-5187-f
Follow-ups to #5187
2015-10-19 11:19:10 -07:00
Ben Alpert
545f31741e Follow-ups to #5187 2015-10-19 11:15:02 -07:00
Paul O’Shannessy
8f1ce99cc3 Fix up stray markdown in blog post 2015-10-19 10:23:28 -07:00
Christopher Chedeau
2a7d054bfc Merge pull request #5211 from vjeux/reactiflux
Reactiflux is moving to Discord blog post
2015-10-19 07:42:40 -07:00
Christopher Chedeau
db7522f2c5 Reactiflux is moving to Discord blog post 2015-10-19 07:35:46 -07:00
Jim
9cb01de1bc Merge pull request #5203 from WanderWang/docs-cn
update Chinese docs to 0.14
2015-10-18 09:38:18 -07:00
WanderWang
1044d4c7d5 update Chinese docs to 0.14 2015-10-19 00:34:04 +08:00
Jim
dd3c4474d1 Merge pull request #4051 from jquense/ie-noisy-input-event
opt out of input events for ie 10 and 11
2015-10-18 09:26:52 -07:00
Ben Alpert
617f03518a Merge pull request #5192 from spicyj/ev-ind
Remove unnecessary indirection in events
2015-10-16 21:43:09 -07:00
Jim
7a164fd3a0 Merge pull request #5187 from tomduncalf/support_invalid_event-issue_5152
Add support for "invalid" event within Form elements
2015-10-16 18:02:18 -07:00
Timothy Yung
278939ec58 Upgrade dependency fbjs@0.4.0 2015-10-16 16:10:06 -07:00
Timothy Yung
cdaea311a3 Remove "Invariant Violation: " from Invariant Error Messages 2015-10-16 16:09:28 -07:00
Jim
98c96b6460 Merge pull request #5199 from jimfb/number-found
Print number of matches (previously unclear if zero or multiple)
2015-10-16 13:00:49 -07:00
Jim
e0904a0a90 Print number of matches (previously unclear if zero or multiple) 2015-10-16 13:00:10 -07:00
Jim
3260b00385 Merge pull request #5195 from trickford/patch-1
Specify focus events work on all elements in the React DOM
2015-10-16 11:50:22 -07:00
Ben Alpert
e67ceae1ad Merge pull request #5198 from spicyj/gh-5071a
Fix buggy DOM nesting warning for text components
2015-10-16 11:42:20 -07:00
Ben Alpert
f7816cdbfe Fix buggy DOM nesting warning for text components
cf. #5071
2015-10-16 11:36:16 -07:00
Jim
0fc8f6ade3 Merge pull request #5193 from conorhastings/enqueue-callback-error
update enqueueCallback invariant to more specifically denote type of passed callback
2015-10-16 09:39:56 -07:00
Rick Ford
3d4e8affcd Specify focus events work on all elements in the React DOM
Generally, focus/blur events only apply to focusable elements found in forms. In React, you can listen to focus/blur events on any element.
2015-10-16 11:02:04 -05:00
conorhastings
20ec78d9f0 update enqueueCallback invariant to more specifically explain what caused error 2015-10-16 11:57:08 -04:00
jquense
b5e7a8447c opt out of input events for ie 10 and 11
while supported then Input event is too noisy in IE. Firing on
placeholder sets, and when an input is focused with a placeholder.

fixes #3377 and fixes #3484
2015-10-16 11:28:36 -04:00
Ben Alpert
ef95128ae2 Remove unnecessary indirection in events 2015-10-15 20:13:14 -07:00
Paul O’Shannessy
ed7ab7b94a Merge pull request #5176 from jimfb/tweak-props-change-wording
Tweak wording when talking about props changing
2015-10-15 12:21:14 -07:00
Paul O’Shannessy
e12ee95e09 [docs] Don't make authors links on all posts page 2015-10-15 12:18:15 -07:00
Tom Duncalf
5ceb22953c Add support for "invalid" event within Form elements
Fixes #5152
2015-10-15 20:15:34 +01:00
Paul O’Shannessy
ccfc2d8049 Merge pull request #5178 from jimfb/multiple-authors
Fix blog post authors
2015-10-15 12:04:56 -07:00
Paul O’Shannessy
95afe4608f Merge pull request #5184 from zpao/fix-style-issues
Fix indentation issues
2015-10-15 11:55:37 -07:00
Paul O’Shannessy
0dc6596dc2 Fix indentation issues 2015-10-15 09:29:28 -07:00
Jim
b735dd4ab4 Merge pull request #5048 from antoaravinth/PR-5013
Issue: 5013 Added necessary code for firing warning if value is null
2015-10-14 23:06:54 -07:00
Ants
b42c1dafcc Issue: 5013 Added necessary code for firing warning if value is null
Fixed the lint issues

Added logic for handling the warning only once and added the test cases for the same. Also moved the warning part to only DEV mode

Changed few lines related to the formatting issues

Removing the empty whitespace
2015-10-15 10:13:35 +05:30
Jim
5ae4f035c7 Fix blog post authors 2015-10-14 18:01:33 -07:00
Ben Alpert
8168c8eac6 Merge pull request #5175 from spicyj/text-no-frag
Don't test frag cases in ReactMultiChildText-test
2015-10-14 16:07:11 -07:00
Jim
c47d2cfada Tweak wording when talking about props changing 2015-10-14 14:43:09 -07:00
Paul O’Shannessy
8e9682c542 Merge pull request #5174 from zpao/dom-attributes-track
Add srcLang and kind to better support track elements
2015-10-14 14:35:03 -07:00
Ben Alpert
5f8fe7d614 Don't test frag cases in ReactMultiChildText-test
These are now just testing the same as the array cases directly above. This should make this test a bunch faster because it (intentionally) has n^2 runtime.
2015-10-14 14:31:45 -07:00
Ben Alpert
8e67b7f624 Merge pull request #4988 from spicyj/fdn
Walk down internal tree to find DOM node
2015-10-14 14:31:28 -07:00
Ben Alpert
5c5d2ec182 Walk down internal tree to find DOM node
This reduces our reliance on hierarchical IDs.
2015-10-14 14:22:53 -07:00
Paul O’Shannessy
659172df50 Add srcLang and kind to better support track elements 2015-10-14 12:05:56 -07:00
Jim
555fd46c7e Merge pull request #5140 from pluma/patch-1
Fix #1357. Don't append "px" suffix to CSS string values.
2015-10-14 11:18:53 -07:00
Alan Plum
a299a366ce Fix #1357. Warn when appending "px" to strings. 2015-10-14 18:36:24 +02:00
Sebastian Markbåge
da1135618e Merge pull request #5166 from spicyj/gh-5157
Add feature test for document.createEvent
2015-10-14 00:08:56 -07:00
Ben Alpert
4f9fdeeec1 Merge pull request #5165 from spicyj/cache-lenient
Be more lenient with invalid nodes in the cache
2015-10-13 17:22:12 -07:00
Ben Alpert
1206d8d2eb Add feature test for document.createEvent
See #5157.
2015-10-13 16:34:05 -07:00
Ben Alpert
e89e675508 Be more lenient with invalid nodes in the cache
This matches our old behavior. I was a little too aggressive in turning on this
error and it's still possible to trigger it (using the test added here).
2015-10-13 16:07:06 -07:00
Paul O’Shannessy
af99b2c2a3 Merge pull request #5164 from zpao/fix-csstransitiongroup-proptype
Correctly handle 0 in CSSTransitionGroup timeout props
2015-10-13 14:54:21 -07:00
Paul O’Shannessy
dc21b95244 Correctly handle 0 in CSSTransitionGroup timeout props 2015-10-13 14:39:55 -07:00
Ben Alpert
dddbca472a Merge pull request #5160 from spicyj/gh-5151
Fetch node to unmount separately from unmounting
2015-10-13 12:19:24 -07:00
Ben Alpert
622db4ee4f Fetch node to unmount separately from unmounting
My last strategy of getting each node recursively while unmounting was a pain to make work properly with ReactMount's confusing cache. Now, we get the node before unmounting anything in the subtree (and we don't try to find the nodes of descendants).

This is a temporary solution and can go away when we get rid of the giant ReactMount node hash map.

Fixes #5151.
2015-10-13 12:07:57 -07:00
Ben Alpert
194ab16d7b Merge pull request #5157 from spicyj/createevent
Use 'document.createEvent' not 'new Event'
2015-10-13 11:40:35 -07:00
Paul O’Shannessy
51c0f86ec7 Merge pull request #5147 from zpao/update-release-task
Stop generating gh-pages during release, update message
2015-10-13 11:20:40 -07:00
Ben Alpert
6488a4c187 Use 'document.createEvent' not 'new Event'
Fixes #5153.

This seems to work in all browsers I tested, including old Android and all IE > 8 which didn't work before.
2015-10-13 11:14:23 -07:00
Ben Alpert
50c9b94552 Merge pull request #5156 from spicyj/bp-codemods
Mention codemods more prominently in release blog
2015-10-13 10:50:38 -07:00
Ben Alpert
4a37796f88 Mention codemods more prominently in release blog 2015-10-13 10:37:42 -07:00
Paul O’Shannessy
f7a3ac2d56 Stop generating gh-pages during release, update message 2015-10-13 09:37:32 -07:00
Cameron Matheson
2c1c7fad4d add npm 3.x to devengines 2015-10-13 02:06:48 -06:00
Jim
bffed177f4 Merge pull request #5150 from jimfb/node-v4-readme
Updated node version requirement in README.md
2015-10-12 18:07:29 -07:00
Jim
e46e5784ce Updated node version requirement in README.md 2015-10-12 18:06:06 -07:00
Jim
c1c9b383a0 Merge pull request #5137 from vipulnsward/2576-add-comparison-tests
Added tests to compare testing of components using different types of element creation
2015-10-12 14:08:08 -07:00
Vipul A M
b4a6bc89c2 - Added tests to compare testing of components using different types of element creation
Fixes [#2576]

- Fixed Lint warnings and errors
2015-10-12 16:44:00 -04:00
Ben Alpert
b32835ea61 Merge pull request #5146 from spicyj/ce-scripts
Don't execute <script> tags w/ createElement mode
2015-10-12 13:43:51 -07:00
Ben Alpert
db989bf686 Don't execute <script> tags w/ createElement mode
Each script will execute at most once so we could also set `.textContent` to something like `;`, then add it to the document, then change the `.textContent`, but this seems like the simplest approach. See http://dev.w3.org/html5/spec-preview/the-script-element.html for details.
2015-10-12 13:43:40 -07:00
Jim
37c71a6e1f Merge pull request #5142 from MaxPRafferty/add-selection-and-composition-events-on-reference-page
Add selection and composition events on reference page
2015-10-12 13:37:56 -07:00
maxprafferty
48ada00bdb added selection and composition events to reference page
added composition events to reference page

added selection events to reference page
2015-10-12 15:44:44 -04:00
Paul O’Shannessy
abaf0051de Merge pull request #5124 from bhamodi/master
Documentation Cleanup Round 1.
2015-10-12 12:34:54 -07:00
Baraa Hamodi
45d4296ac5 Documentation cleanup. 2015-10-12 15:33:32 -04:00
Paul O’Shannessy
875e2b36cc Merge pull request #5144 from zpao/grunt-gulp-windows
Use the right gulp executable on Windows
2015-10-12 12:28:21 -07:00
Ben Alpert
b03b195759 Merge pull request #5130 from matiassingers/jasmine-spy-call-args-consistency
Jasmine spies call args property consistency
2015-10-12 10:24:56 -07:00
Paul O’Shannessy
227ba42f81 Use the right gulp executable on Windows 2015-10-12 10:01:23 -07:00
Jim
e45e46a567 Merge pull request #5141 from pluma/patch-2
Removed ESLint warning
2015-10-12 09:59:17 -07:00
Alan Plum
0e451162bc Removed eslint warning. 2015-10-12 17:42:38 +02:00
Matias Singers
f8f2be05ce Consistently use calls[n].args[n] instead of argsForCall[n][n] for Jasmine spies 2015-10-12 22:39:19 +08:00
Ben Alpert
01817c143c Merge pull request #5129 from matiassingers/jasmine-spy-calls-length-consistency
Jasmine spies call count property consistency, take II
2015-10-11 15:03:27 -07:00
Matias Singers
dd0b1a643b Consistently use calls.length instead of callCount for Jasmine spies, take II
See #3105 for take I
2015-10-11 15:42:24 +08:00
Paul O’Shannessy
5dc2858bc9 Merge pull request #5126 from bhamodi/white-space
File Cleanup.
2015-10-10 19:30:29 -07:00
Paul O’Shannessy
0b21632f8e Merge pull request #5123 from vipulnsward/fix-html-jsx-page
- Bring back JSX compiler styling still being used on HTML JSX page
2015-10-10 19:11:26 -07:00
Baraa Hamodi
a86e349535 File Cleanup. 2015-10-10 16:05:58 -04:00
Vipul A M
2b81ea0d20 - Bring back JSX compiler styling still being used on HTML JSX page
Fixes [#5121]
2015-10-10 13:53:59 -04:00
Jim
0b29035484 Merge pull request #5120 from abloomston/patch-1
Include react-dom
2015-10-10 07:35:19 -07:00
Adam Bloomston
ab1be09d7d Include react-dom
Fixes `Uncaught ReferenceError: ReactDOM is not defined`
2015-10-10 10:17:08 -04:00
Paul O’Shannessy
be90351add Update Readme with for 0.14 2015-10-09 17:48:44 -07:00
Jim
5c3e99c7f4 Merge pull request #5116 from jimfb/download-page-links
Added react-dom to individual downloads
2015-10-09 15:17:08 -07:00
Jim
f6e09f1903 Added react-dom to individual downloads 2015-10-09 15:11:11 -07:00
Ben Alpert
fb9e1ed475 Merge pull request #5014 from spicyj/native-parents
Thread native-parent pointers through everything
2015-10-09 15:07:59 -07:00
Ben Alpert
8210299437 Add SVG/MathML support for createElement mode 2015-10-09 14:56:57 -07:00
Ben Alpert
1dca72ebfa Thread native-parent pointers through everything
Now we don't repurpose context for our own secret needs (hi Dan). In this diff I avoid storing the native parent on native (DOM) components and store it only on composites, but we'll probably want to store it on native components too soon for event bubbling.
2015-10-09 14:56:08 -07:00
Ben Alpert
a907da9430 Make Danger-test simpler and more robust 2015-10-09 14:54:42 -07:00
Ben Alpert
4e48c67120 Merge pull request #5113 from spicyj/document-context
Document context
2015-10-09 14:46:56 -07:00
Ben Alpert
28b10a9d6a Document context
Fixes #580.
2015-10-09 14:44:24 -07:00
Paul O’Shannessy
09b688efce [docs] Fix line highlights for linked-state-mixin 2015-10-09 12:32:01 -07:00
Jim
15c731edca Merge pull request #5109 from Josh-a-e/undefined_this_on_controlled_components
add test to show `this` is indeed undefined - closes #3613
2015-10-09 11:44:19 -07:00
Ben Alpert
d95381387e Merge pull request #5111 from spicyj/vdn-current
validateDOMNesting: parentTag -> current
2015-10-09 11:43:31 -07:00
Ben Alpert
9c836b09f2 validateDOMNesting: parentTag -> current 2015-10-09 11:40:55 -07:00
Joshua Evans
8f4c2997a0 add test to show this is indeed undefined - closes #3613 2015-10-09 19:37:58 +01:00
Jim
845135531a Merge pull request #5105 from jimfb/changelog-0.14
Added changelog for 0.14
2015-10-09 10:51:36 -07:00
Paul O’Shannessy
3359e2f64c Merge pull request #5101 from bcbcb/patch-1
[docs] fix forms Default Value example
2015-10-09 10:47:01 -07:00
Jim
e8be7013ba Merge pull request #4981 from iamchenxin/zh_docs
[docs] Sync up tutorial.zh-CN with en(a440f40)
2015-10-09 10:46:16 -07:00
iamchenxin
a8459214d1 [docs] Sync up tutorial.zh-CN with en(a440f40)
[docs] Amend wrong words in zh-CN

08.1-more-about-refs.zh-CN.md

Update zh-CN docs

add thinking-in-react.zh-CN.md

[docs] Update two zh-CN docs

       new file:   ref-01-top-level-api.zh-CN.md
       new file:   ref-02-component-api.zh-CN.md
2015-10-10 01:35:03 +08:00
Jim
72e70f345b Added changelog for 0.14 2015-10-09 10:26:18 -07:00
Ben Alpert
407e88d6c8 Merge pull request #5107 from mbrookes/patch-1
Grammar
2015-10-09 08:59:47 -07:00
Matt Brookes
98aecac34c Grammar
I'm assuming this was meant to say that the JSX spread syntax saves typing, not copying attributes.
2015-10-09 14:31:59 +01:00
Jim
1a7c0a4b16 Merge pull request #5102 from TracyJordan/master
Fixed some comment punctuation in ReactDOMComponent.js
2015-10-09 00:33:39 -07:00
Kevin Cheng
ff17bc25d1 Fixed punctuation 2015-10-08 19:36:05 -07:00
Brenard Cubacub
d96f319d6e [docs] fix forms Default Value example
The Default Value section in the forms docs says "This example will function much like the Controlled Components example above."

The example actually functions like the Uncontrolled Components example, not the Controlled Components example.
2015-10-08 16:41:19 -07:00
Ben Alpert
f522371cee Merge pull request #5100 from spicyj/ssr-dupe
Remove duplication in ReactServerRendering
2015-10-08 15:11:34 -07:00
Ben Alpert
d4420eca8a Remove duplication in ReactServerRendering 2015-10-08 15:06:09 -07:00
Ben Alpert
3f5747009d Merge pull request #5083 from spicyj/warn-min
Warn when using a minified copy of dev React
2015-10-08 14:08:50 -07:00
Paul O’Shannessy
c511f161df Merge pull request #5096 from songawee/docs_babel_fix
fix(docs): adjust babel release to match the babel.js changelog
2015-10-08 11:52:42 -07:00
Ben Alpert
f3a506bc0c Warn when using a minified copy of dev React
Fixes #4842.
2015-10-08 11:44:56 -07:00
songawee
8fb436a5eb fix(docs): adjust babel release to match the babel.js changelog 2015-10-08 12:44:24 -06:00
Ben Alpert
2253405dcc Merge pull request #5085 from spicyj/cdp
Extract defineProperty feature testing to one file
2015-10-08 11:33:07 -07:00
Ben Alpert
4fb39ce984 Merge pull request #5081 from spicyj/svg-tu
Don't break on SVG tags in scryRenderedDOMComponentsWithClass
2015-10-08 08:38:32 -07:00
Ben Alpert
4bb83d237e Don't break on SVG tags in scryRenderedDOMComponentsWithClass
Fixes #5076.
2015-10-08 08:29:53 -07:00
Ben Alpert
e9796cc447 Merge pull request #5084 from spicyj/rearrange-utils
Move escapeTextContentForBrowser and quoteAttributeValueForBrowser to DOM directory
2015-10-08 08:28:40 -07:00
Ben Alpert
3fb2d3f5d4 Extract defineProperty feature testing to one file
This makes it slightly more bearable to debug in IE8 with an exception breakpoint. Also the old way was just silly and could mask other bugs.
2015-10-07 18:33:13 -07:00
Ben Alpert
2637a8eaf4 Move escapeTextContentForBrowser and quoteAttributeValueForBrowser to DOM directory
Only DOM files use these.
2015-10-07 18:11:15 -07:00
Ben Alpert
a7189c57fc Merge pull request #5057 from camsong/patch-1
Text fix in ReactClass.js
2015-10-07 17:19:19 -07:00
Cam Song
9af15d3ecd Text fix in ReactClass.js
Rename 'component class' to 'function' as it should be.
2015-10-08 08:13:27 +08:00
Ben Alpert
0d12643652 Merge pull request #5078 from nickpresta/master
Add docs for `React.Children.toArray` in 0.14.0.
2015-10-07 17:02:06 -07:00
Nick Presta
319b374097 Add docs for React.Children.toArray in 0.14.0.
* Update the docs to change return type of `React.Children.map` from `object` to `array`.
2015-10-07 19:16:05 -04:00
Jim
d0970ee8b8 Merge pull request #5063 from facebook/revert-5062-revert-4959-no-shams
Remove dependence on ES5 shams per #4189
2015-10-07 14:23:35 -07:00
Jim
f97d759db1 Merge pull request #5032 from jimfb/remove-react-link
Added warning for use of ReactLink.
2015-10-07 14:23:11 -07:00
Ben Alpert
40cce38330 Merge pull request #5075 from spicyj/docs-downloads
Update downloads page for 0.14
2015-10-07 13:04:41 -07:00
Ben Alpert
f31a46cb18 Merge pull request #4983 from spicyj/id-swap
Refactor how composite type changes work, fix memory leak in ReactMount caching
2015-10-07 13:02:58 -07:00
Ben Alpert
34d84a36d6 Merge pull request #5066 from camsong/patch-2
Always use ANONYMOUS const in  ReactPropTypes.js
2015-10-07 12:57:59 -07:00
Ben Alpert
8ce7b7120c ReactMount now never expects invalid nodes in its cache
It never really made sense for us to have "invalid" nodes in the cache -- when we unmount things, we should always remove them from the cache properly. Now that swapping composite types doesn't repopulate the cache, we should be okay to now assume that everything in the cache is good.
2015-10-07 12:57:34 -07:00
Ben Alpert
fe9a76ef25 Rewrite ReactInstanceHandles-test to be less brittle 2015-10-07 12:57:34 -07:00
Ben Alpert
60491d89f8 Use returned native node for composite type-change
With this change, all unmounted components should be properly purged from ReactMount's cache.
2015-10-07 12:57:34 -07:00
Ben Alpert
743ccf090f Cache native node on native components, return it when unmounting
This is probably slightly slower for unmounts in the case that no updates were ever performed, but caching the node on the instance should make updates faster. In any case, the more important consequence of this change is that we can fix the current memory leak that happens when swapping composite types.
2015-10-07 12:57:34 -07:00
Ben Alpert
e4a43389b8 Don't use existing "root" ID if non-root
Before, if you had

```
container = <div data-reactid=".0"><div data-reactid=".0.0" /></div>;
```

and did `ReactDOM.render(<span />, container)` you would get

```
<div data-reactid=".0"><span data-reactid=".0" /></div>;
```

(along with a warning not to replace React-rendered children with a new tree like that). But that makes no sense -- the span should have a new index, not truncate the ID of the old child it's replacing.

(Now tests pass again with useCreateElement on; before they threw a "valid but unequal" on our test for this warning.)
2015-10-07 12:57:34 -07:00
Ben Alpert
8ebbb7802c Merge pull request #4918 from glenjamin/shallow-getinstance
Expose component instance in shallow rendering
2015-10-07 12:52:09 -07:00
Ben Alpert
501a2765ac Merge pull request #4947 from fabiomcosta/server_render_index
[react] making sure ReactDOMServer always uses ServerReactRootIndex, …
2015-10-07 12:51:59 -07:00
Ben Alpert
4a29fd892a Merge pull request #4779 from mnordick/master
Support CSS3 Grid Layout Module for inline styles
2015-10-07 12:51:26 -07:00
Ben Alpert
e1d4668fd5 Update downloads page for 0.14 2015-10-07 12:50:59 -07:00
Paul O’Shannessy
926f372dc5 Merge pull request #5073 from mfunkie/patch-2
Update Pure Render Mixin docs to point to new npm package
2015-10-07 12:22:04 -07:00
Paul O’Shannessy
30386b2e86 Final docs update for 0.14 2015-10-07 11:25:50 -07:00
Paul O’Shannessy
42481fe51f [docs] Update acknowledgements for 0.14 2015-10-07 11:25:44 -07:00
Mark Funk
c2ae332718 Update Pure Render Mixin docs to point to new npm package 2015-10-07 14:16:26 -04:00
Paul O’Shannessy
59cd224a03 Bump version in master for 0.15 development 2015-10-07 09:57:53 -07:00
Cam Song
a69f05c881 Always use ANONYMOUS const in ReactPropTypes.js 2015-10-07 11:28:38 +08:00
Jim
fc043bb3a5 Revert "Revert "Remove dependence on ES5 shams per #4189"" 2015-10-06 14:31:20 -07:00
Jim
c103c8d065 Added warning for use of ReactLink. 2015-10-02 11:33:48 -07:00
Ben Alpert
3b28c72142 Add rudimentary jsc perf-counters runner
Works at least on a CentOS 7 machine after running `sudo yum install
webkitgtk webkitgtk-devel`.

The only globals you get are `print` and `PerfCounters`. No `console` nor the other globals provided by the `jsc` command-line tool (load, readFile, etc) though they're probably not hard to implement.

You can disable the JIT by setting the environment variable `JSC_useJIT=false`.

Test Plan:
```
~/local/react/scripts/perf-counters$ make
~/local/react/scripts/perf-counters$ build/jsc-perf <(echo 'PerfCounters.init(); var a = PerfCounters.getCounters().instructions; print("moo"); var b = PerfCounters.getCounters().instructions; print(b - a);')
moo
72182
~/local/react/scripts/perf-counters$
```
2015-09-30 23:36:06 -07:00
James Friend
107e3014ef Perform transaction around shallow render to run lifecycle methods 2015-09-28 22:48:15 +10:00
Fabio Costa
e65fe182e7 [react] making sure ReactDOMServer always uses ServerReactRootIndex, even on an environment that can use DOM 2015-09-24 19:59:39 -07:00
Glen Mailer
241533782c Expose component instance in shallow rendering
Fixes #4056
2015-09-20 15:16:51 +01:00
Ben Alpert
b7bf1ccafe Don't build up mount-ready queue for server side rendering
This is a little faster when rendering iframe/img/form/video/audio on the server.
2015-09-15 21:47:30 -07:00
Mike Nordick
8da4efa899 Adding support for CSS3 Grid layout module.
grid-row and grid-column must be unitless numbers.
2015-09-10 15:56:11 -05:00
402 changed files with 24761 additions and 18321 deletions

25
.babelrc Normal file
View File

@@ -0,0 +1,25 @@
{
"presets": ["react"],
"ignore": ["third_party"],
"plugins": [
"fbjs-scripts/babel-6/dev-expression",
"syntax-trailing-function-commas",
"transform-es2015-template-literals",
"transform-es2015-literals",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
["transform-es2015-classes", { "loose": true }],
"transform-es2015-object-super",
"transform-es2015-shorthand-properties",
"transform-es2015-computed-properties",
"transform-es2015-for-of",
"check-es2015-constants",
["transform-es2015-spread", { "loose": true }],
"transform-es2015-parameters",
["transform-es2015-destructuring", { "loose": true }],
"transform-es2015-block-scoping",
"transform-es2015-modules-commonjs",
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
]
}

View File

@@ -11,9 +11,6 @@ docs/vendor/bundle/
examples/
# Ignore built files.
build/
# react-codemod
packages/react-codemod/test/
packages/react-codemod/scripts/
packages/react-codemod/build/
packages/react-codemod/node_modules/
coverage/
scripts/bench/bench-*.js
vendor/*

View File

@@ -1,63 +0,0 @@
---
parser: babel-eslint
extends:
- ./node_modules/fbjs-scripts/eslint/.eslintrc
plugins:
- react
- react-internal
# We're stricter than the default config, mostly. We'll override a few rules and
# then enable some React specific ones.
rules:
accessor-pairs: 0
brace-style: [2, 1tbs]
comma-dangle: [2, always-multiline]
consistent-return: 2
dot-location: [2, property]
dot-notation: 2
eol-last: 2
indent: [2, 2, {SwitchCase: 1}]
jsx-quotes: [2, prefer-double]
no-bitwise: 0
no-dupe-class-members: 2
no-multi-spaces: 2
no-restricted-syntax: [2, WithStatement]
no-shadow: 2
no-unused-expressions: 2
no-unused-vars: [2, {args: none}]
quotes: [2, single, avoid-escape]
space-after-keywords: 2
space-before-blocks: 2
# TODO: enable this rule after https://github.com/eslint/eslint/pull/3768 lands
space-before-keywords: 0
strict: [2, global]
# JSX
# Our transforms set this automatically
react/display-name: 0
react/jsx-boolean-value: [2, always]
react/jsx-no-undef: 2
# We don't care to do this
react/jsx-sort-prop-types: 0
react/jsx-sort-props: 0
react/jsx-uses-react: 2
react/jsx-uses-vars: 2
# It's easier to test some things this way
react/no-did-mount-set-state: 0
react/no-did-update-set-state: 0
# We define multiple components in test files
react/no-multi-comp: 0
react/no-unknown-property: 2
# This isn't useful in our test code
react/prop-types: 0
react/react-in-jsx-scope: 2
react/self-closing-comp: 2
# We don't care to do this
react/sort-comp: 0
react/wrap-multilines: [2, {declaration: false, assignment: false}]
# CUSTOM RULES
# the second argument of warning/invariant should be a literal string
react-internal/warning-and-invariant-args: 2

73
.eslintrc.js Normal file
View File

@@ -0,0 +1,73 @@
const OFF = 0;
const WARNING = 1;
const ERROR = 2;
module.exports = {
parser: 'babel-eslint',
extends: './node_modules/fbjs-scripts/eslint/.eslintrc.js',
plugins: [
'react',
'react-internal',
],
ecmaFeatures: {
modules: false
},
// We're stricter than the default config, mostly. We'll override a few rules
// and then enable some React specific ones.
rules: {
'accessor-pairs': OFF,
'brace-style': [ERROR, '1tbs'],
'comma-dangle': [ERROR, 'always-multiline'],
'consistent-return': ERROR,
'dot-location': [ERROR, 'property'],
'dot-notation': ERROR,
'eol-last': ERROR,
'eqeqeq': [ERROR, 'allow-null'],
'indent': [ERROR, 2, {SwitchCase: 1}],
'jsx-quotes': [ERROR, 'prefer-double'],
'no-bitwise': OFF,
'no-multi-spaces': ERROR,
'no-restricted-syntax': [ERROR, 'WithStatement'],
'no-shadow': ERROR,
'no-unused-expressions': ERROR,
'no-unused-vars': [ERROR, {args: 'none'}],
'quotes': [ERROR, 'single', 'avoid-escape'],
'space-after-keywords': ERROR,
'space-before-blocks': ERROR,
'space-before-function-paren': [ERROR, {anonymous: 'never', named: 'never'}],
'space-before-keywords': ERROR,
'strict': [ERROR, 'global'],
// React & JSX
// Our transforms set this automatically
'react/display-name': OFF,
'react/jsx-boolean-value': [ERROR, 'always'],
'react/jsx-no-undef': ERROR,
// We don't care to do this
'react/jsx-sort-prop-types': OFF,
'react/jsx-sort-props': OFF,
'react/jsx-uses-react': ERROR,
'react/jsx-uses-vars': ERROR,
// It's easier to test some things this way
'react/no-did-mount-set-state': OFF,
'react/no-did-update-set-state': OFF,
// We define multiple components in test files
'react/no-multi-comp': OFF,
'react/no-unknown-property': OFF,
// This isn't useful in our test code
'react/prop-types': OFF,
'react/react-in-jsx-scope': ERROR,
'react/self-closing-comp': ERROR,
// We don't care to do this
'react/sort-comp': OFF,
'react/wrap-multilines': [ERROR, {declaration: false, assignment: false}],
// CUSTOM RULES
// the second argument of warning/invariant should be a literal string
'react-internal/warning-and-invariant-args': ERROR,
}
};

1
.gitignore vendored
View File

@@ -7,6 +7,7 @@ static
_SpecRunner.html
__benchmarks__
build/
coverage/
.module-cache
*.gem
docs/.bundle

View File

@@ -65,13 +65,26 @@ script:
-F "branch=$TRAVIS_BRANCH" \
$SERVER
fi
elif [ "$TEST_TYPE" = test ]; then
if [ "$TRAVIS_PULL_REQUEST" = false ]; then
set -e
./node_modules/.bin/grunt jest:coverage
cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
else
./node_modules/.bin/grunt jest:normal
fi
echo 'Testing in server-render (HTML generation) mode...'
printf '\nmodule.exports.useCreateElement = false;\n' \
>> src/renderers/dom/shared/ReactDOMFeatureFlags.js
./node_modules/.bin/grunt jest:normal
git checkout -- src/renderers/dom/shared/ReactDOMFeatureFlags.js
else
./node_modules/.bin/grunt $TEST_TYPE
fi
env:
matrix:
- TEST_TYPE=build
- TEST_TYPE=jest
- TEST_TYPE=test
- TEST_TYPE=lint
- TEST_TYPE=build_website
global:
@@ -81,8 +94,8 @@ env:
- secure: dkpPW+VnoqC/okhRdV90m36NcyBFhcwEKL3bNFExAwi0dXnFao8RoFlvnwiPlA23h2faROkMIetXlti6Aju08BgUFV+f9aL6vLyU7gUent4Nd3413zf2fwDtXIWIETg6uLnOpSykGKgCAT/hY3Q2oPLqOoY0OxfgnbqwxkxljrE=
# GITHUB_TOKEN
- secure: EHCyCSKMwKlLHNtcj9nmkRzmiiPE3aDGlPcnEyrDJeRI0SeN/iCXHXfFivR0vFq3vr+9naMBczAR2AEidtps5KbJrKqdZnjPFRbmfVtzWr/LlvVCub3u13Pub6TdKIVBTny1PuZ5X8GvdxMNVig89jGjvzhhWuQRaz3VhJnTra4=
matrix:
fast_finish: true
# COVERALLS_TOKEN
- secure: h/cUq+TrUMZOQmkFD7CvuwX0uAwmjIfKZ4qSUzY+QzUtDzOzA0L/XF84xTBq1Q5YYsEiaoF6GxxGCdrLQiBA/ZTd+88UHgeZPMRvi0xG9Q+PeePVOsZMTxy4/WWFgOfSQCk49Mj9zizGgO78i6vxq+SDXMtFHnZ+TpPJIEW6/m0=
notifications:
irc:
use_notice: true

View File

@@ -1,8 +1,3 @@
## 0.14.8 (March 29, 2016)
### React
- Fixed memory leak when rendering on the server
## 0.14.7 (January 28, 2016)
### React
@@ -97,8 +92,8 @@
- `React.initializeTouchEvents` is no longer necessary and has been removed completely. Touch events now work automatically.
- Add-Ons: Due to the DOM node refs change mentioned above, `TestUtils.findAllInRenderedTree` and related helpers are no longer able to take a DOM component, only a custom component.
- The `props` object is now frozen, so mutating props after creating a component element is no longer supported. In most cases, [`React.cloneElement`](/react/docs/top-level-api.html#react.cloneelement) should be used instead. This change makes your components easier to reason about and enables the compiler optimizations mentioned above.
- Plain objects are no longer supported as React children; arrays should be used instead. You can use the [`createFragment`](/react/docs/create-fragment.html) helper to migrate, which now returns an array.
- The `props` object is now frozen, so mutating props after creating a component element is no longer supported. In most cases, [`React.cloneElement`](https://facebook.github.io/react/docs/top-level-api.html#react.cloneelement) should be used instead. This change makes your components easier to reason about and enables the compiler optimizations mentioned above.
- Plain objects are no longer supported as React children; arrays should be used instead. You can use the [`createFragment`](https://facebook.github.io/react/docs/create-fragment.html) helper to migrate, which now returns an array.
- Add-Ons: `classSet` has been removed. Use [classnames](https://github.com/JedWatson/classnames) instead.
- Web components (custom elements) now use native property names. Eg: `class` instead of `className`.
@@ -106,9 +101,9 @@
- `this.getDOMNode()` is now deprecated and `ReactDOM.findDOMNode(this)` can be used instead. Note that in the common case, `findDOMNode` is now unnecessary since a ref to the DOM component is now the actual DOM node.
- `setProps` and `replaceProps` are now deprecated. Instead, call ReactDOM.render again at the top level with the new props.
- ES6 component classes must now extend `React.Component` in order to enable stateless function components. The [ES3 module pattern](/react/blog/2015/01/27/react-v0.13.0-beta-1.html#other-languages) will continue to work.
- ES6 component classes must now extend `React.Component` in order to enable stateless function components. The [ES3 module pattern](https://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#other-languages) will continue to work.
- Reusing and mutating a `style` object between renders has been deprecated. This mirrors our change to freeze the `props` object.
- Add-Ons: `cloneWithProps` is now deprecated. Use [`React.cloneElement`](/react/docs/top-level-api.html#react.cloneelement) instead (unlike `cloneWithProps`, `cloneElement` does not merge `className` or `style` automatically; you can merge them manually if needed).
- Add-Ons: `cloneWithProps` is now deprecated. Use [`React.cloneElement`](https://facebook.github.io/react/docs/top-level-api.html#react.cloneelement) instead (unlike `cloneWithProps`, `cloneElement` does not merge `className` or `style` automatically; you can merge them manually if needed).
- Add-Ons: To improve reliability, `CSSTransitionGroup` will no longer listen to transition events. Instead, you should specify transition durations manually using props such as `transitionEnterTimeout={500}`.
### Notable enhancements
@@ -149,7 +144,7 @@
#### Breaking Changes
- The `react-tools` package and `JSXTransformer.js` browser file [have been deprecated](/react/blog/2015/06/12/deprecating-jstransform-and-react-tools.html). You can continue using version `0.13.3` of both, but we no longer support them and recommend migrating to [Babel](http://babeljs.io/), which has built-in support for React and JSX.
- The `react-tools` package and `JSXTransformer.js` browser file [have been deprecated](https://facebook.github.io/react/blog/2015/06/12/deprecating-jstransform-and-react-tools.html). You can continue using version `0.13.3` of both, but we no longer support them and recommend migrating to [Babel](http://babeljs.io/), which has built-in support for React and JSX.
#### New Features
@@ -251,7 +246,7 @@
* Support for using ES6 classes to build React components; see the [v0.13.0 beta 1 notes](https://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html) for details.
* Added new top-level API `React.findDOMNode(component)`, which should be used in place of `component.getDOMNode()`. The base class for ES6-based components will not have `getDOMNode`. This change will enable some more patterns moving forward.
* Added a new top-level API `React.cloneElement(el, props)` for making copies of React elements see the [v0.13 RC2 notes](/react/blog/2015/03/03/react-v0.13-rc2.html#react.cloneelement) for more details.
* Added a new top-level API `React.cloneElement(el, props)` for making copies of React elements see the [v0.13 RC2 notes](https://facebook.github.io/react/blog/2015/03/03/react-v0.13-rc2.html#react.cloneelement) for more details.
* New `ref` style, allowing a callback to be used in place of a name: `<Photo ref={(c) => this._photo = c} />` allows you to reference the component with `this._photo` (as opposed to `ref="photo"` which gives `this.refs.photo`).
* `this.setState()` can now take a function as the first argument for transactional state updates, such as `this.setState((state, props) => ({count: state.count + 1}));` this means that you no longer need to use `this._pendingState`, which is now gone.
* Support for iterators and immutable-js sequences as children.
@@ -265,7 +260,7 @@
#### New Features
* [`React.addons.createFragment` was added](/react/docs/create-fragment.html) for adding keys to entire sets of children.
* [`React.addons.createFragment` was added](https://facebook.github.io/react/docs/create-fragment.html) for adding keys to entire sets of children.
#### Deprecations

View File

@@ -14,6 +14,20 @@ Some of the core team will be working directly on GitHub. These changes will be
We will do our best to keep `master` in good shape, with tests passing at all times. But in order to move fast, we will make API changes that your application might not be compatible with. We will do our best to communicate these changes and always version appropriately so you can lock into a specific version if need be.
### Test Suite
Use `grunt test` to run the full test suite with PhantomJS.
This command is just a facade to [Jest](https://facebook.github.io/jest/). You may optionally run `npm install -g jest-cli` and use Jest commands directly to have more control over how tests are executed.
For example, `jest --watch` lets you automatically run the test suite on every file change.
You can also run a subset of tests by passing a prefix to `jest`. For instance, `jest ReactDOMSVG` will only run tests in the files that start with `ReactDOMSVG`, such as `ReactDOMSVG-test.js`.
When you know which tests you want to run, you can achieve a fast feedback loop by using these two features together. For example, `jest ReactDOMSVG --watch` will re-run only the matching tests on every change.
Just make sure to run the whole test suite before submitting a pull request!
### Pull Requests
The core team will be monitoring for pull requests. When we get one, we'll run some Facebook-specific integration tests on it first. From here, we'll need to get another person to sign off on the changes and then merge the pull request. For API changes we may need to fix internal uses, which could cause some delay. We'll do our best to provide updates and feedback throughout the process.

View File

@@ -1,8 +1,12 @@
'use strict';
var assign = require('object-assign');
var path = require('path');
var GULP_EXE = 'gulp';
if (process.platform === 'win32') {
GULP_EXE += '.cmd';
}
module.exports = function(grunt) {
grunt.initConfig({
@@ -17,20 +21,19 @@ module.exports = function(grunt) {
'./examples/shared/*.js',
'.module-cache',
],
/*eslint-disable camelcase */
compare_size: require('./grunt/config/compare_size'),
/*eslint-enable camelcase */
'compare_size': require('./grunt/config/compare_size'),
});
grunt.config.set('compress', require('./grunt/config/compress'));
function spawnGulp(args, opts, done) {
grunt.util.spawn({
// This could be more flexible (require.resolve & lookup bin in package)
// but if it breaks we'll fix it then.
cmd: path.join('node_modules', '.bin', 'gulp'),
cmd: path.join('node_modules', '.bin', GULP_EXE),
args: args,
opts: assign({stdio: 'inherit'}, opts),
opts: Object.assign({stdio: 'inherit'}, opts),
}, function(err, result, code) {
if (err) {
grunt.fail.fatal('Something went wrong running gulp: ', result);
@@ -106,10 +109,12 @@ module.exports = function(grunt) {
]);
grunt.registerTask('build:react-dom', require('./grunt/tasks/react-dom'));
grunt.registerTask('test', ['jest']);
grunt.registerTask('npm:test', ['build', 'npm:pack']);
var jestTasks = require('./grunt/tasks/jest');
grunt.registerTask('jest:normal', jestTasks.normal);
grunt.registerTask('jest:coverage', jestTasks.coverage);
grunt.registerTask('jest', require('./grunt/tasks/jest'));
grunt.registerTask('test', ['jest:normal']);
grunt.registerTask('npm:test', ['build', 'npm:pack']);
// Optimized build task that does all of our builds. The subtasks will be run
// in order so we can take advantage of that and only run build-modules once.

View File

@@ -2,7 +2,7 @@ BSD License
For React software
Copyright (c) 2013-2015, Facebook, Inc.
Copyright (c) 2013-present, Facebook, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,

View File

@@ -1,4 +1,4 @@
# [React](https://facebook.github.io/react/) [![Build Status](https://travis-ci.org/facebook/react.svg?branch=0.14-stable)](https://travis-ci.org/facebook/react) [![npm version](https://badge.fury.io/js/react.svg)](http://badge.fury.io/js/react)
# [React](https://facebook.github.io/react/) [![Build Status](https://img.shields.io/travis/facebook/react/master.svg?style=flat)](https://travis-ci.org/facebook/react) [![Coverage Status](https://img.shields.io/coveralls/facebook/react/master.svg?style=flat)](https://coveralls.io/github/facebook/react?branch=master) [![npm version](https://img.shields.io/npm/v/react.svg?style=flat)](https://www.npmjs.com/package/react)
React is a JavaScript library for building user interfaces.
@@ -33,16 +33,16 @@ You'll notice that we used an HTML-like syntax; [we call it JSX](https://faceboo
## Installation
The fastest way to get started is to serve JavaScript from the CDN (also available on [cdnjs](https://cdnjs.com/libraries/react) and [jsdelivr](http://www.jsdelivr.com/#!react)):
The fastest way to get started is to serve JavaScript from the CDN (also available on [cdnjs](https://cdnjs.com/libraries/react) and [jsdelivr](https://www.jsdelivr.com/projects/react)):
```html
<!-- The core React library -->
<script src="https://fb.me/react-0.14.8.js"></script>
<script src="https://fb.me/react-0.14.7.js"></script>
<!-- The ReactDOM Library -->
<script src="https://fb.me/react-dom-0.14.8.js"></script>
<script src="https://fb.me/react-dom-0.14.7.js"></script>
```
We've also built a [starter kit](https://facebook.github.io/react/downloads/react-0.14.8.zip) which might be useful if this is your first time using React. It includes a webpage with an example of using React with live code.
We've also built a [starter kit](https://facebook.github.io/react/downloads/react-0.14.7.zip) which might be useful if this is your first time using React. It includes a webpage with an example of using React with live code.
If you'd like to use [bower](http://bower.io), it's as easy as:
@@ -50,6 +50,12 @@ If you'd like to use [bower](http://bower.io), it's as easy as:
bower install --save react
```
And it's just as easy with [npm](http://npmjs.com):
```sh
npm i --save react
```
## Contribute
The main purpose of this repository is to continue to evolve React core, making it faster and easier to use. If you're interested in helping with that, then keep reading. If you're not interested in helping right now that's ok too. :) Any feedback you have about using React would be greatly appreciated.
@@ -60,7 +66,7 @@ The process to build `react.js` is built entirely on top of node.js, using many
#### Prerequisites
* You have `node` installed at v0.10.0+ (it might work at lower versions, we just haven't tested) and `npm` at v2.0.0+.
* You have `node` installed at v4.0.0+ and `npm` at v2.0.0+.
* You are familiar with `npm` and know whether or not you need to use `sudo` when installing packages globally.
* You are familiar with `git`.
@@ -84,14 +90,16 @@ We use grunt to automate many tasks. Run `grunt -h` to see a mostly complete lis
```sh
# Build and run tests with PhantomJS
grunt test
# Build and run tests in your browser
grunt test --debug
# Lint the code with ESLint
grunt lint
# Wipe out build directory
grunt clean
```
### Good First Bug
To help you get your feet wet and get you familiar with our contribution process, we have a list of [good first bugs](https://github.com/facebook/react/labels/good%20first%20bug) that contain bugs which are fairly easy to fix. This is a great place to get started.
### License
React is [BSD licensed](./LICENSE). We also provide an additional [patent grant](./PATENTS).

View File

@@ -1,11 +1,19 @@
require('rubygems')
require('json')
require('yaml')
require('open-uri')
desc "download babel-browser"
task :fetch_remotes do
IO.copy_stream(
open('https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js'),
'js/babel-browser.min.js'
)
end
desc "generate js from jsx"
task :js do
system "cp ../node_modules/babel/node_modules/babel-core/browser.min.js ./js/babel-browser.min.js"
system "../node_modules/babel/bin/babel.js _js --out-dir=js"
system "../node_modules/.bin/babel _js --out-dir=js"
end
desc "watch js"
@@ -54,7 +62,7 @@ task :update_acknowledgements do
end
desc "build into ../../react-gh-pages"
task :release => [:update_version, :default] do
task :release => [:update_version, :js, :fetch_remotes] do
system "jekyll build -d ../../react-gh-pages"
end

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the

View File

@@ -16,7 +16,6 @@
<link rel="shortcut icon" href="/react/favicon.ico">
<link rel="alternate" type="application/rss+xml" title="{{ site.name }}" href="{{ site.url }}{{ site.baseurl }}/feed.xml">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css" />
<link rel="stylesheet" href="/react/css/syntax.css">
<link rel="stylesheet" href="/react/css/codemirror.css">
<link rel="stylesheet" href="/react/css/react.css">
@@ -29,7 +28,6 @@
<script src="/react/js/es5-shim.min.js"></script>
<script src="/react/js/es5-sham.min.js"></script>
<![endif]-->
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
<script src="/react/js/codemirror.js"></script>
<script src="/react/js/javascript.js"></script>
<script src="/react/js/react.js"></script>
@@ -52,9 +50,6 @@
<li><a href="/react/support.html"{% if page.id == 'support' %} class="active"{% endif %}>Support</a></li>
<li><a href="/react/downloads.html"{% if page.id == 'downloads' %} class="active"{% endif %}>Download</a></li>
<li><a href="/react/blog/"{% if page.sectionid == 'blog' %} class="active"{% endif %}>Blog</a></li>
<li>
<input id="algolia-doc-search" type="text" placeholder="Search docs..." />
</li>
</ul>
<ul class="nav-site nav-site-external">
@@ -112,12 +107,6 @@
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=623268441017527";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
docsearch({
apiKey: '36221914cce388c46d0420343e0bb32e',
indexName: 'react',
inputSelector: '#algolia-doc-search'
});
</script>
</body>
</html>

View File

@@ -56,7 +56,7 @@ The video will be available soon on the [JSConf EU website](http://2013.jsconf.e
[Todd Kennedy](http://blog.selfassembled.org/) working at [Cond&eacute; Nast](http://www.condenast.com/) implemented a wrapper on-top of [JSHint](http://www.jshint.com/) that first converts JSX files to JS.
> A wrapper around JSHint to allow linting of files containg JSX syntax. Accepts glob patterns. Respects your local .jshintrc file and .gitignore to filter your glob patterns.
> A wrapper around JSHint to allow linting of files containing JSX syntax. Accepts glob patterns. Respects your local .jshintrc file and .gitignore to filter your glob patterns.
>
> ```
npm install -g jsxhint

View File

@@ -13,7 +13,7 @@ React is only one-piece of your web application stack. [Mark Lussier](https://gi
>
> I encourage you to fork, and make it right and submit a pull request!
>
> My current opinion is using tools like Grunt, Browserify, Bower and mutiple grunt plugins to get the job done. I also opted for Zepto over jQuery and the Flatiron Project's Director when I need a router. Oh and for the last little bit of tech that makes you mad, I am in the SASS camp when it comes to stylesheets
> My current opinion is using tools like Grunt, Browserify, Bower and multiple grunt plugins to get the job done. I also opted for Zepto over jQuery and the Flatiron Project's Director when I need a router. Oh and for the last little bit of tech that makes you mad, I am in the SASS camp when it comes to stylesheets
>
> [Check it out on GitHub...](https://github.com/intabulas/reactjs-baseline)

View File

@@ -49,7 +49,7 @@ React.DOM.div(null,
)
```
We believe this new behavior is more helpful and elimates cases where unwanted whitespace was previously added.
We believe this new behavior is more helpful and eliminates cases where unwanted whitespace was previously added.
In cases where you want to preserve the space adjacent to a newline, you can write a JS string like `{"Monkeys: "}` in your JSX source. We've included a script to do an automated codemod of your JSX source tree that preserves the old whitespace behavior by adding and removing spaces appropriately. You can [install jsx\_whitespace\_transformer from npm](https://github.com/facebook/react/blob/master/npm-jsx_whitespace_transformer/README.md) and run it over your source tree to modify files in place. The transformed JSX files will preserve your code's existing whitespace behavior.

View File

@@ -57,7 +57,7 @@ React.DOM.div(null,
)
```
We believe this new behavior is more helpful and elimates cases where unwanted whitespace was previously added.
We believe this new behavior is more helpful and eliminates cases where unwanted whitespace was previously added.
In cases where you want to preserve the space adjacent to a newline, you can write `{'Monkeys: '}` or `Monkeys:{' '}` in your JSX source. We've included a script to do an automated codemod of your JSX source tree that preserves the old whitespace behavior by adding and removing spaces appropriately. You can [install jsx\_whitespace\_transformer from npm](https://github.com/facebook/react/blob/master/npm-jsx_whitespace_transformer/README.md) and run it over your source tree to modify files in place. The transformed JSX files will preserve your code's existing whitespace behavior.

View File

@@ -1,96 +0,0 @@
---
title: "React v15.0 Release Candidate"
author: zpao
---
Sorry for the small delay in releasing this. As we said, we've been busy binge-watching House of Cards. That scene in the last episode where Francis and Claire Underwood <abbr title="You didn't think we would actually spoil anything did you?">████████████████████████████████████</abbr>. WOW!
But now we're ready, so without further ado, we're shipping a release candidate for React v15 now. As a reminder, [we're switching to major versions](/react/blog/2016/02/19/new-versioning-scheme.html) to indicate that we have been using React in production for a long time. This 15.0 release follows our previous 0.14 version and we'll continue to follow semver like we've been doing since 2013. It's also worth noting that [we no longer actively support Internet Explorer 8](/react/blog/2016/01/12/discontinuing-ie8-support.html). We believe React will work in its current form there but we will not be prioritizing any efforts to fix new issues that only affect IE8.
Please try it out before we publish the final release. Let us know if you run into any problems by filing issues on our [GitHub repo](https://github.com/facebook/react).
## Upgrade Guide
Like always, we have a few breaking changes in this release. We know changes can be painful (the Facebook codebase has over 15,000 React components), so we always try to make changes gradually in order to minimize the pain.
If your code is free of warnings when running under React 0.14, upgrading should be easy. The bulk of changes in this release are actually behind the scenes, impacting the way that React interacts with the DOM. The other substantial change is that React now supports the full range of SVG elements and attributes. Beyond that we have a large number of incremental improvements and additional warnings aimed to aid developers. We've also laid some groundwork in the core to bring you some new capabilities in future releases.
See the changelog below for more details.
## Installation
We recommend using React from `npm` and using a tool like browserify or webpack to build your code into a single bundle. To install the two packages:
* `npm install --save react@15.0.0-rc.1 react-dom@15.0.0-rc.1`
Remember that by default, React runs extra checks and provides helpful warnings in development mode. When deploying your app, set the `NODE_ENV` environment variable to `production` to use the production build of React which does not include the development warnings and runs significantly faster.
If you cant use `npm` yet, we provide pre-built browser builds for your convenience, which are also available in the `react` package on bower.
* **React**
Dev build with warnings: <https://fb.me/react-15.0.0-rc.1.js>
Minified build for production: <https://fb.me/react-15.0.0-rc.1.min.js>
* **React with Add-Ons**
Dev build with warnings: <https://fb.me/react-with-addons-15.0.0-rc.1.js>
Minified build for production: <https://fb.me/react-with-addons-15.0.0-rc.1.min.js>
* **React DOM** (include React in the page before React DOM)
Dev build with warnings: <https://fb.me/react-dom-15.0.0-rc.1.js>
Minified build for production: <https://fb.me/react-dom-15.0.0-rc.1.min.js>
## Changelog
### Major changes
- #### `document.createElement` is in and `data-reactid` is out
There were a number of large changes to our interactions with the DOM. One of the most noticeable changes is that we no longer set the `data-reactid` attribute for each DOM node. While this will make it much more difficult to know if a website is using React, the advantage is that the DOM is much more lightweight. This change was made possible by us switching to use `document.createElement` on initial render. Previously we would generate a large string of HTML and then set `node.innerHTML`. At the time, this was decided to be faster than using `document.createElement` for the majority of cases and browsers that we supported. Browsers have continued to improve and so overwhelmingly this is no longer true. By using `createElement` we can make other parts of React faster. The ids were used to map back from events to the original React component, meaning we had to do a bunch of work on every event, even though we cached this data heavily. As we've all experienced, caching and in particularly invalidating caches, can be error prone and we saw many hard to reproduce issues over the years as a result. Now we can build up a direct mapping at render time since we already have a handle on the node.
- #### No more extra `<span>`s
Another big change with our DOM interaction is how we render text blocks. Previously you may have noticed that React rendered a lot of extra `<span>`s. Eg, in our most basic example on the home page we render `<div>Hello {this.props.name}</div>`, resulting in markup that contained 2 `<span>`s. Now we'll render plain text nodes interspersed with comment nodes that are used for demarcation. This gives us the same ability to update individual pieces of text, without creating extra nested nodes. Very few people have depended on the actual markup generated here so it's likely you are not impacted. However if you were targeting these `<span>`s in your CSS, you will need to adjust accordingly. You can always render them explicitly in your components.
- #### Rendering `null` now uses comment nodes
We've also made use of these comment nodes to change what `null` renders to. Rendering to `null` was a feature we added in React v0.11 and was implemented by rendering `<noscript>` elements. By rendering to comment nodes now, there's a chance some of your CSS will be targeting the wrong thing, specifically if you are making use of `:nth-child` selectors. This, along with the other changes mentioned above, have always been considered implementation details of how React targets the DOM. We believe they are safe changes to make without going through a release with warnings detailing the subtle differences as they are details that should not be depended upon. Additionally, we have seen that these changes have improved React performance for many typical applications.
- #### Improved SVG support
All SVG tags and attributes are now fully supported. (Uncommon SVG tags are not present on the `React.DOM` element helper, but JSX and `React.createElement` work on all tag names.) All SVG attributes match their original capitalization and hyphenation as defined in the specification (ex: `gradientTransform` must be camel-cased but `clip-path` should be hyphenated).
### Breaking changes
It's worth calling out the DOM structure changes above again, in particular the change from `<span>`s. In the course of updating the Facebook codebase, we found a very small amount of code that was depending on the markup that React generated. Some of these cases were integration tests like WebDriver which were doing very specific XPath queries to target nodes. Others were simply tests using `ReactDOM.renderToStaticMarkup` and comparing markup. Again, there were a very small number of changes that had to be made, but we don't want anybody to be blindsided. We encourage everybody to run their test suites when upgrading and consider alternative approaches when possible. One approach that will work for some cases is to explicitly use `<span>`s in your `render` method.
These deprecations were introduced in v0.14 with a warning and the APIs are now removed.
- Deprecated APIs removed from `React`, specifically `findDOMNode`, `render`, `renderToString`, `renderToStaticMarkup`, and `unmountComponentAtNode`.
- Deprecated APIs removed from `React.addons`, specifically `batchedUpdates` and `cloneWithProps`.
- Deprecated APIs removed from component instances, specifically `setProps`, `replaceProps`, and `getDOMNode`.
### New deprecations, introduced with a warning
Each of these changes will continue to work as before with a new warning until the release of React 16 so you can upgrade your code gradually.
- `LinkedStateMixin` and `valueLink` are now deprecated due to very low popularity. If you need this, you can use a wrapper component that implements the same behavior: [react-linked-input](https://www.npmjs.com/package/react-linked-input).
### New helpful warnings
- If you use a minified copy of the _development_ build, React DOM kindly encourages you to use the faster production build instead.
- React DOM: When specifying a unit-less CSS value as a string, a future version will not add `px` automatically. This version now warns in this case (ex: writing `style={{'{{'}}width: '300'}}`. (Unitless *number* values like `width: 300` are unchanged.)
- Synthetic Events will now warn when setting and accessing properties (which will not get cleared appropriately), as well as warn on access after an event has been returned to the pool.
- Elements will now warn when attempting to read `ref` and `key` from the props.
- React DOM now attempts to warn for mistyped event handlers on DOM elements (ex: `onclick` which should be `onClick`)
### Notable bug fixes
- Fixed multiple small memory leaks
- Click events are handled by React DOM more reliably in mobile browsers, particularly in Mobile Safari.
- Input events are handled more reliably in IE 10 and IE 11; spurious events no longer fire when using a placeholder.
- React DOM now supports the `cite` and `profile` HTML attributes.
- React DOM now supports the `onAnimationStart`, `onAnimationEnd`, `onAnimationIteration`, `onTransitionEnd`, and `onInvalid` events. Support for `onLoad` has been added to `object` elements.
- Add-Ons: ReactTransitionGroup now correctly handles multiple nodes being removed simultaneously.
- `Object.is` is used in a number of places to compare values, which leads to fewer false positives, especially involving `NaN`. In particular, this affects the `shallowCompare` add-on.
- React DOM now defaults to using DOM attributes instead of properties, which fixes a few edge case bugs. Additionally the nullification of values (ex: `href={null}`) now results in the forceful removal, no longer trying to set to the default value used by browsers in the absence of a value.

View File

@@ -1,32 +0,0 @@
---
title: "React v15.0 Release Candidate 2"
author: zpao
---
Today we're releasing a second release candidate for version 15. Primarily this is to address 2 issues, but we also picked up a few small changes from new contributors, including some improvements to some of our new warnings.
The most pressing change that was made is to fix a bug in our new code that removes `<span>`s, as discussed in the original RC1 post. Specifically we have some code that takes a different path in IE11 and Edge due to the speed of some DOM operations. There was a bug in this code which didn't break out of the optimization for `DocumentFragment`s, resulting in text not appearing at all. Thanks to the several people who [reported this](https://github.com/facebook/react/issues/6246).
The other change is to our SVG code. In RC1 we had made the decision to pass through all attributes directly. This led to [some confusion with `class` vs `className`](https://github.com/facebook/react/issues/6211) and ultimately led us to reconsider our position on the approach. Passing through all attributes meant that we would have two different patterns for using React where things like hyphenated attributes would work for SVG but not HTML. In the future, we *might* change our approach to the problem for HTML as well but in the meantime, maintaining consistency is important. So we reverted the changes that allowed the attributes to be passed through and instead expanded the SVG property list to include all attributes that are in the spec. We believe we have everything now but definitely [let us know](https://github.com/facebook/react/issues/1657#issuecomment-197031403) if we missed anything. It was and still is our intent to support the full range of SVG tags and attributes in this release.
Thanks again to everybody who has tried the RC1 and reported issues. It has been extremely important and we wouldn't be able to do this without your help!
## Installation
We recommend using React from `npm` and using a tool like browserify or webpack to build your code into a single bundle. To install the two packages:
* `npm install --save react@15.0.0-rc.2 react-dom@15.0.0-rc.2`
Remember that by default, React runs extra checks and provides helpful warnings in development mode. When deploying your app, set the `NODE_ENV` environment variable to `production` to use the production build of React which does not include the development warnings and runs significantly faster.
If you cant use `npm` yet, we provide pre-built browser builds for your convenience, which are also available in the `react` package on bower.
* **React**
Dev build with warnings: <https://fb.me/react-15.0.0-rc.2.js>
Minified build for production: <https://fb.me/react-15.0.0-rc.2.min.js>
* **React with Add-Ons**
Dev build with warnings: <https://fb.me/react-with-addons-15.0.0-rc.2.js>
Minified build for production: <https://fb.me/react-with-addons-15.0.0-rc.2.min.js>
* **React DOM** (include React in the page before React DOM)
Dev build with warnings: <https://fb.me/react-dom-15.0.0-rc.2.js>
Minified build for production: <https://fb.me/react-dom-15.0.0-rc.2.min.js>

View File

@@ -5,7 +5,7 @@
font-family: monospace;
}
.CodeMirror-scroll {
/* Set scrolling behaviour here */
/* Set scrolling behavior here */
overflow: auto;
}
@@ -122,7 +122,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
}
/* The fake, visible scrollbars. Used to force redraw during scrolling
before actuall scrolling happens, thus preventing shaking and
before actual scrolling happens, thus preventing shaking and
flickering artifacts. */
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler {
position: absolute;

View File

@@ -129,7 +129,7 @@ h1, h2, h3, h4, h5, h6 {
margin: 0;
}
li > a {
a {
box-sizing: content-box;
padding: 0 10px;
line-height: $navHeight;
@@ -759,6 +759,8 @@ p a code {
margin-bottom: 0;
background-color: transparent;
border: 0;
float: left;
min-width: 100%;
}
.highlight pre code {
@@ -854,72 +856,3 @@ div[data-twttr-id] iframe {
.three-column > ul:first-child {
margin-left: 20px;
}
/* Algolia Doc Search */
@media screen and (max-width: 960px) {
#algolia-doc-search {
display: none;
}
}
input#algolia-doc-search {
background: transparent url('/react/img/search.png') no-repeat 10px center;
background-size: 16px 16px;
position: relative;
vertical-align: top;
margin-left: 10px;
padding: 0 10px;
padding-left: 35px;
height: 30px;
margin-top: 10px;
font-size: 16px;
line-height: 20px;
background-color: #333;
border-radius: 4px;
color: white;
outline: none;
width: 170px;
transition: width .2s ease;
}
input#algolia-doc-search:focus {
width: 240px;
}
.algolia-autocomplete .aa-dropdown-menu {
margin-left: -110px;
margin-top: -4px;
}
.algolia-autocomplete {
vertical-align: top;
height: 53px;
}
.algolia-docsearch-suggestion {
border-bottom-color: #c05b4d;
}
.algolia-docsearch-suggestion--category-header {
background-color: #cc7a6f;
}
.algolia-docsearch-suggestion--highlight {
color: #c05b4d;
}
.algolia-docsearch-suggestion--category-header .algolia-docsearch-suggestion--highlight {
background-color: #c05b4d;
}
.aa-cursor .algolia-docsearch-suggestion--content {
color: #c05b4d;
}
.aa-cursor .algolia-docsearch-suggestion {
background: #f1f3f5;
}

View File

@@ -4,6 +4,7 @@ title: 为什么使用 React?
permalink: why-react-zh-CN.html
next: displaying-data-zh-CN.html
---
React 是一个 Facebook 和 Instagram 用来创建用户界面的 JavaScript 库。很多人选择将 React 认为是 **[MVC](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)** 中的 **V**(视图)。
我们创造 React 是为了解决一个问题:**构建随着时间数据不断变化的大规模应用程序**。
@@ -27,3 +28,5 @@ React挑战了很多传统的知识第一眼看上去可能很多想法有点
## 了解更多
你可以从这篇[博客](/react/blog/2013/06/05/why-react.html)了解更多我们创造 React 的动机。

View File

@@ -62,7 +62,7 @@ setInterval(function() {
このことについて私たちが理解できる方法は、Reactは必要になるまで、DOMの操作を行わないということです。 **Reactは、DOMの変化を表現し、あなたにもっとも効率的なDOMの変化を見積もるために早い、内部のモックのDOMを使っています。**
このコンポーネントのインプットは `props` と呼ばれるものです。"properties" の省略形です。それらはJSXシンタックスの中でアトリビュートとして渡されます。それらはコンポーネントの中で不変と考えるべきで、 **`this.props` と書かないようにしてください**
このコンポーネントのインプットは `props` と呼ばれるものです。"properties" の省略形です。それらはJSXシンタックスの中でアトリビュートとして渡されます。それらはコンポーネントの中で不変と考えるべきで、 **`this.props` には書き込まないようにしてください**
## コンポーネントは関数のようなものです。

View File

@@ -97,7 +97,7 @@ JSX 类似于 HTML但不是完全一样。参考 [JSX 陷阱](/react/docs/jsx
## 没有 JSX 的 React
JSX完全是可选的你无需在 React 中必须使用 JSX。你可以通过 `React.createElement` 来创建一个树。第一个参数是标签,第二个参数是一个属性对象,三个是子节点。
JSX完全是可选的你无需在 React 中必须使用 JSX。你可以通过 `React.createElement` 来创建一个树。第一个参数是标签,第二个参数是一个属性对象,三个是子节点。
```javascript
var child1 = React.createElement('li', null, 'First Text Content');

View File

@@ -14,49 +14,49 @@ next: reusable-components-zh-CN.html
## 组合实例
让我们用 Facebook Graph API 开发一个显示 Facebook 页面图片和用户名的简单 Avatar 组件吧。
一起来使用 Facebook Graph API 开发显示个人图片和用户名的简单 Avatar 组件吧。
```javascript
var Avatar = React.createClass({
render: function() {
return (
<div>
<PagePic pagename={this.props.pagename} />
<PageLink pagename={this.props.pagename} />
<ProfilePic username={this.props.username} />
<ProfileLink username={this.props.username} />
</div>
);
}
});
var PagePic = React.createClass({
var ProfilePic = React.createClass({
render: function() {
return (
<img src={'https://graph.facebook.com/' + this.props.pagename + '/picture'} />
<img src={'https://graph.facebook.com/' + this.props.username + '/picture'} />
);
}
});
var PageLink = React.createClass({
var ProfileLink = React.createClass({
render: function() {
return (
<a href={'https://www.facebook.com/' + this.props.pagename}>
{this.props.pagename}
<a href={'https://www.facebook.com/' + this.props.username}>
{this.props.username}
</a>
);
}
});
ReactDOM.render(
<Avatar pagename="Engineering" />,
<Avatar username="pwh" />,
document.getElementById('example')
);
```
## 从属关系
上面例子中,`Avatar` 拥有 `PagePic``PageLink` 的实例。`拥有者` 就是给其它组件设置 `props` 的那个组件。更正式地说,如果组件 `Y``render()` 方法是创建了组件 `X`,那么 `Y` 就拥有 `X`。上面讲过,组件不能修改自身的 `props` - 它们总是与它们拥有者设置的保持一致。这是保持用户界面一致性的基本不变量。
上面例子中,`Avatar` 拥有 `ProfilePic``ProfileLink` 的实例。`拥有者` 就是给其它组件设置 `props` 的那个组件。更正式地说,如果组件 `Y``render()` 方法是创建了组件 `X`,那么 `Y` 就拥有 `X`。上面讲过,组件不能修改自身的 `props` - 它们总是与它们拥有者设置的保持一致。这是保持用户界面一致性的基本不变量。
把从属关系与父子关系加以区别至关重要。从属关系是 React 特有的而父子关系简单来讲就是DOM 里的标签的关系。在上一个例子中,`Avatar` 拥有 `div``PagePic``PageLink` 实例,`div``PagePic``PageLink` 实例的**父级**(但不是拥有者)。
把从属关系与父子关系加以区别至关重要。从属关系是 React 特有的而父子关系简单来讲就是DOM 里的标签的关系。在上一个例子中,`Avatar` 拥有 `div``ProfilePic``ProfileLink` 实例,`div``ProfilePic``ProfileLink` 实例的**父级**(但不是拥有者)。
## 子级

View File

@@ -254,4 +254,4 @@ ReactDOM.render(<HelloMessage name="Sebastian" />, mountNode);
>
> 因为无状态函数没有备份实例,你不能附加一个引用到一个无状态函数组件。 通常这不是问题因为无状态函数不提供一个命令式的API。没有命令式的API你就没有任何需要实例来做的事。然而如果用户想查找无状态函数组件的DOM节点他们必须把这个组件包装在一个有状态组件里比如ES6 类组件) 并且连接一个引用到有状态的包装组件。
在理想世界里,你的大多数组件都应该是无状态函数,因为将来我们可能会用避免不必要的检查和内存分配的方式来对这些组件进行优化。 如果可能,这是推荐的模式。
在理想世界里,你的大多数组件都应该是无状态函数式的,因为这些无状态组件可以在React核心里经过一个快速的代码路径。 如果可能,这是推荐的模式。

View File

@@ -96,7 +96,7 @@ function FancyCheckbox(props) {
## 使用和传递同一个 Prop
如果组件需要使用一个属性又要往下传递,可以直接使用 `checked={checked}` 再传一次。这样做比传整个 `props` 对象要好,因为更利于重构和语法检查。
如果组件需要使用一个属性又要往下传递,可以直接使用 `checked={checked}` 再传一次。这样做比传整个 `this.props` 对象要好,因为更利于重构和语法检查。
```javascript
function FancyCheckbox(props) {

View File

@@ -30,11 +30,11 @@ next: working-with-the-browser-zh-CN.html
> 注意:
>
> 对于 `<input>` and `<textarea>` `onChange` 代 — 一般应该用来替代 — DOM内建的 [`oninput`](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/oninput) 事件处理。
> 对于 `<input>` and `<textarea>` `onChange` 代 — 一般应该用来替代 — the DOM's 内建的 [`oninput`](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/oninput) 事件处理。
## 受组件
## 受组件
一个*受控*`<input>` 一个 `value` prop。渲染一个受控 `<input>` 会反映 `value` prop 的值。
设置了 `value` `<input>` 一个*受限*组件。 对于受限的 `<input>`,渲染出来的 HTML 元素始终保持 `value` 属性的值。例如:
```javascript
render: function() {
@@ -42,7 +42,7 @@ next: working-with-the-browser-zh-CN.html
}
```
用户输入在被渲染的元素里将没有作用,因为 React 已经声明值为 `Hello!`要更新 value 来响应用户输入,你可以使用 `onChange` 事件:
上面的代码将渲染出一个值为 `Hello!` 的 input 元素。用户在渲染出来的元素里输入任何值都不起作用因为 React 已经值为 `Hello!`如果想响应更新用户输入的值,就得使用 `onChange` 事件:
```javascript
getInitialState: function() {
@@ -52,17 +52,12 @@ next: working-with-the-browser-zh-CN.html
this.setState({value: event.target.value});
},
render: function() {
return (
<input
type="text"
value={this.state.value}
onChange={this.handleChange}
/>
);
var value = this.state.value;
return <input type="text" value={value} onChange={this.handleChange} />;
}
```
在这个例子中,我们接受用户提供的值更新 `<input>` 组件的 `value` prop。这个模式使实现响应或者验证用户输入的界面容易。例如:
上面的代码中React 将用户输入的值更新 `<input>` 组件的 `value` 属性。这样实现响应或者验证用户输入的界面就很容易。例如:
```javascript
handleChange: function(event) {
@@ -72,15 +67,13 @@ next: working-with-the-browser-zh-CN.html
上面的代码接受用户输入,并截取前 140 个字符。
受控组件不维持一个自己的内部状态;它单纯的基于 props 渲染。
### 复选框与单选按钮的潜在问题
当心在力图标准化复选框与单选按钮的变换处理中React使用`click` 事件代替 `change` 事件。在大多数情况下它们表现的如同预期,除了在`change` handler中调用`preventDefault``preventDefault` 阻止了浏览器视觉上更新输入,即使`checked`被触发。变通的方式是要么移除`preventDefault`的调用,要么把`checked` 的触发放在一个`setTimeout`里。
## 不受组件
## 不受组件
一个没有 `value` 属性`<input>` 是一个不*受控*组件:
没有设置 `value`(或者设为 `null`) `<input>` 组件是一个*不受限*组件。对于不受限的 `<input>` 组件,渲染出来的元素直接反应用户输入。例如:
```javascript
render: function() {
@@ -88,9 +81,7 @@ next: working-with-the-browser-zh-CN.html
}
```
上面的代码将渲染出一个空值的输入框,用户输入将立即反应到元素上。和受元素一样,使用 `onChange` 事件可以监听值的变化。
*不受控*组件维持它自己的内部状态。
上面的代码将渲染出一个空值的输入框,用户输入将立即反应到元素上。和受元素一样,使用 `onChange` 事件可以监听值的变化。
### 默认值
@@ -102,17 +93,17 @@ next: working-with-the-browser-zh-CN.html
}
```
这个例子会像上面的 **不受组件** 例子一样运行。
这个例子会像上面的 **不受组件** 例子一样运行。
同样的, `<input type="checkbox">``<input type="radio">` 支持 `defaultChecked``<select>` 支持 `defaultValue`.
同样的, `<input>` 支持 `defaultChecked``<select>` 支持 `defaultValue`.
> 注意:
>
> `defaultValue` 和 `defaultChecked` props 只能在内部渲染时被使用。 如果你需要在随后的渲染更新值, 你需要使用 [受组件](#受组件).
> `defaultValue` 和 `defaultChecked` props 只能在内部渲染时被使用。 如果你需要在随后的渲染更新值, 你需要使用 [受组件](#受组件).
## 高级主题
### 为什么使用受组件?
### 为什么使用受组件?
在 React 中使用诸如 `<input>` 的表单组件时,遇到了一个在传统 HTML 中没有的挑战。比如下面的代码:
@@ -120,9 +111,9 @@ next: working-with-the-browser-zh-CN.html
<input type="text" name="title" value="Untitled" />
```
它渲染一个*初始值*`Untitled` 的输入框。用户改变输入框的值时,节点的 `value` 属性( *property*)将随之变化,但是 `node.getAttribute('value')` 还是会返回初始设置的值 `Untitled`.
在 HTML 中将渲染 *初始值* `Untitled` 的输入框。用户改变输入框的值时,节点的 `value` 属性( *property*)将随之变化,但是 `node.getAttribute('value')` 还是会返回初始设置的值 `Untitled`.
与 HTML 不同React 组件必须在任何时间点表现视图的状态,而不仅仅是在初始化时。比如在 React 中:
与 HTML 不同React 组件必须在任何时间点描绘视图的状态,而不仅仅是在初始化时。比如在 React 中:
```javascript
render: function() {
@@ -130,7 +121,7 @@ next: working-with-the-browser-zh-CN.html
}
```
既然这个方法描述了在任时间点上的视图,那么文本输入框的值就应该*始终*`Untitled`
该方法在任时间点渲染组件以后,输入框的值就应该 *始终* `Untitled`
### 为什么 `<textarea>` 使用 `value` 属性?
@@ -141,7 +132,7 @@ next: working-with-the-browser-zh-CN.html
<textarea name="description">This is the description.</textarea>
```
对 HTML 而言让开发者设置多行的值很容易。但是React 是 JavaScript没有字符限制,可以使用 `\n` 实现换行。简言之React 已经有 `value``defaultValue` 属性,`</textarea>` 组件的子节点扮演什么角色就有点模棱两可了。基于此, 设置 `<textarea>` 值时不应该使用子节点:
对 HTML 而言让开发者设置多行的值很容易。但是React 是 JavaScript没有字符限制可以使用 `\n` 实现换行。简言之React 已经有 `value``defaultValue` 属性,`</textarea>` 组件的子节点扮演什么角色就有点模棱两可了。基于此, 设置 `<textarea>` 值时不应该使用子节点:
```javascript
<textarea name="description" value="This is a description." />
@@ -161,7 +152,7 @@ HTML 中 `<select>` 通常使用 `<option>` 的 `selected` 属性设置选中状
</select>
```
如果是不受组件,则使用 `defaultValue`
如果是不受组件,则使用 `defaultValue`
> 注意:
>

View File

@@ -22,7 +22,7 @@ next: addons-zh-CN.html
### 浏览器中的JSX转化
如果你喜欢使用JSXBabel5 提供了被称为browser.js 用于开发的一个浏览器的 ES6 和 JSX 转换器,它可以从 [CDNJS](http://cdnjs.com/libraries/babel-core/5.8.34) 引用。Include `<script type="text/babel">` 标记来使用 JSX 转换器.
如果你喜欢使用JSXBabel提供了一个被称为browser.js的[开发用的浏览器的 ES6 和 JSX 转换器](http://babeljs.io/docs/usage/browser/) ,它可以从`babel-core` npm release 或者[CDNJS](http://cdnjs.com/libraries/babel-core) 中 include。Include `<script type="text/babel">` 标记来使用 JSX 转换器.
> 注意:
>

View File

@@ -18,7 +18,7 @@ React插件是一系列的用来构建 React app的有用模块。 **这些应
下面的插件只存在开发版(未压缩)React中
- [`TestUtils`](test-utils.html), 用于写测试用例的简单的辅助工具。
- [`Perf`](perf.html), 一个用于查找优化机会的性能分析工具
- [`TestUtils`](test-utils.html), 用于写测试用例的简单的辅助工具(仅存在于未压缩版本)
- [`Perf`](perf.html), 用于测量性能并给你提示哪里可以优化
要获取插件单独从npm安装他们(例如 `npm install react-addons-pure-render-mixin`).我们不支持使用插件如果你没有用npm.

View File

@@ -10,7 +10,7 @@ next: test-utils.html
> Note:
>
> If you're new to the framework, note that `ReactLink` is not needed for most applications and should be used cautiously.
> ReactLink is deprecated as of React v15. The recommendation is to explicitly set the value and change handler, instead of using ReactLink.
In React, data flows one way: from owner to child. This is because data only flows one direction in [the Von Neumann model of computing](https://en.wikipedia.org/wiki/Von_Neumann_architecture). You can think of it as "one-way data binding."

View File

@@ -10,7 +10,7 @@ next: test-utils-zh-CN.html
> 注意:
>
> 在 React v15 中 ReactLink 被弃用了。推荐明确的设置值和变动的处理,而不是使用 ReactLink
> 如果你刚学这个框架,注意 `ReactLink` 对大多数应用是不需要的,应该慎重的使用
在React里数据单向流动 从拥有者到子级。这是因为数据只单向流动[the Von Neumann model of computing](https://en.wikipedia.org/wiki/Von_Neumann_architecture)。你可以把它想象为 “单向数据绑定”。
@@ -70,7 +70,7 @@ var WithLink = React.createClass({
## 引擎盖下
There are two sides to `ReactLink`: the place where you create the `ReactLink` instance and the place where you use it. To prove how simple `ReactLink` is, let's rewrite each side separately to be more explicit.
这里对 `ReactLink`有两方面:创建`ReactLink`的实例以及使用它的地方。为了证明`ReactLink`有多简单,让我们重写两方面一边更好的理解。
### ReactLink Without LinkedStateMixin
@@ -92,7 +92,7 @@ var WithoutMixin = React.createClass({
});
```
As you can see, `ReactLink` objects are very simple objects that just have a `value` and `requestChange` prop. And `LinkedStateMixin` is similarly simple: it just populates those fields with a value from `this.state` and a callback that calls `this.setState()`.
正如你所见,`ReactLink`对象是非常简单,只有`value``requestChange`属性.并且`LinkStateMixin`也很简单:它只是作用(populates)于`this.state`的元素值并且回调名为`this.setState()`的函数.
### ReactLink Without valueLink
@@ -114,4 +114,4 @@ var WithoutLink = React.createClass({
});
```
The `valueLink` prop is also quite simple. It simply handles the `onChange` event and calls `this.props.valueLink.requestChange()` and also uses `this.props.valueLink.value` instead of `this.props.value`. That's it!
对于`valueLink`的属性同样也很简单,它只是简单的处理`onChange`事件,调用`this.props.valueLink.requestChange()`的时候也使用`this.props.valueLink.requestChange()`代替`this.props.value`.这就是双向绑定!

View File

@@ -30,7 +30,7 @@ React.addons.TestUtils.Simulate.click(node);
```javascript
var node = ReactDOM.findDOMNode(this.refs.input);
node.value = 'giraffe';
node.value = 'giraffe'
React.addons.TestUtils.Simulate.change(node);
React.addons.TestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13});
```

View File

@@ -36,7 +36,7 @@ ReactTestUtils.Simulate.click(node);
```javascript
// <input ref="input" />
var node = this.refs.input;
node.value = 'giraffe';
node.value = 'giraffe'
ReactTestUtils.Simulate.change(node);
ReactTestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13});
```

View File

@@ -36,7 +36,7 @@ ReactTestUtils.Simulate.click(node);
```javascript
// <input ref="input" />
var node = this.refs.input;
node.value = 'giraffe';
node.value = 'giraffe'
ReactTestUtils.Simulate.change(node);
ReactTestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13});
```

View File

@@ -1,244 +0,0 @@
---
id: test-utils-zh-CN
title: 测试工具
permalink: test-utils-zh-CN.html
prev: two-way-binding-helpers-zh-CN.html
next: clone-with-props-zh-CN.html
---
`ReactTestUtils` 使你在你选择的测试框架中 (我们使用 [Jest](https://facebook.github.io/jest/)) 测试 React 组件变得容易。
```
var ReactTestUtils = require('react-addons-test-utils');
```
### Simulate
```javascript
Simulate.{eventName}(
DOMElement element,
[object eventData]
)
```
模拟一个在 DOM 节点上带有可选 `eventData` 事件数据的事件派遣event dispatch。**这可能是 `ReactTestUtils` 里单独最有用的工具。**
**点击一个元素**
```javascript
// <button ref="button">...</button>
var node = this.refs.button;
ReactTestUtils.Simulate.click(node);
```
**改变 input 域的值然后点击 回车。**
```javascript
// <input ref="input" />
var node = this.refs.input;
node.value = 'giraffe';
ReactTestUtils.Simulate.change(node);
ReactTestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13});
```
*注意你将必须提供任何你在你的组件里使用的事件属性(例如 keyCode, which, 等等因为React没有为你创建任何这类东西。*
`Simulate` has a method for [every event that React understands](/react/docs/events.html#supported-events).
### renderIntoDocument
```javascript
ReactComponent renderIntoDocument(
ReactElement instance
)
```
渲染一个组件到 document 里的 detached DOM 节点。**这个函数需要一个 DOM。**
> 注意:
>
> 在你 import React **之前**,你需要让 `window`, `window.document` 和 `window.document.createElement` 全局可用。
不然 React 会认为它不能访问 DOM 然后类似 `setState` 的方法会不工作。
### mockComponent
```javascript
object mockComponent(
function componentClass,
[string mockTagName]
)
```
传入一个 mocked 组件模块到这个方法来给它增加有用的方法,使它可以被用作 dummy React 组件。代替像通常一样的渲染,组件会成为一个简单的包含了任意被提供的子级的 `<div>` (或者其他 tag 名,如果提供了 `mockTagName`
### isElement
```javascript
boolean isElement(
ReactElement element
)
```
返回 `true` 如果 `element` 是任意的 ReactElement。
### isElementOfType
```javascript
boolean isElementOfType(
ReactElement element,
function componentClass
)
```
返回 `true` 如果 `element` 是一个类型是 React `componentClass` 的 ReactElement。
### isDOMComponent
```javascript
boolean isDOMComponent(
ReactComponent instance
)
```
返回 `true` 如果 `instance` 是一个 DOM 组件 (比如一个 `<div>` 或者 `<span>`)。
### isCompositeComponent
```javascript
boolean isCompositeComponent(
ReactComponent instance
)
```
返回 `true` 如果 `instance` 是一个复合组件 (由 `React.createClass()` 创建)。
### isCompositeComponentWithType
```javascript
boolean isCompositeComponentWithType(
ReactComponent instance,
function componentClass
)
```
返回 `true` 如果 `instance` 是一个类型为 React `componentClass` 的复合组件 (由 `React.createClass()` 创建)。
### findAllInRenderedTree
```javascript
array findAllInRenderedTree(
ReactComponent tree,
function test
)
```
遍历 `tree` 里所有的组件,并累积所有 `test(component)``true` 的组件。它本身并没有什么用,但是它被用作其他测试工具的基本元素。
### scryRenderedDOMComponentsWithClass
```javascript
array scryRenderedDOMComponentsWithClass(
ReactComponent tree, string className
)
```
在渲染的树中查找所有 DOM组件的类名匹配`className` 的组件实例。
### findRenderedDOMComponentWithClass
```javascript
ReactComponent findRenderedDOMComponentWithClass(
ReactComponent tree,
string className
)
```
类似 `scryRenderedDOMComponentsWithClass()` 除了只有一个返回结果,并且要么返回这个结果,要么如果还有其他的匹配项就抛出一个异常。
### scryRenderedDOMComponentsWithTag
```javascript
array scryRenderedDOMComponentsWithTag(
ReactComponent tree,
string tagName
)
```
在渲染的树中查找所有 DOM 组件的 tag 名匹配 `tagName` 的组件实例。
### findRenderedDOMComponentWithTag
```javascript
ReactComponent findRenderedDOMComponentWithTag(
ReactComponent tree,
string tagName
)
```
类似 `scryRenderedDOMComponentsWithTag()` 除了只有一个返回结果,并且要么返回这个结果,要么如果还有其他的匹配项就抛出一个异常。
### scryRenderedComponentsWithType
```javascript
array scryRenderedComponentsWithType(
ReactComponent tree,
function componentClass
)
```
查找所有类型等于 `componentClass` 的组件实例。
### findRenderedComponentWithType
```javascript
ReactComponent findRenderedComponentWithType(
ReactComponent tree, function componentClass
)
```
类似 `scryRenderedComponentsWithType()` 除了只有一个返回结果,并且要么返回这个结果,要么如果还有其他的匹配项就抛出一个异常。
## Shallow rendering浅渲染
浅渲染是一个实验性特性,让你渲染一个组件为 "one level deep" 并且断言渲染方法返回的内容,不用担心子组件的行为,它们没有被实例化或者渲染。这个方式不需要一个 DOM。
```javascript
ReactShallowRenderer createRenderer()
```
在你的测试里调用它来创建一个浅渲染器。你可以把它想做是一个你渲染你要测试的组件的 "地方",它可以自己响应事件并更新。
```javascript
shallowRenderer.render(
ReactElement element
)
```
类似于 `ReactDOM.render`
```javascript
ReactElement shallowRenderer.getRenderOutput()
```
`render` 被调用后,返回一个浅渲染的输出。你可以接着断言输出的内容。例如,如果你的组件的渲染方法返回:
```javascript
<div>
<span className="heading">Title</span>
<Subcomponent foo="bar" />
</div>
```
然后你可以断言:
```javascript
var renderer = ReactTestUtils.createRenderer();
result = renderer.getRenderOutput();
expect(result.type).toBe('div');
expect(result.props.children).toEqual([
<span className="heading">Title</span>,
<Subcomponent foo="bar" />
]);
```
浅测试现在有一些限制,即不支持 refs。我们在早期发布这个特性并感激 React 社区关于它应该如何演化的反馈。

View File

@@ -1,36 +0,0 @@
---
id: clone-with-props-zh-CN
title: 克隆 ReactElements
permalink: clone-with-props-zh-CN.html
prev: test-utils-zh-CN.html
next: create-fragment-zh-CN.html
---
> 注意:
> `cloneWithProps` 被弃用了. 用 [React.cloneElement](top-level-api.html#react.cloneelement) 代替.
在很罕见的情况下,你可能需要创建一个 React 元素的拷贝,它与初始的元素有不同的 props。一个例子是克隆这些传递到 `this.props.children` 的元素并用不同的 props 渲染他们。
```js
var cloneWithProps = require('react-addons-clone-with-props');
var _makeBlue = function(element) {
return cloneWithProps(element, {style: {color: 'blue'}});
};
var Blue = React.createClass({
render: function() {
var blueChildren = React.Children.map(this.props.children, _makeBlue);
return <div>{blueChildren}</div>;
}
});
ReactDOM.render(
<Blue>
<p>This text is blue.</p>
</Blue>,
document.getElementById('container')
);
```
`cloneWithProps` 不传递 `key` 或者 `ref` 到被克隆的元素。`className``style` props 被自动合并。

View File

@@ -1,75 +0,0 @@
---
id: create-fragment-zh-CN
title: Keyed Fragments
permalink: create-fragment-zh-CN.html
prev: clone-with-props-zh-CN.html
next: update-zh-CN.html
---
在大多数情况下,你可以使用 `key` prop 指定你从 `render` 返回的元素的 keys。然而这在一个情况下会失败如果你有两组你需要记录的子级将没有办法在不使用包裹元素的情况下放置一个 key 到每组上。
即是,如果你有一个像这样的组件:
```js
var Swapper = React.createClass({
propTypes: {
// `leftChildren` and `rightChildren` can be a string, element, array, etc.
leftChildren: React.PropTypes.node,
rightChildren: React.PropTypes.node,
swapped: React.PropTypes.bool
},
render: function() {
var children;
if (this.props.swapped) {
children = [this.props.rightChildren, this.props.leftChildren];
} else {
children = [this.props.leftChildren, this.props.rightChildren];
}
return <div>{children}</div>;
}
});
```
这些子级会在当你改变 `swapped` prop 时加载和卸载,因为没有任何的 key 标记在这两组子级上。
要解决这个问题,你可以使用 `createFragment` 插件来给予这两组子级 keys.
#### `Array<ReactNode> createFragment(object children)`
代替创建数组,我们这样写:
```js
var createFragment = require('react-addons-create-fragment');
if (this.props.swapped) {
children = createFragment({
right: this.props.rightChildren,
left: this.props.leftChildren
});
} else {
children = createFragment({
left: this.props.leftChildren,
right: this.props.rightChildren
});
}
```
被传入对象的 keys (即 `left``right`)被用作为整组子级的 keys并且对象 keys 的顺序被用于决定渲染子级的顺序。通过这个改变,这两个子级将会恰当的在 DOM 里排序,而不被卸载。
`createFragment` 的返回值应该被对待为一个不透明的对象;你可以使用 `React.Children` 来遍历一个 fragment 但是不应该直接访问它。同样注意,我们依赖于 JavaScript 引擎保留了对象的枚举顺序,这点在 spec 上是不保证的,但是所有主要的浏览器和 VMs 都对非数字键的对象实现了这个特性。
> **注意:**
>
> 将来,`createFragment` 也许会被替换为如下的API
>
> ```js
> return (
> <div>
> <x:frag key="right">{this.props.rightChildren}</x:frag>,
> <x:frag key="left">{this.props.leftChildren}</x:frag>
> </div>
> );
> ```
>
> 允许你直接在 JSX 里赋值 keys 而不用添加包裹元素。

View File

@@ -1,102 +0,0 @@
---
id: update-zh-CN
title: immutability 助手
permalink: update-zh-CN.html
prev: create-fragment-zh-CN.html
next: pure-render-mixin-zh-CN.html
---
React 让你可以使用任何你想要的数据管理方式,包括 mutation。然而如果你可以在你的应用的性能关键性部分里使用 immutable 数据,将会易于实现一个快速的 `shouldComponentUpdate()` 方法来显著加速你的 app。
在 JavaScript 里处理 immutable 数据比在为此设计的语言中要难的多,比如 [Clojure](http://clojure.org/)。然而,我们提供了一个简单的 immutability 助手,`update()`,它使处理这类数据容易多了,*不用* 根本性的改变你的数据的表达方式。你也同样可以看一看 Facebook 的 [Immutable-js](https://facebook.github.io/immutable-js/docs/) 和[Advanced Performance](/react/docs/advanced-performance.html) 了解更多关于 Immutable-js 的信息。
## 主要的思路
如果你像这样变动数据:
```js
myData.x.y.z = 7;
// or...
myData.a.b.push(9);
```
你将没有任何办法决定哪个数据被改变了,因为之前的拷贝已经被覆盖。作为替代,你需要创建一个新的 `myData` 的拷贝并且只修改需要改变的地方。然后你可以用三个等于在 `shouldComponentUpdate()` 里比较旧的 `myData` 拷贝与新的拷贝:
```js
var newData = deepCopy(myData);
newData.x.y.z = 7;
newData.a.b.push(9);
```
不幸的是,深拷贝很昂贵,并且有时候不可能。你可以通过仅仅拷贝需要被改变和重用没有改变的对象来缓解这个情况。不幸的是,在当今的 JavaScript 里这会很笨重:
```js
var newData = extend(myData, {
x: extend(myData.x, {
y: extend(myData.x.y, {z: 7}),
}),
a: extend(myData.a, {b: myData.a.b.concat(9)})
});
```
虽然这相当高性能(因为只对 `log n` 的对象进行了浅拷贝并重用了剩下的),但它写起来很痛苦。看看所有重复的代码!这不仅仅是烦人的,同时也提供了一大片 bugs 区域。
`update()` 提供了这个模式的简单语法糖来使写这类代码更容易。上面的代码变成:
```js
var update = require('react-addons-update');
var newData = update(myData, {
x: {y: {z: {$set: 7}}},
a: {b: {$push: [9]}}
});
```
虽然这个语法需要花一些时间来适应(它的灵感来自于 [MongoDB's query language](http://docs.mongodb.org/manual/core/crud-introduction/#query)),但是没有冗余,它可静态分析并且没有 mutative 版本那么多键入。
`$`-前缀的 keys 被称为 *命令*。被 "变动的" 数据结构被称为 *目标*
## 有效的命令
* `{$push: array}` 在目标上 `push()` 所有 `array` 里的项目。
* `{$unshift: array}` 在目标上 `unshift()` 所有 `array` 里的项目。
* `{$splice: array of arrays}` 在目标上对于每一个 `arrays` 里的项目使用项目提供的参数调用 `splice()`
* `{$set: any}` 整个替换目标.
* `{$merge: object}` 合并 目标和 `object` 的 keys.
* `{$apply: function}` 传递当前的值给 function 并用返回值更新它。
## 例子
### 简单的 push
```js
var initialArray = [1, 2, 3];
var newArray = update(initialArray, {$push: [4]}); // => [1, 2, 3, 4]
```
`initialArray` is still `[1, 2, 3]`.
### 嵌套的 collections
```js
var collection = [1, 2, {a: [12, 17, 15]}];
var newCollection = update(collection, {2: {a: {$splice: [[1, 1, 13, 14]]}}});
// => [1, 2, {a: [12, 13, 14, 15]}]
```
本例访问了 `collection``2`索引下的键`a`,并且拼接了一个从索引`1`开始(移除`17`)并插入`13``14`的项目。
### 基于当前的值更新新值
```js
var obj = {a: 5, b: 3};
var newObj = update(obj, {b: {$apply: function(x) {return x * 2;}}});
// => {a: 5, b: 6}
// This is equivalent, but gets verbose for deeply nested collections:
var newObj2 = update(obj, {b: {$set: obj.b * 2}});
```
### (浅) 合并
```js
var obj = {a: 5, b: 3};
var newObj = update(obj, {$merge: {b: 6, c: 7}}); // => {a: 5, b: 6, c: 7}
```

View File

@@ -1,46 +0,0 @@
---
id: pure-render-mixin-zh-CN
title: PureRenderMixin
permalink: pure-render-mixin-zh-CN.html
prev: update-zh-CN.html
next: perf-zh-CN.html
---
如果你的 React 组件的 render 函数是 "纯净" 的(换句话说,它的渲染在给定相同的 props 和 state 时返回相同的结果),你可以使用这个 mixin 在某些情况下进行性能加速。
例子:
```js
var PureRenderMixin = require('react-addons-pure-render-mixin');
React.createClass({
mixins: [PureRenderMixin],
render: function() {
return <div className={this.props.className}>foo</div>;
}
});
```
使用 ES6 class 语法的例子:
```js
import PureRenderMixin from 'react-addons-pure-render-mixin';
class FooComponent extends React.Component {
constructor(props) {
super(props);
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
render() {
return <div className={this.props.className}>foo</div>;
}
}
```
在内部, mixin 实现了 [shouldComponentUpdate](/react/docs/component-specs.html#updating-shouldcomponentupdate), 它对当前及下一步的 props 和 state 进行比较,并当相等时返回 `false`
> 注意:
>
> 它仅仅浅比较对象。如果包含了复杂的对象,可能会对于深层的不同产生 false-negatives。只 mix 到那些含有简单 props 和 state 的组件,或者在你知道深层对象改变时使用 `forceUpdate()` 。或者,考虑使用[immutable objects](https://facebook.github.io/immutable-js/) 来促进快速的嵌套数据比较。
>
> 此外, `shouldComponentUpdate` 跳过了整个子树的更新。确保所有的子组件都是 "纯净" 的。

View File

@@ -1,74 +0,0 @@
---
id: perf-zh-CN
title: 性能工具
permalink: perf-zh-CN.html
prev: pure-render-mixin-zh-CN.html
next: shallow-compare-zh-CN.html
---
React 通常是相当快的。然而,在你需要压榨你的 app 的每一分性能的情况下,它提供了一个[shouldComponentUpdate](/react/docs/component-specs.html#updating-shouldcomponentupdate) 钩子,在此你可以添加优化提示到 React 的 diff 算法里。
除了给予你一个你的 app 的整体性能概览外ReactPerf 还是一个准确告诉你,你需要在哪里放置这些钩子的分析工具。
## General API
这里陈述的 `Perf` 对象被用 `require('react-addons-perf')` 暴露,并且只能被使用在 React 的开发模式。你不应在生产环境下在你的 app 包含这个包。
> 注意:
>
> 开发版的 React 慢于生产版因为所有额外提供的逻辑例如React 的友好的控制台警告 (在生产版中被除去)。因此,分析工具仅服务于指示你的 app _相对_ 昂贵的部分。
### `Perf.start()` and `Perf.stop()`
开始/停止测量。其间的React操作被记录用于之后的分析。产生无关紧要时间的操作被忽略。
在停止以后,你将需要 `Perf.getLastMeasurements()` (下面将介绍)来获取测量结果。
### `Perf.printInclusive(measurements)`
打印总体花费的时间。如果没有传入参数,默认是从上次记录的所有测量数据。它在控制台里打印良好格式化的结果,像这样:
![](/react/img/docs/perf-inclusive.png)
### `Perf.printExclusive(measurements)`
"独占的"时间不包括花费于加载组件的时间: 处理 props, `getInitialState`, 调用 `componentWillMount``componentDidMount`, 等等。
![](/react/img/docs/perf-exclusive.png)
### `Perf.printWasted(measurements)`
**分析工具里最有用的部分**.
"垃圾"时间是花费在组件上实际没有绘制任何东西的时间,例如渲染结果总是相同,所以 DOM 没有被触碰到。
![](/react/img/docs/perf-wasted.png)
### `Perf.printDOM(measurements)`
打印底层的 DOM 操纵,例如 "set innerHTML" 和 "remove".
![](/react/img/docs/perf-dom.png)
## Advanced API
以上的打印方法使用 `Perf.getLastMeasurements()` 来美观的打印结果。
### `Perf.getLastMeasurements()`
从最后的 start-stop 会话获取测量数据数据。这个数组包含对象,每个看起来像这样:
```js
{
// The term "inclusive" and "exclusive" are explained below
"exclusive": {},
// '.0.0' is the React ID of the node
"inclusive": {".0.0": 0.0670000008540228, ".0": 0.3259999939473346},
"render": {".0": 0.036999990697950125, ".0.0": 0.010000003385357559},
// Number of instances
"counts": {".0": 1, ".0.0": 1},
// DOM touches
"writes": {},
// Extra debugging info
"displayNames": {
".0": {"current": "App", "owner": "<root>"},
".0.0": {"current": "Box", "owner": "App"}
},
"totalTime": 0.48499999684281647
}
```

View File

@@ -177,7 +177,7 @@ var MediaQuery = React.createClass({
},
componentDidMount: function(){
var checkMediaQuery = function(){
var type = window.matchMedia("(min-width: 1025px)").matches ? 'desktop' : 'mobile';
var type = window.matchMedia("min-width: 1025px").matches ? 'desktop' : 'mobile';
if (type !== this.state.type){
this.setState({type:type});
}

View File

@@ -5,7 +5,7 @@ permalink: context-zh-CN.html
prev: advanced-performance-zh-CN.html
---
React最大的优势之一是很容易从你的React组件里跟踪数据流动。当你看着一个组件你可以很容易准确看出哪个props被传入这让你的APP很容易推断。
React最大的优势之一是很容易从你的React组件里跟踪数据流动。当你看着一个组件你可以很容易准确看出哪个props被传入这让你的APP很容易推断。
偶尔你想通过组件树传递数据而不在每一级上手工下传propReact的 "context" 让你做到这点。
@@ -160,38 +160,6 @@ function Button(props, context) {
Button.contextTypes = {color: React.PropTypes.string};
```
## Updating context
当 state 或者 props 变化时 `getChildContext` 函数会被调用。为了更新context里的数据用 `this.setState` 触发一个本地的state更新。这将会触发一个新的 context 并且子级将收到变化。
```javascript
var MediaQuery = React.createClass({
getInitialState: function(){
return {type:'desktop'};
},
childContextTypes: {
type: React.PropTypes.string
},
getChildContext: function() {
return {type: this.state.type};
},
componentDidMount: function(){
var checkMediaQuery = function(){
var type = window.matchMedia("(min-width: 1025px)").matches ? 'desktop' : 'mobile';
if (type !== this.state.type){
this.setState({type:type});
}
};
window.addEventListener('resize', checkMediaQuery);
checkMediaQuery();
},
render: function(){
return this.props.children;
}
});
```
## 什么时候不用 context
正像全局变量是在写清晰代码时最好要避免的,你应该在大多数情况下避免使用context. 特别是,在用它来"节省输入"和代替显示传入props时要三思.

View File

@@ -46,15 +46,6 @@ $ webpack
>
> 如果你正在使用 ES2015, 你将要使用 `babel-preset-es2015` 包.
**注意:** 默认情况下React 将会在开发模式,很缓慢,不建议用于生产。要在生产模式下使用 React设置环境变量 `NODE_ENV``production` (使用 envify 或者 webpack's DefinePlugin。例如
```js
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
});
```
## 不用 npm 的快速开始
@@ -90,7 +81,7 @@ new webpack.DefinePlugin({
</html>
```
在 JavaScript 代码里写着 XML 格式的代码称为 JSX可以去 [JSX 语法](/react/docs/jsx-in-depth.html) 里学习更多 JSX 相关的知识。为了把 JSX 转成标准的 JavaScript我们用 `<script type="text/babel">` 标签,并引入 Babel 来完成在浏览器里的代码转换。在浏览器里打开这个html你应该可以看到成功的消息
在 JavaScript 代码里写着 XML 格式的代码称为 JSX可以去 [JSX 语法](/react/docs/jsx-in-depth.html) 里学习更多 JSX 相关的知识。为了把 JSX 转成标准的 JavaScript我们用 `<script type="text/babel">` 标签,并引入 Babel 来完成在浏览器里的代码转换。
### 分离文件
@@ -139,7 +130,6 @@ ReactDOM.render(
);
```
对照下面更新你的 HTML 代码
```html{8,12}

View File

@@ -86,13 +86,6 @@ There is also the React-specific attribute `dangerouslySetInnerHTML` ([more here
### SVG Attributes
```
clipPath cx cy d dx dy fill fillOpacity fontFamily
fontSize fx fy gradientTransform gradientUnits markerEnd
markerMid markerStart offset opacity patternContentUnits
patternUnits points preserveAspectRatio r rx ry spreadMethod
stopColor stopOpacity stroke strokeDasharray strokeLinecap
strokeOpacity strokeWidth textAnchor transform version
viewBox x1 x2 x xlinkActuate xlinkArcrole xlinkHref xlinkRole
xlinkShow xlinkTitle xlinkType xmlBase xmlLang xmlSpace y1 y2 y
```
Any attributes passed to SVG tags are passed through without changes.
React used to support special camelCase aliases for certain SVG attributes, such as `clipPath`. If you use them now you'll see a deprecation warning. These aliases will be removed in the next version in favor of their real names from the SVG specification, such as `clip-path`. Attributes that have a camelCase name in the spec, such as `gradientTransform`, will keep their names.

View File

@@ -18,11 +18,11 @@ React试着支持所有常见的元素.如果你需要一个没有列在这里
a abbr address area article aside audio b base bdi bdo big blockquote body br
button canvas caption cite code col colgroup data datalist dd del details dfn
dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5
h6 head header hgroup hr html i iframe img input ins kbd keygen label legend li
link main map mark menu menuitem meta meter nav noscript object ol optgroup
option output p param picture pre progress q rp rt ruby s samp script section
select small source span strong style sub summary sup table tbody td textarea
tfoot th thead time title tr track u ul var video wbr
h6 head header hr html i iframe img input ins kbd keygen label legend li link
main map mark menu menuitem meta meter nav noscript object ol optgroup option
output p param picture pre progress q rp rt ruby s samp script section select
small source span strong style sub summary sup table tbody td textarea tfoot th
thead time title tr track u ul var video wbr
```
### SVG 元素
@@ -30,8 +30,8 @@ tfoot th thead time title tr track u ul var video wbr
下面的 SVG 元素是被支持的:
```
circle clipPath defs ellipse g image line linearGradient mask path pattern
polygon polyline radialGradient rect stop svg text tspan
circle clipPath defs ellipse g line linearGradient mask path pattern polygon polyline
radialGradient rect stop svg text tspan
```
你也许对 [react-art](https://github.com/facebook/react-art)有兴趣,一个让React绘制Canvas, SVG, 或者 VML (for IE8) 的绘制库.
@@ -53,33 +53,25 @@ React支持所有的 `data-*` 和 `aria-*` 以及下列的属性.
```
accept acceptCharset accessKey action allowFullScreen allowTransparency alt
async autoComplete autoFocus autoPlay capture cellPadding cellSpacing challenge
charSet checked classID className colSpan cols content contentEditable
contextMenu controls coords crossOrigin data dateTime default defer dir
disabled download draggable encType form formAction formEncType formMethod
formNoValidate formTarget frameBorder headers height hidden high href hrefLang
htmlFor httpEquiv icon id inputMode integrity is keyParams keyType kind label
lang list loop low manifest marginHeight marginWidth max maxLength media
mediaGroup method min minLength multiple muted name noValidate nonce open
optimum pattern placeholder poster preload radioGroup readOnly rel required
reversed role rowSpan rows sandbox scope scoped scrolling seamless selected
shape size sizes span spellCheck src srcDoc srcLang srcSet start step style
summary tabIndex target title type useMap value width wmode wrap
```
这些RDFa属性是被支持的 许多RDFa属性和标准的HTML属性重叠因此被从这个列表里去除
```
about datatype inlist prefix property resource typeof vocab
async autoComplete autoFocus autoPlay capture cellPadding cellSpacing charSet
challenge checked classID className cols colSpan content contentEditable contextMenu
controls coords crossOrigin data dateTime defer dir disabled download draggable
encType form formAction formEncType formMethod formNoValidate formTarget frameBorder
headers height hidden high href hrefLang htmlFor httpEquiv icon id inputMode
keyParams keyType label lang list loop low manifest marginHeight marginWidth max
maxLength media mediaGroup method min minLength multiple muted name noValidate open
optimum pattern placeholder poster preload radioGroup readOnly rel required role
rows rowSpan sandbox scope scoped scrolling seamless selected shape size sizes
span spellCheck src srcDoc srcSet start step style summary tabIndex target title
type useMap value width wmode wrap
```
另外,支持下面的非标准属性:
- `autoCapitalize autoCorrect` for Mobile Safari.
- `color` for `<link rel="mask-icon" />` in Safari.
- `property` for [Open Graph](http://ogp.me/) meta tags.
- `itemProp itemScope itemType itemRef itemID` for [HTML5 microdata](http://schema.org/docs/gs.html).
- `security` 老的IE浏览器.
- `unselectable` IE浏览器.
- `unselectable` for Internet Explorer.
- `results autoSave` for WebKit/Blink input fields of type `search`.
同样有React规范的属性 `dangerouslySetInnerHTML` ([more here](/react/docs/special-non-dom-attributes.html)),用于直接插入HTML字符串到组件里.

View File

@@ -137,6 +137,8 @@ Properties:
DOMEventTarget relatedTarget
```
These focus events work on all elements in the React DOM, not just form elements.
### Form Events
@@ -245,6 +247,7 @@ number deltaY
number deltaZ
```
### Media Events
Event names:
@@ -253,6 +256,7 @@ Event names:
onAbort onCanPlay onCanPlayThrough onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting
```
### Image Events
Event names:
@@ -260,3 +264,37 @@ Event names:
```
onLoad onError
```
### Animation Events
Event names:
```
onAnimationStart onAnimationEnd onAnimationIteration
```
Properties:
```javascript
string animationName
string pseudoElement
float elapsedTime
```
### Transition Events
Event names:
```
onTransitionEnd
```
Properties:
```javascript
string propertyName
string pseudoElement
float elapsedTime
```

View File

@@ -139,7 +139,6 @@ DOMEventTarget relatedTarget
焦点事件在所有的React DOM上工作,不仅仅是表单元素.
### 表单事件
事件名称:
@@ -247,8 +246,7 @@ number deltaY
number deltaZ
```
### 媒体事件
### Media Events
事件名称:
@@ -256,45 +254,10 @@ number deltaZ
onAbort onCanPlay onCanPlayThrough onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting
```
### 图片事件
### Image Events
事件名称:
```
onLoad onError
```
### 动画事件
事件名称:
```
onAnimationStart onAnimationEnd onAnimationIteration
```
属性:
```javascript
string animationName
string pseudoElement
float elapsedTime
```
### Transition Events
事件名称:
```
onTransitionEnd
```
属性:
```javascript
string propertyName
string pseudoElement
float elapsedTime
```

View File

@@ -31,7 +31,7 @@ Our JSON API returns some data that looks like this:
];
```
## Step 1: break the UI into a component hierarchy
## Step 1: Break the UI into a component hierarchy
The first thing you'll want to do is to draw boxes around every component (and subcomponent) in the mock and give them all names. If you're working with a designer, they may have already done this, so go talk to them! Their Photoshop layer names may end up being the names of your React components!

View File

@@ -44,7 +44,6 @@ next: thinking-in-react-zh-CN.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/{{site.react_version}}/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
</head>
<body>
<div id="content"></div>
@@ -97,7 +96,7 @@ ReactDOM.render(
#### JSX 语法
首先你会注意到你的 JavaScript 中 XML 式的语法。我们有一个简单的预编译器,将语法糖转换成这种纯的JavaScript
首先你会注意到你的 JavaScript 中 XML 式的语法。我们有一个简单的预编译器,将这种语法糖转换成纯的 JavaScript
```javascript
// tutorial1-raw.js
@@ -128,10 +127,6 @@ ReactDOM.render(
`ReactDOM.render()` 实例化根组件,启动框架,注入标记到原始的 DOM 元素中,作为第二个参数提供。
`ReactDOM` 模块暴露了 DOM 相关的方法, 而 `React` 保有被不同平台的 React 共享的核心工具 (例如 [React Native](http://facebook.github.io/react-native/))。
对于本教程 `ReactDOM.render` 保持在脚本底部是很重要的。`ReactDOM.render` 应该只在复合组件被定义之后被调用。
## 组合组件
让我们为 `CommentList``CommentForm` 建造骨架,它们将会,再一次的,是一些简单的 `<div>`。添加这两个组件到你的文件里,保持现存的 `CommentBox` 声明和 `ReactDOM.render` 调用:
@@ -224,7 +219,22 @@ var CommentList = React.createClass({
Markdown 是一种简单的内联格式化你的文字的方法。例如,用星号包围文本将会使其强调突出。
在本教程中我们使用第三方库 **marked**接受 Markdown 文本并且转换为原始的 HTML。我们已经在初始的页面标记里包含了这个库,所以我们可以直接开始使用它,让我们转换评论文本为 Markdown 并输出它
首先,添加第三方库 **marked** 到你的应用。这是一个JavaScript库,接受 Markdown 文本并且转换为原始的 HTML。这需要在你的头部有一个 script 标签(那个我们已经在 React 操场上包含了的标签)
```html{9}
<!-- index.html -->
<head>
<meta charset="utf-8" />
<title>React Tutorial</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/{{site.react_version}}/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/{{site.react_version}}/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
</head>
```
然后,让我们转换评论文本为 Markdown 并输出它:
```javascript{9}
// tutorial6.js
@@ -280,12 +290,12 @@ var Comment = React.createClass({
```javascript
// tutorial8.js
var data = [
{id: 1, author: "Pete Hunt", text: "This is one comment"},
{id: 2, author: "Jordan Walke", text: "This is *another* comment"}
{author: "Pete Hunt", text: "This is one comment"},
{author: "Jordan Walke", text: "This is *another* comment"}
];
```
我们需要以一种模块化的方式将这个数据传入到 `CommentList`。修改 `CommentBox` 和 `ReactDOM.render()` 方法,以便于通过 props 传入数据到 `CommentList`
我们需要以一种模块化的方式将这个数据传入到 `CommentList`。修改 `CommentBox` 和 `ReactDOM.render()` 方法,以通过 props 传入数据到 `CommentList`
```javascript{7,15}
// tutorial9.js
@@ -313,9 +323,9 @@ ReactDOM.render(
// tutorial10.js
var CommentList = React.createClass({
render: function() {
var commentNodes = this.props.data.map(function(comment) {
var commentNodes = this.props.data.map(function (comment) {
return (
<Comment author={comment.author} key={comment.id}>
<Comment author={comment.author}>
{comment.text}
</Comment>
);
@@ -376,7 +386,7 @@ var CommentBox = React.createClass({
`getInitialState()` 在生命周期里只执行一次,并设置组件的初始状态。
#### 更新状态
当组件第一次创建时,我们想从服务器获取一些 JSON 并且更新状态以反映最新的数据。我们将用 jQuery 来发送一个异步请求到我们刚才启动的服务器以获取我们需要的数据。这些数据已经被包含在了你已启动的服务器里(基于`comments.json`文件),所以一旦被获取,`this.state.data` 会看起来像这样:
当组件第一次创建时,我们想从服务器获取一些 JSON 并且更新状态以反映最新的数据。我们将用 jQuery 来发送一个异步请求到我们刚才启动的服务器以获取我们需要的数据。看起来像这样:
```json
[
@@ -480,39 +490,28 @@ var CommentForm = React.createClass({
});
```
#### 受控组件
让我们做一个交互式的表单。当用户提交表单时,我们应该清空它,提交一个请求给服务器,和刷新评论列表。要开始,让我们监听表单的提交事件并清空它。
对于传统的 DOM `input` 元素被渲染并且浏览器管理它的状态它的渲染值。结果是DOM的实际值会和组件不同。这是不理想的因为视图的值会和组件的值不同。在React中组件应该总是表示视图的值而不只是在初始化时。
因此,我们将使用 `this.state` 来在用户输入时保存输入。我们定义一个初始 `state`,它带有 `author` 和 `text` 两个属性并将他们设置为空字符串。在我们的 `<input>` 元素里,我们设置 `value` prop 来反映组件的 `state` 并给他们附加 `onChange` 事件处理。这些带有设置了 `value` 的 `<input>` 元素被称为受控组件。更多关于受控组件请阅读 [Forms article](/react/docs/forms.html#controlled-components)。
```javascript{3-11,15-26}
```javascript{3-14,16-19}
// tutorial16.js
var CommentForm = React.createClass({
getInitialState: function() {
return {author: '', text: ''};
},
handleAuthorChange: function(e) {
this.setState({author: e.target.value});
},
handleTextChange: function(e) {
this.setState({text: e.target.value});
handleSubmit: function(e) {
e.preventDefault();
var author = React.findDOMNode(this.refs.author).value.trim();
var text = React.findDOMNode(this.refs.text).value.trim();
if (!text || !author) {
return;
}
// TODO: send request to the server
React.findDOMNode(this.refs.author).value = '';
React.findDOMNode(this.refs.text).value = '';
return;
},
render: function() {
return (
<form className="commentForm">
<input
type="text"
placeholder="Your name"
value={this.state.author}
onChange={this.handleAuthorChange}
/>
<input
type="text"
placeholder="Say something..."
value={this.state.text}
onChange={this.handleTextChange}
/>
<form className="commentForm" onSubmit={this.handleSubmit}>
<input type="text" placeholder="Your name" ref="author" />
<input type="text" placeholder="Say something..." ref="text" />
<input type="submit" value="Post" />
</form>
);
@@ -522,60 +521,14 @@ var CommentForm = React.createClass({
##### 事件
React使用驼峰命名规范(camelCase)给组件绑定事件处理器。我们附加 `onChange` 给两个 `<input>` 元素。现在,当用户输入文本到 `<input>` 中,被附加的 `onChange` 回调函数被激发并且组件的 `state` 被修改。然后,被渲染的 `input` 元素的值将会更新以反映当前组件的 `state`
#### 提交表单
让我们使表单具有交互性。当用户提交表单时,我们应该清除它,提交一个请求到服务器,并刷新评论列表。让我们监听表单的提交事件并清除它。
```javascript{12-21,24}
// tutorial17.js
var CommentForm = React.createClass({
getInitialState: function() {
return {author: '', text: ''};
},
handleAuthorChange: function(e) {
this.setState({author: e.target.value});
},
handleTextChange: function(e) {
this.setState({text: e.target.value});
},
handleSubmit: function(e) {
e.preventDefault();
var author = this.state.author.trim();
var text = this.state.text.trim();
if (!text || !author) {
return;
}
// TODO: send request to the server
this.setState({author: '', text: ''});
},
render: function() {
return (
<form className="commentForm" onSubmit={this.handleSubmit}>
<input
type="text"
placeholder="Your name"
value={this.state.author}
onChange={this.handleAuthorChange}
/>
<input
type="text"
placeholder="Say something..."
value={this.state.text}
onChange={this.handleTextChange}
/>
<input type="submit" value="Post" />
</form>
);
}
});
```
我们给表单绑定一个`onSubmit`处理器,它在表单提交了合法的输入后清空表单字段。
React使用驼峰命名规范(camelCase)给组件绑定事件处理器。我们给表单绑定一个`onSubmit`处理器,它在表单提交了合法的输入后清空表单字段
在事件中调用`preventDefault()`来阻止浏览器提交表单的默认行为。
##### Refs
我们利用`ref`属性给子组件赋予名字,`this.refs`-引用组件。我们可以在组件上调用 `React.findDOMNode(component)` 获取原生的浏览器DOM元素。
##### 回调函数作为属性
当用户提交评论时,我们需要刷新评论列表来包含这条新评论。在`CommentBox`中完成所有逻辑是有道理的,因为`CommentBox` 拥有代表了评论列表的状态(state)。
@@ -583,7 +536,7 @@ var CommentForm = React.createClass({
我们需要从子组件传回数据到它的父组件。我们在父组件的`render`方法中以传递一个新的回调函数(`handleCommentSubmit`)到子组件完成这件事,绑定它到子组件的 `onCommentSubmit` 事件上。无论事件什么时候触发,回调函数都将被调用:
```javascript{16-18,31}
// tutorial18.js
// tutorial17.js
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
$.ajax({
@@ -620,45 +573,28 @@ var CommentBox = React.createClass({
});
```
既然 `CommentBox` 已经通过 `onCommentSubmit` prop 使回调函数对于 `CommentForm` 可用,`CommentForm` 就可以在用户提交表单时调用回调函数:
当用户提交表单时,让我们从 `CommentForm` 调用这个回调函数:
```javascript{19}
// tutorial19.js
```javascript{10}
// tutorial18.js
var CommentForm = React.createClass({
getInitialState: function() {
return {author: '', text: ''};
},
handleAuthorChange: function(e) {
this.setState({author: e.target.value});
},
handleTextChange: function(e) {
this.setState({text: e.target.value});
},
handleSubmit: function(e) {
e.preventDefault();
var author = this.state.author.trim();
var text = this.state.text.trim();
var author = React.findDOMNode(this.refs.author).value.trim();
var text = React.findDOMNode(this.refs.text).value.trim();
if (!text || !author) {
return;
}
this.props.onCommentSubmit({author: author, text: text});
this.setState({author: '', text: ''});
React.findDOMNode(this.refs.author).value = '';
React.findDOMNode(this.refs.text).value = '';
return;
},
render: function() {
return (
<form className="commentForm" onSubmit={this.handleSubmit}>
<input
type="text"
placeholder="Your name"
value={this.state.author}
onChange={this.handleAuthorChange}
/>
<input
type="text"
placeholder="Say something..."
value={this.state.text}
onChange={this.handleTextChange}
/>
<input type="text" placeholder="Your name" ref="author" />
<input type="text" placeholder="Say something..." ref="text" />
<input type="submit" value="Post" />
</form>
);
@@ -669,7 +605,7 @@ var CommentForm = React.createClass({
既然现在回调函数已经就绪,我们所需要做的就是提交到服务器然后刷新列表:
```javascript{17-28}
// tutorial20.js
// tutorial19.js
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
$.ajax({
@@ -721,8 +657,8 @@ var CommentBox = React.createClass({
我们的应用现在已经功能完备,但是它感觉很慢,因为在评论出现在列表前必须等待请求完成。我们可以优化添加这条评论到列表以使应用感觉更快。
```javascript{17-23,33}
// tutorial21.js
```javascript{17-19,29}
// tutorial20.js
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
$.ajax({
@@ -739,10 +675,6 @@ var CommentBox = React.createClass({
},
handleCommentSubmit: function(comment) {
var comments = this.state.data;
// Optimistically set an id on the new comment. It will be replaced by an
// id generated by the server. In a production application you would likely
// not use Date.now() for this and would have a more robust system in place.
comment.id = Date.now();
var newComments = comments.concat([comment]);
this.setState({data: newComments});
$.ajax({

View File

@@ -29,7 +29,7 @@ Un video di [tagtree.tv](http://tagtree.tv/) che espone i principi di [Pensare i
* * *
### Pensare in grande con React ###
### Pensare in grande con React
"Sulla carta, tutti questi framework JS sembrano promettenti: implementazioni pulite, design veloce del codice, esecuzione perfetta. Ma che succede quando metti Javascript sotto stress? Che succede se gli dài in pasto 6 megabyte di codice? In questo talk investigheremo come si comporta React in situazioni di stress elevato, e come ha aiutato il nostro team a costruire codice sicuro ad una scala enorme."
<figure>[![](https://i.vimeocdn.com/video/481670116_650.jpg)](https://skillsmatter.com/skillscasts/5429-going-big-with-react#video)</figure>

View File

@@ -29,7 +29,7 @@ A [tagtree.tv](http://tagtree.tv/) video conveying the principles of [Thinking i
* * *
### Going big with React ###
### Going big with React
"On paper, all those JS frameworks look promising: clean implementations, quick code design, flawless execution. But what happens when you stress test Javascript? What happens when you throw 6 megabytes of code at it? In this talk, we'll investigate how React performs in a high stress situation, and how it has helped our team build safe code on a massive scale."
<figure>[![](https://i.vimeocdn.com/video/481670116_650.jpg)](https://skillsmatter.com/skillscasts/5429-going-big-with-react#video)</figure>

View File

@@ -29,7 +29,7 @@ next: complementary-tools-zh-CN.html
* * *
### Going big with React ###
### Going big with React
"理论上所有的JS框架都大有可为干净的实现,快速的代码设计,完美的执行。但是当你压力测试时Javascript会怎样当你丢进6MB的代码时会怎样在这次演讲中我们会探究React在高压环境下如何表现以及它如何帮助我们的团队在大规模时构建安全代码。 "
<figure>[![](https://i.vimeocdn.com/video/481670116_650.jpg)](https://skillsmatter.com/skillscasts/5429-going-big-with-react#video)</figure>

View File

@@ -24,32 +24,48 @@ If you're just starting out, make sure to use the development version.
The uncompressed, development version of [react.js](https://fb.me/react-{{site.react_version}}.js) and [react-dom.js](https://fb.me/react-dom-{{site.react_version}}.js) with inline documentation (you need both files).
```html
<script src="https://fb.me/react-{{site.react_version}}.js"></script>
<script src="https://fb.me/react-dom-{{site.react_version}}.js"></script>
<script src="https://fb.me/react-{{site.react_version}}.js"
integrity="sha384-{{site.react_hashes.dev}}"
crossorigin="anonymous"></script>
<script src="https://fb.me/react-dom-{{site.react_version}}.js"
integrity="sha384-{{site.react_hashes.dom_dev}}"
crossorigin="anonymous"></script>
```
#### React {{site.react_version}} (production)
The compressed, production version of [react.js](https://fb.me/react-{{site.react_version}}.min.js) and [react-dom.js](https://fb.me/react-dom-{{site.react_version}}.min.js) (you need both).
```html
<script src="https://fb.me/react-{{site.react_version}}.min.js"></script>
<script src="https://fb.me/react-dom-{{site.react_version}}.min.js"></script>
<script src="https://fb.me/react-{{site.react_version}}.min.js"
integrity="sha384-{{site.react_hashes.prod}}"
crossorigin="anonymous"></script>
<script src="https://fb.me/react-dom-{{site.react_version}}.min.js"
integrity="sha384-{{site.react_hashes.dom_prod}}"
crossorigin="anonymous"></script>
```
#### React with Add-Ons {{site.react_version}} (development)
The uncompressed, development version of React with [optional add-ons](/react/docs/addons.html).
```html
<script src="https://fb.me/react-with-addons-{{site.react_version}}.js"></script>
<script src="https://fb.me/react-dom-{{site.react_version}}.js"></script>
<script src="https://fb.me/react-with-addons-{{site.react_version}}.js"
integrity="sha384-{{site.react_hashes.addons_dev}}"
crossorigin="anonymous"></script>
<script src="https://fb.me/react-dom-{{site.react_version}}.js"
integrity="sha384-{{site.react_hashes.dom_dev}}"
crossorigin="anonymous"></script>
```
#### React with Add-Ons {{site.react_version}} (production)
The compressed, production version of React with [optional add-ons](/react/docs/addons.html).
```html
<script src="https://fb.me/react-with-addons-{{site.react_version}}.min.js"></script>
<script src="https://fb.me/react-dom-{{site.react_version}}.min.js"></script>
<script src="https://fb.me/react-with-addons-{{site.react_version}}.min.js"
integrity="sha384-{{site.react_hashes.addons_prod}}"
crossorigin="anonymous"></script>
<script src="https://fb.me/react-dom-{{site.react_version}}.min.js"
integrity="sha384-{{site.react_hashes.dom_prod}}"
crossorigin="anonymous"></script>
```
All scripts are also available via [CDNJS](https://cdnjs.com/libraries/react/).

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2015, Facebook, Inc.
* Copyright 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2015, Facebook, Inc.
* Copyright 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
@@ -17,7 +17,7 @@
*/
module.exports = function(context) {
// we also allow literal strings and concatinated literal strings
// we also allow literal strings and concatenated literal strings
function getLiteralString(node) {
if (node.type === 'Literal' && typeof node.value === 'string') {
return node.value;
@@ -67,7 +67,7 @@ module.exports = function(context) {
);
return;
}
// count the number of formating substitutions, plus the first two args
// count the number of formatting substitutions, plus the first two args
var expectedNArgs = (format.match(/%s/g) || []).length + 2;
if (node.arguments.length !== expectedNArgs) {
context.report(

View File

@@ -11,9 +11,10 @@
<p>
If you can see this, React is not running. Try running:
</p>
<pre>npm install -g babel
<pre>npm install -g babel-cli
cd examples/basic-jsx-precompile/
babel example.js --out-dir=build</pre>
npm install babel-preset-react
babel example.js --presets react --out-dir=build</pre>
</div>
<h4>Example Details</h4>
<p>This is written with JSX in a separate file and precompiled to vanilla JS by running:</p>
@@ -25,8 +26,8 @@ babel example.js --out-dir=build</pre>
<p><i>With Babel 6.0 or higher</i></p>
<pre>npm install -g babel-cli
npm install babel-preset-react
cd examples/basic-jsx-precompile/
npm install babel-preset-react
babel example.js --presets react --out-dir=build</pre>
<p>
Learn more about React at

View File

@@ -19,9 +19,13 @@ var BootstrapModal = React.createClass({
componentDidMount: function() {
// When the component is added, turn it into a modal
$(this.refs.root).modal({backdrop: 'static', keyboard: false, show: false});
// Bootstrap's modal class exposes a few events for hooking into modal
// functionality. Lets hook into one of them:
$(this.refs.root).on('hidden.bs.modal', this.handleHidden);
},
componentWillUnmount: function() {
$(this.refs.root).off('hidden', this.handleHidden);
$(this.refs.root).off('hidden.bs.modal', this.handleHidden);
},
close: function() {
$(this.refs.root).modal('hide');
@@ -84,6 +88,11 @@ var BootstrapModal = React.createClass({
if (this.props.onConfirm) {
this.props.onConfirm();
}
},
handleHidden: function() {
if (this.props.onHidden) {
this.props.onHidden();
}
}
});
@@ -102,6 +111,7 @@ var Example = React.createClass({
cancel="Cancel"
onCancel={this.handleCancel}
onConfirm={this.closeModal}
onHidden={this.handleModalDidClose}
title="Hello, Bootstrap!">
This is a React component powered by jQuery and Bootstrap!
</BootstrapModal>
@@ -120,6 +130,9 @@ var Example = React.createClass({
},
closeModal: function() {
this.refs.modal.close();
},
handleModalDidClose: function() {
alert("The modal has been dismissed!");
}
});

View File

@@ -1,7 +1,7 @@
/**
* <%= package %> v<%= version %>
*
* Copyright 2013-2015, Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the

View File

@@ -16,18 +16,15 @@ module.exports = function() {
config.globalTransforms = config.globalTransforms || [];
config.plugins = config.plugins || [];
config.after = config.after || [];
config.paths = config.paths || [];
// create the bundle we'll work with
var entries = grunt.file.expand(config.entries);
var paths = grunt.file.expand(config.paths);
// Extract other options
var options = {
entries: entries,
debug: config.debug, // sourcemaps
standalone: config.standalone, // global
paths: paths,
};
var bundle = browserify(options);

View File

@@ -2,10 +2,12 @@
var grunt = require('grunt');
var extension = process.platform === 'win32' ? '.cmd': '';
module.exports = function() {
var done = this.async();
grunt.util.spawn({
cmd: 'node_modules/.bin/eslint',
cmd: 'node_modules/.bin/eslint' + extension,
args: ['.'],
opts: {stdio: 'inherit'}, // allows colors to passthrough
}, function(err, result, code) {

View File

@@ -6,20 +6,88 @@
'use strict';
var async = require('async');
var fs = require('fs');
var glob = require('glob');
var grunt = require('grunt');
var path = require('path');
module.exports = function() {
var done = this.async();
var rootPath = path.resolve('.');
var buildPath = path.join(rootPath, 'build');
var tempConfigPath = path.join(buildPath, 'jest-config.json');
var config = require(path.join(rootPath, 'package.json')).jest;
var collectCoverageOnlyFrom = {
'src/**/*.js': {
ignore: [
'src/**/__tests__/*.js',
'src/shared/vendor/third_party/*.js',
'src/test/*.js',
],
},
};
function getCollectCoverageOnlyFrom(callback) {
var patterns = Object.keys(collectCoverageOnlyFrom);
var result = {};
async.each(patterns, function(pattern) {
var options = Object.assign({ nodir: true }, collectCoverageOnlyFrom[pattern]);
glob(pattern, options, function(err, files) {
(files || []).reduce(function(object, key) {
object[key] = true;
return object;
}, result);
callback(err);
});
}, function(err) {
callback(err, result);
});
}
function getJestConfig(callback) {
var rootDir = path.resolve(buildPath, path.resolve(config.rootDir));
getCollectCoverageOnlyFrom(function(err, data) {
callback(err, Object.assign({}, config, {
rootDir: rootDir,
collectCoverage: true,
collectCoverageOnlyFrom: data,
}));
});
}
function onError(err) {
grunt.log.error('jest failed');
grunt.log.error(err);
}
function writeTempConfig(callback) {
getJestConfig(function(err, data) {
if (err) {
callback(err);
} else {
grunt.file.mkdir(buildPath);
fs.writeFile(tempConfigPath, JSON.stringify(data, null, ' '), 'utf8', callback);
}
});
}
function run(done, configPath) {
grunt.log.writeln('running jest (this may take a while)');
var args = ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest')];
if (configPath) {
args.push('--config', configPath);
}
grunt.util.spawn({
cmd: 'node',
args: ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest')],
opts: {stdio: 'inherit', env: {NODE_ENV: 'test'}},
}, function(err, result, code) {
if (err) {
grunt.log.error('jest failed');
grunt.log.error(err);
args: args,
opts: { stdio: 'inherit', env: { NODE_ENV: 'test' } },
}, function(spawnErr, result, code) {
if (spawnErr) {
onError(spawnErr);
} else {
grunt.log.ok('jest passed');
}
@@ -27,4 +95,27 @@ module.exports = function() {
done(code === 0);
});
}
function runJestNormally() {
var done = this.async();
run(done);
}
function runJestWithCoverage() {
var done = this.async();
writeTempConfig(function(writeErr) {
if (writeErr) {
onError(writeErr);
return;
}
run(done, tempConfigPath);
});
}
module.exports = {
normal: runJestNormally,
coverage: runJestWithCoverage,
};

View File

@@ -26,7 +26,7 @@ module.exports = function() {
});
args.push.apply(args, rootIDs);
args.push('--config' /* from stdin */);
args.push('--config');
var child = spawn({
cmd: 'node',

View File

@@ -1,6 +1,5 @@
'use strict';
var assign = require('object-assign');
var fs = require('fs');
var grunt = require('grunt');
var path = require('path');
@@ -36,11 +35,6 @@ var addons = {
name: 'transition-group',
docs: 'animation',
},
cloneWithProps: {
module: 'cloneWithProps',
name: 'clone-with-props',
docs: 'clone-with-props',
},
createFragment: {
module: 'ReactFragment',
method: 'create',
@@ -81,7 +75,7 @@ function buildReleases() {
var destLicense = path.join(destDir, 'LICENSE');
var destPatents = path.join(destDir, 'PATENTS');
var pkgData = assign({}, pkgTemplate);
var pkgData = Object.assign({}, pkgTemplate);
pkgData.name = pkgName;
grunt.file.mkdir(destDir);

View File

@@ -14,8 +14,6 @@ var BOWER_FILES = [
'react-dom-server.js',
'react-dom-server.min.js',
];
var GH_PAGES_PATH = '../react-gh-pages/';
var GH_PAGES_GLOB = [GH_PAGES_PATH + '*'];
var EXAMPLES_PATH = 'examples/';
var EXAMPLES_GLOB = [EXAMPLES_PATH + '**/*.*'];
@@ -77,12 +75,6 @@ function setup() {
return false;
}
if (!grunt.file.exists(GH_PAGES_PATH)) {
grunt.log.error('Make sure you have the react gh-pages branch checked ' +
'out at ../react-gh-pages.');
return false;
}
VERSION = grunt.config.data.pkg.version;
VERSION_STRING = 'v' + VERSION;
}
@@ -106,28 +98,9 @@ function bower() {
}
function docs() {
var done = this.async();
grunt.file.copy('build/react-' + VERSION + '.zip', 'docs/downloads/react-' + VERSION + '.zip');
grunt.file.copy('build/react.js', 'docs/js/react.js');
grunt.file.copy('build/react-dom.js', 'docs/js/react-dom.js');
var files = grunt.file.expand(GH_PAGES_GLOB);
files.forEach(function(file) {
grunt.file.delete(file, {force: true});
});
// Build the docs with `rake release`, which will compile the CSS & JS, then
// build jekyll into GH_PAGES_PATH
var rakeOpts = {
cmd: 'rake',
args: ['release'],
opts: {cwd: 'docs'},
};
grunt.util.spawn(rakeOpts, function() {
// Commit the repo. We don't really care about tagging this.
_gitCommitAndTag(GH_PAGES_PATH, VERSION_STRING, null, done);
});
}
function msg() {
@@ -136,8 +109,10 @@ function msg() {
var steps = [
'Still todo:',
'* put files on CDN',
'* add starter pack (git add -f docs/downloads/react-version.zip)',
'* push changes to git repositories',
'* publish npm module (`npm publish .`)',
'* update docs branch variable in Travis CI',
'* publish npm modules',
'* announce it on FB/Twitter/mailing list',
];
steps.forEach(function(ln) {

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
@@ -14,8 +14,7 @@ var babel = require('gulp-babel');
var flatten = require('gulp-flatten');
var del = require('del');
var babelPluginDEV = require('fbjs-scripts/babel/dev-expression');
var babelPluginModules = require('fbjs-scripts/babel/rewrite-modules');
var babelPluginModules = require('fbjs-scripts/babel-6/rewrite-modules');
var paths = {
react: {
@@ -23,26 +22,20 @@ var paths = {
'src/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
'!src/shared/vendor/**/*.js',
],
lib: 'build/modules',
},
};
var babelOpts = {
nonStandard: true,
blacklist: [
'spec.functionName',
plugins: [
[babelPluginModules, { map: require('fbjs/module-map') }],
],
optional: [
'es7.trailingFunctionCommas',
],
plugins: [babelPluginDEV, babelPluginModules],
ignore: ['third_party'],
_moduleMap: require('fbjs/module-map'),
};
gulp.task('react:clean', function(cb) {
del([paths.react.lib], cb);
gulp.task('react:clean', function() {
return del([paths.react.lib]);
});
gulp.task('react:modules', function() {

View File

@@ -1,23 +1,22 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ClientReactRootIndex
* @typechecks
* @providesModule ReactElementTestChild
*/
'use strict';
var nextReactRootIndex = 0;
var React = require('React');
var ClientReactRootIndex = {
createReactRootIndex: function() {
return nextReactRootIndex++;
var Child = React.createClass({
render: function() {
return React.createElement('div');
},
};
});
module.exports = ClientReactRootIndex;
module.exports = Child;

View File

@@ -0,0 +1,35 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactMockedComponentTestComponent
*/
'use strict';
var React = require('React');
var ReactMockedComponentTestComponent = React.createClass({
getDefaultProps: function() {
return {bar: 'baz'};
},
getInitialState: function() {
return {foo: 'bar'};
},
hasCustomMethod: function() {
return true;
},
render: function() {
return <span />;
},
});
module.exports = ReactMockedComponentTestComponent;

9278
npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,47 +1,65 @@
{
"name": "react-build",
"private": true,
"version": "0.14.8",
"version": "15.0.0-rc.1",
"devDependencies": {
"babel": "^5.8.3",
"babel-eslint": "^4.1.3",
"benchmark": "^1.0.0",
"browserify": "^9.0.3",
"async": "^1.5.0",
"babel-cli": "^6.6.5",
"babel-core": "^6.0.0",
"babel-eslint": "^5.0.0",
"babel-plugin-check-es2015-constants": "^6.5.0",
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
"babel-plugin-transform-es2015-block-scoped-functions": "^6.5.0",
"babel-plugin-transform-es2015-block-scoping": "^6.5.0",
"babel-plugin-transform-es2015-classes": "^6.5.2",
"babel-plugin-transform-es2015-computed-properties": "^6.5.2",
"babel-plugin-transform-es2015-destructuring": "^6.5.0",
"babel-plugin-transform-es2015-for-of": "^6.5.2",
"babel-plugin-transform-es2015-literals": "^6.5.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.2",
"babel-plugin-transform-es2015-object-super": "^6.5.0",
"babel-plugin-transform-es2015-parameters": "^6.5.0",
"babel-plugin-transform-es2015-shorthand-properties": "^6.5.0",
"babel-plugin-transform-es2015-spread": "^6.5.2",
"babel-plugin-transform-es2015-template-literals": "^6.5.2",
"babel-plugin-transform-es3-member-expression-literals": "^6.5.0",
"babel-plugin-transform-es3-property-literals": "^6.5.0",
"babel-preset-react": "^6.5.0",
"browserify": "^12.0.1",
"bundle-collapser": "^1.1.1",
"coffee-script": "^1.8.0",
"del": "^1.2.0",
"derequire": "^2.0.0",
"coveralls": "^2.11.6",
"del": "^2.0.2",
"derequire": "^2.0.3",
"envify": "^3.0.0",
"eslint": "^1.5.1",
"eslint-plugin-react": "^3.4.2",
"eslint": "1.10.3",
"eslint-plugin-react": "4.1.0",
"eslint-plugin-react-internal": "file:eslint-rules",
"fbjs": "^0.6.1",
"fbjs-scripts": "^0.2.0",
"fbjs": "^0.8.0-alpha.2",
"fbjs-scripts": "^0.6.0-alpha.3",
"glob": "^6.0.1",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-compare-size": "^0.4.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-compress": "^0.13.0",
"grunt-contrib-compress": "^0.14.0",
"gulp": "^3.9.0",
"gulp-babel": "^5.1.0",
"gulp-flatten": "^0.1.0",
"gulp-util": "^3.0.5",
"gulp-babel": "^6.0.0",
"gulp-flatten": "^0.2.0",
"gzip-js": "~0.3.2",
"jest-cli": "^0.5.7",
"jstransform": "^11.0.0",
"object-assign": "^3.0.0",
"optimist": "^0.6.1",
"jest-cli": "^0.9.0",
"platform": "^1.1.0",
"run-sequence": "^1.1.0",
"run-sequence": "^1.1.4",
"through2": "^2.0.0",
"tmp": "~0.0.18",
"tmp": "~0.0.28",
"typescript": "~1.4.0",
"uglify-js": "^2.4.23",
"uglify-js": "^2.5.0",
"uglifyify": "^3.0.1"
},
"devEngines": {
"node": "4.x",
"npm": "2.x"
"node": "4.x || 5.x",
"npm": "2.x || 3.x"
},
"commonerConfig": {
"version": 7
@@ -63,6 +81,7 @@
"scriptPreprocessor": "scripts/jest/preprocessor.js",
"setupEnvScriptFile": "scripts/jest/environment.js",
"setupTestFrameworkScriptFile": "scripts/jest/test-framework-setup.js",
"testRunner": "jasmine1",
"testFileExtensions": [
"coffee",
"js",
@@ -70,6 +89,7 @@
],
"testPathDirs": [
"<rootDir>/eslint-rules",
"<rootDir>/mocks",
"<rootDir>/src",
"node_modules/fbjs"
],

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the

View File

@@ -1,6 +1,6 @@
{
"name": "react-addons-template",
"version": "0.14.8",
"version": "15.0.0-rc.1",
"main": "index.js",
"repository": "facebook/react",
"keywords": [
@@ -10,6 +10,6 @@
"license": "BSD-3-Clause",
"dependencies": {},
"peerDependencies": {
"react": "^0.14.8"
"react": "^15.0.0-rc.1"
}
}

View File

@@ -1,111 +0,0 @@
## react-codemod
This repository contains a collection of codemod scripts based for use with
[JSCodeshift](https://github.com/facebook/jscodeshift) that help update React
APIs.
### Setup & Run
* `npm install -g jscodeshift`
* `git clone https://github.com/facebook/react.git` or download a zip file
from `https://github.com/facebook/react/archive/master.zip`
* `jscodeshift -t <codemod-script> <file>`
* Use the `-d` option for a dry-run and use `-p` to print the output
for comparison
### Included Scripts
`findDOMNode` updates `this.getDOMNode()` or `this.refs.foo.getDOMNode()`
calls inside of `React.createClass` components to `React.findDOMNode(foo)`. Note
that it will only look at code inside of `React.createClass` calls and only
update calls on the component instance or its refs. You can use this script to
update most calls to `getDOMNode` and then manually go through the remaining
calls.
* `jscodeshift -t react/packages/react-codemod/transforms/findDOMNode.js <file>`
`react-to-react-dom` updates code for the split of the `react` and `react-dom`
packages (e.g., `React.render` to `ReactDOM.render`). It looks for
`require('react')` and replaces the appropriate property accesses using
`require('react-dom')`. It does not support ES6 modules or other non-CommonJS
systems. We recommend performing the `findDOMNode` conversion first.
* `jscodeshift -t react/packages/react-codemod/transforms/react-to-react-dom.js <file>`
* After running the automated codemod, you may want to run a regex-based find-and-replace to remove extra whitespace between the added requires, such as `codemod.py -m -d src --extensions js '(var React\s*=\s*require\(.react.\);)\n\n(\s*var ReactDOM)' '\1\n\2'` using https://github.com/facebook/codemod.
`pure-render-mixin` removes `PureRenderMixin` and inlines
`shouldComponentUpdate` so that the ES2015 class transform can pick up the React
component and turn it into an ES2015 class. NOTE: This currently only works if you
are using the master version (>0.13.1) of React as it is using
`React.addons.shallowCompare`
* `jscodeshift -t react/packages/react-codemod/transforms/pure-render-mixin.js <file>`
* If `--mixin-name=<name>` is specified it will look for the specified name
instead of `PureRenderMixin`. Note that it is not possible to use a
namespaced name for the mixin. `mixins: [React.addons.PureRenderMixin]` will
not currently work.
`class` transforms `React.createClass` calls into ES2015 classes.
* `jscodeshift -t react/packages/react-codemod/transforms/class.js <file>`
* If `--no-super-class` is specified it will not extend
`React.Component` if `setState` and `forceUpdate` aren't being called in a
class. We do recommend always extending from `React.Component`, especially
if you are using or planning to use [Flow](http://flowtype.org/). Also make
sure you are not calling `setState` anywhere outside of your component.
These three scripts take an option `--no-explicit-require` if you don't have a
`require('React')` statement in your code files and if you access React as a
global.
### Explanation of the ES2015 class transform
* Ignore components with calls to deprecated APIs. This is very defensive, if
the script finds any identifiers called `isMounted`, `getDOMNode`,
`replaceProps`, `replaceState` or `setProps` it will skip the component.
* Replaces `var A = React.createClass(spec)` with
`class A (extends React.Component) {spec}`.
* Pulls out all statics defined on `statics` plus the few special cased
statics like `propTypes`, `childContextTypes`, `contextTypes` and
`displayName` and assigns them after the class is created.
`class A {}; A.foo = bar;`
* Takes `getDefaultProps` and inlines it as a static `defaultProps`.
If `getDefaultProps` is defined as a function with a single statement that
returns an object, it optimizes and transforms
`getDefaultProps() { return {foo: 'bar'}; }` into
`A.defaultProps = {foo: 'bar'};`. If `getDefaultProps` contains more than
one statement it will transform into a self-invoking function like this:
`A.defaultProps = function() {…}();`. Note that this means that the function
will be executed only a single time per app-lifetime. In practice this
hasn't caused any issues `getDefaultProps` should not contain any
side-effects.
* Binds class methods to the instance if methods are referenced without being
called directly. It checks for `this.foo` but also traces variable
assignments like `var self = this; self.foo`. It does not bind functions
from the React API and ignores functions that are being called directly
(unless it is both called directly and passed around to somewhere else)
* Creates a constructor if necessary. This is necessary if either
`getInitialState` exists in the `React.createClass` spec OR if functions
need to be bound to the instance.
* When `--no-super-class` is passed it only optionally extends
`React.Component` when `setState` or `forceUpdate` are used within the
class.
The constructor logic is as follows:
* Call `super(props, context)` if the base class needs to be extended.
* Bind all functions that are passed around,
like `this.foo = this.foo.bind(this)`
* Inline `getInitialState` (and remove `getInitialState` from the spec). It
also updates access of `this.props.foo` to `props.foo` and adds `props` as
argument to the constructor. This is necessary in the case when the base
class does not need to be extended where `this.props` will only be set by
React after the constructor has been run.
* Changes `return StateObject` from `getInitialState` to assign `this.state`
directly.
### Recast Options
Options to [recast](https://github.com/benjamn/recast)'s printer can be provided
through the `printOptions` command line argument
* `jscodeshift -t transform.js <file> --printOptions='{"quote":"double"}'`

View File

@@ -1,26 +0,0 @@
{
"name": "react-codemod",
"version": "3.0.0",
"description": "React codemod scripts",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "https://github.com/facebook/react"
},
"scripts": {
"test": "jest"
},
"dependencies": {
"jscodeshift": "^0.3.7"
},
"devDependencies": {
"babel-jest": "^5.3.0",
"jest-cli": "^0.5.1"
},
"jest": {
"scriptPreprocessor": "./node_modules/babel-jest",
"testPathDirs": [
"test"
]
}
}

View File

@@ -1,68 +0,0 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
"use strict";
jest.autoMockOff();
var fs = require('fs');
var jscodeshift = require('jscodeshift');
function read(fileName) {
return fs.readFileSync(__dirname + '/../' + fileName, 'utf8');
}
function test(transformName, testFileName, options) {
var path = testFileName + '.js';
var source = read(testFileName + '.js');
var output = read(testFileName + '.output.js');
var transform = require('../../transforms/' + transformName);
expect(
(transform({path, source}, {jscodeshift}, options || {}) || '').trim()
).toEqual(
output.trim()
);
}
describe('Transform Tests', () => {
it('transforms the "findDOMNode" tests correctly', () => {
test('findDOMNode', 'findDOMNode-test');
});
it('transforms the "pure-render-mixin" tests correctly', () => {
test('pure-render-mixin', 'pure-render-mixin-test');
test('pure-render-mixin', 'pure-render-mixin-test2');
test('pure-render-mixin', 'pure-render-mixin-test3');
test('pure-render-mixin', 'pure-render-mixin-test4', {
'mixin-name': 'ReactComponentWithPureRenderMixin',
});
});
it('transforms the "class" tests correctly', () => {
test('class', 'class-test');
test('class', 'class-test2', {
'super-class': false
});
test('class', 'class-test3');
});
it('transforms exports class', () => {
test('class', 'export-default-class-test');
});
});

View File

@@ -1,133 +0,0 @@
'use strict';
var React = require('React');
var Relay = require('Relay');
var Image = require('Image.react');
/*
* Multiline
*/
var MyComponent = React.createClass({
getInitialState: function() {
var x = this.props.foo;
return {
heyoo: 23,
};
},
foo: function() {
this.setState({heyoo: 24});
}
});
// Class comment
var MyComponent2 = React.createClass({
getDefaultProps: function() {
return {a: 1};
},
foo: function() {
pass(this.foo);
this.forceUpdate();
}
});
var MyComponent3 = React.createClass({
statics: {
someThing: 10,
foo: function() {},
},
propTypes: {
highlightEntities: React.PropTypes.bool,
linkifyEntities: React.PropTypes.bool,
text: React.PropTypes.shape({
text: React.PropTypes.string,
ranges: React.PropTypes.array
}).isRequired
},
getDefaultProps: function() {
foo();
return {
linkifyEntities: true,
highlightEntities: false
};
},
getInitialState: function() {
this.props.foo();
return {
heyoo: 23,
};
},
_renderText: function(text) {
return <Text text={text} />;
},
_renderImageRange: function(text, range) {
var image = range.image;
if (image) {
return (
<Image
src={image.uri}
height={image.height / image.scale}
width={image.width / image.scale}
/>
);
}
},
autobindMe: function() {},
dontAutobindMe: function() {},
// Function comment
_renderRange: function(text, range) {
var self = this;
self.dontAutobindMe();
call(self.autobindMe);
var type = rage.type;
var {highlightEntities} = this.props;
if (type === 'ImageAtRange') {
return this._renderImageRange(text, range);
}
if (this.props.linkifyEntities) {
text =
<Link href={usersURI}>
{text}
</Link>;
} else {
text = <span>{text}</span>;
}
return text;
},
/* This is a comment */
render: function() {
var content = this.props.text;
return (
<BaseText
{...this.props}
textRenderer={this._renderText}
rangeRenderer={this._renderRange}
text={content.text}
/>
);
}
});
var MyComponent4 = React.createClass({
foo: callMeMaybe(),
render: function() {},
});
module.exports = Relay.createContainer(MyComponent, {
queries: {
me: Relay.graphql`this is not graphql`,
}
});

View File

@@ -1,144 +0,0 @@
'use strict';
var React = require('React');
var Relay = require('Relay');
var Image = require('Image.react');
/*
* Multiline
*/
class MyComponent extends React.Component {
constructor(props, context) {
super(props, context);
var x = props.foo;
this.state = {
heyoo: 23,
};
}
foo() {
this.setState({heyoo: 24});
}
}
// Class comment
class MyComponent2 extends React.Component {
constructor(props, context) {
super(props, context);
this.foo = this.foo.bind(this);
}
foo() {
pass(this.foo);
this.forceUpdate();
}
}
MyComponent2.defaultProps = {a: 1};
class MyComponent3 extends React.Component {
constructor(props, context) {
super(props, context);
this._renderRange = this._renderRange.bind(this);
this._renderText = this._renderText.bind(this);
this.autobindMe = this.autobindMe.bind(this);
props.foo();
this.state = {
heyoo: 23,
};
}
_renderText(text) {
return <Text text={text} />;
}
_renderImageRange(text, range) {
var image = range.image;
if (image) {
return (
<Image
src={image.uri}
height={image.height / image.scale}
width={image.width / image.scale}
/>
);
}
}
autobindMe() {}
dontAutobindMe() {}
// Function comment
_renderRange(text, range) {
var self = this;
self.dontAutobindMe();
call(self.autobindMe);
var type = rage.type;
var {highlightEntities} = this.props;
if (type === 'ImageAtRange') {
return this._renderImageRange(text, range);
}
if (this.props.linkifyEntities) {
text =
<Link href={usersURI}>
{text}
</Link>;
} else {
text = <span>{text}</span>;
}
return text;
}
/* This is a comment */
render() {
var content = this.props.text;
return (
<BaseText
{...this.props}
textRenderer={this._renderText}
rangeRenderer={this._renderRange}
text={content.text}
/>
);
}
}
MyComponent3.defaultProps = function() {
foo();
return {
linkifyEntities: true,
highlightEntities: false
};
}();
MyComponent3.foo = function() {};
MyComponent3.propTypes = {
highlightEntities: React.PropTypes.bool,
linkifyEntities: React.PropTypes.bool,
text: React.PropTypes.shape({
text: React.PropTypes.string,
ranges: React.PropTypes.array
}).isRequired
};
MyComponent3.someThing = 10;
var MyComponent4 = React.createClass({
foo: callMeMaybe(),
render: function() {},
});
module.exports = Relay.createContainer(MyComponent, {
queries: {
me: Relay.graphql`this is not graphql`,
}
});

View File

@@ -1,33 +0,0 @@
'use strict';
var React = require('React');
var IdontNeedAParent = React.createClass({
render: function() {
return <div />;
}
});
var ButIDo = React.createClass({
foo: function() {
this.setState({banana: '?'});
},
render: function() {
return <div />;
}
});
var IAccessProps = React.createClass({
getInitialState: function() {
return {
relayReleaseDate: this.props.soon,
};
},
render: function() {
return
}
});

View File

@@ -1,31 +0,0 @@
'use strict';
var React = require('React');
class IdontNeedAParent {
render() {
return <div />;
}
}
class ButIDo extends React.Component {
foo() {
this.setState({banana: '?'});
}
render() {
return <div />;
}
}
class IAccessProps {
constructor(props) {
this.state = {
relayReleaseDate: props.soon,
};
}
render() {
return
}
}

View File

@@ -1,20 +0,0 @@
'use strict';
var React = require('React');
// Comment
module.exports = React.createClass({
propTypes: {
foo: React.PropTypes.bool,
},
getInitialState: function() {
return {
foo: 'bar',
};
},
render: function() {
return <div />;
}
});

View File

@@ -1,22 +0,0 @@
'use strict';
var React = require('React');
// Comment
module.exports = class extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
foo: 'bar',
};
}
render() {
return <div />;
}
};
module.exports.propTypes = {
foo: React.PropTypes.bool,
};

View File

@@ -1,19 +0,0 @@
'use strict';
import React from 'React';
export default React.createClass({
getInitialState: function() {
return {
foo: 'bar',
};
},
propTypes: {
foo: React.PropTypes.string,
},
render: function() {
return <div />;
}
});

View File

@@ -1,21 +0,0 @@
'use strict';
import React from 'React';
export default class extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
foo: 'bar',
};
}
static propTypes = {
foo: React.PropTypes.string,
};
render() {
return <div />;
}
}

View File

@@ -1,34 +0,0 @@
'use strict';
var React = require('React');
var Composer = React.createClass({
componentWillReceiveProps: function(nextProps) {
this.getDOMNode();
return foo(this.refs.input.getDOMNode());
},
foo: function() {
var ref = 'foo';
var element = this.refs[ref];
var domNode = element.getDOMNode();
},
bar: function() {
var thing = this.refs.foo;
thing.getDOMNode();
},
foobar: function() {
passThisOn(this.refs.main.refs.list.getDOMNode());
}
});
var SomeDialog = React.createClass({
render: function() {
call(this.refs.SomeThing);
return (
<div />
);
}
});

View File

@@ -1,34 +0,0 @@
'use strict';
var React = require('React');
var Composer = React.createClass({
componentWillReceiveProps: function(nextProps) {
React.findDOMNode(this);
return foo(React.findDOMNode(this.refs.input));
},
foo: function() {
var ref = 'foo';
var element = this.refs[ref];
var domNode = React.findDOMNode(element);
},
bar: function() {
var thing = this.refs.foo;
React.findDOMNode(thing);
},
foobar: function() {
passThisOn(React.findDOMNode(this.refs.main.refs.list));
}
});
var SomeDialog = React.createClass({
render: function() {
call(this.refs.SomeThing);
return (
<div />
);
}
});

View File

@@ -1,45 +0,0 @@
var React = require('react/addons');
var PureRenderMixin = React.addons.PureRenderMixin;
var MyComponent = React.createClass({
mixins: [PureRenderMixin],
render: function() {
return <div />;
}
});
var MyMixedComponent = React.createClass({
mixins: [PureRenderMixin, SomeOtherMixin],
render: function() {
return <div />;
}
});
var MyFooComponent = React.createClass({
mixins: [PureRenderMixin, SomeOtherMixin],
render: function() {
return <div />;
},
foo: function() {
}
});
var MyStupidComponent = React.createClass({
mixins: [PureRenderMixin],
shouldComponentUpdate: function() {
return !!'wtf is this doing here?';
},
render: function() {
return <div />;
}
});
module.exports = MyComponent;

View File

@@ -1,55 +0,0 @@
var React = require('react/addons');
var PureRenderMixin = React.addons.PureRenderMixin;
var MyComponent = React.createClass({
shouldComponentUpdate: function(nextProps, nextState) {
return React.addons.shallowCompare(this, nextProps, nextState);
},
render: function() {
return <div />;
}
});
var MyMixedComponent = React.createClass({
mixins: [SomeOtherMixin],
shouldComponentUpdate: function(nextProps, nextState) {
return React.addons.shallowCompare(this, nextProps, nextState);
},
render: function() {
return <div />;
}
});
var MyFooComponent = React.createClass({
mixins: [SomeOtherMixin],
render: function() {
return <div />;
},
foo: function() {
},
shouldComponentUpdate: function(nextProps, nextState) {
return React.addons.shallowCompare(this, nextProps, nextState);
}
});
var MyStupidComponent = React.createClass({
mixins: [PureRenderMixin],
shouldComponentUpdate: function() {
return !!'wtf is this doing here?';
},
render: function() {
return <div />;
}
});
module.exports = MyComponent;

View File

@@ -1,13 +0,0 @@
var React = require('react/addons');
var PureRenderMixin = React.addons.PureRenderMixin;
var MyComponent = React.createClass({
mixins: [PureRenderMixin],
render: function() {
return <div />;
}
});
module.exports = MyComponent;

View File

@@ -1,13 +0,0 @@
var React = require('react/addons');
var MyComponent = React.createClass({
shouldComponentUpdate: function(nextProps, nextState) {
return React.addons.shallowCompare(this, nextProps, nextState);
},
render: function() {
return <div />;
}
});
module.exports = MyComponent;

View File

@@ -1,14 +0,0 @@
var React = require('react/addons');
var Foo = 'Foo';
var PureRenderMixin = React.addons.PureRenderMixin;
var MyComponent = React.createClass({
mixins: [PureRenderMixin],
render: function() {
return <div />;
}
});
module.exports = MyComponent;

View File

@@ -1,15 +0,0 @@
var React = require('react/addons');
var Foo = 'Foo';
var MyComponent = React.createClass({
shouldComponentUpdate: function(nextProps, nextState) {
return React.addons.shallowCompare(this, nextProps, nextState);
},
render: function() {
return <div />;
}
});
module.exports = MyComponent;

View File

@@ -1,12 +0,0 @@
var React = require('React');
var ReactComponentWithPureRenderMixin = require('ReactComponentWithPureRenderMixin');
var MyComponent = React.createClass({
mixins: [ReactComponentWithPureRenderMixin],
render: function() {
return <div />;
}
});
module.exports = MyComponent;

View File

@@ -1,13 +0,0 @@
var React = require('React');
var MyComponent = React.createClass({
shouldComponentUpdate: function(nextProps, nextState) {
return React.addons.shallowCompare(this, nextProps, nextState);
},
render: function() {
return <div />;
}
});
module.exports = MyComponent;

View File

@@ -1,555 +0,0 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
module.exports = (file, api, options) => {
const j = api.jscodeshift;
require('./utils/array-polyfills');
const ReactUtils = require('./utils/ReactUtils')(j);
const printOptions =
options.printOptions || {quote: 'single', trailingComma: true};
const root = j(file.source);
const AUTOBIND_IGNORE_KEYS = {
componentDidMount: true,
componentDidUpdate: true,
componentWillReceiveProps: true,
componentWillMount: true,
componentWillUpdate: true,
componentWillUnmount: true,
getDefaultProps: true,
getInitialState: true,
render: true,
shouldComponentUpdate: true,
};
const BASE_COMPONENT_METHODS = ['setState', 'forceUpdate'];
const DEFAULT_PROPS_FIELD = 'getDefaultProps';
const DEFAULT_PROPS_KEY = 'defaultProps';
const GET_INITIAL_STATE_FIELD = 'getInitialState';
const DEPRECATED_APIS = [
'getDOMNode',
'isMounted',
'replaceProps',
'replaceState',
'setProps',
];
const STATIC_KEY = 'statics';
const STATIC_KEYS = {
childContextTypes: true,
contextTypes: true,
displayName: true,
propTypes: true,
};
// ---------------------------------------------------------------------------
// Checks if the module uses mixins or accesses deprecated APIs.
const checkDeprecatedAPICalls = classPath =>
DEPRECATED_APIS.reduce(
(acc, name) =>
acc + j(classPath)
.find(j.Identifier, {name})
.size(),
0
) > 0;
const callsDeprecatedAPIs = classPath => {
if (checkDeprecatedAPICalls(classPath)) {
console.log(
file.path + ': `' + ReactUtils.getComponentName(classPath) + '` ' +
'was skipped because of deprecated API calls. Remove calls to ' +
DEPRECATED_APIS.join(', ') + ' in your React component and re-run ' +
'this script.'
);
return false;
}
return true;
};
const canConvertToClass = classPath => {
const specPath = ReactUtils.getReactCreateClassSpec(classPath);
const invalidProperties = specPath.properties.filter(prop => (
!prop.key.name || (
!STATIC_KEYS[prop.key.name] &&
STATIC_KEY != prop.key.name &&
!filterDefaultPropsField(prop) &&
!filterGetInitialStateField(prop) &&
!isFunctionExpression(prop)
)
));
if (invalidProperties.length) {
const invalidText = invalidProperties
.map(prop => prop.key.name ? prop.key.name : prop.key)
.join(', ');
console.log(
file.path + ': `' + ReactUtils.getComponentName(classPath) + '` ' +
'was skipped because of invalid field(s) `' + invalidText + '` on ' +
'the React component. Remove any right-hand-side expressions that ' +
'are not simple, like: `componentWillUpdate: createWillUpdate()` or ' +
'`render: foo ? renderA : renderB`.'
);
}
return !invalidProperties.length;
};
const hasMixins = classPath => {
if (ReactUtils.hasMixins(classPath)) {
console.log(
file.path + ': `' + ReactUtils.getComponentName(classPath) + '` ' +
'was skipped because of mixins.'
);
return false;
}
return true;
};
// ---------------------------------------------------------------------------
// Helpers
const createFindPropFn = prop => property => (
property.key &&
property.key.type === 'Identifier' &&
property.key.name === prop
);
const filterDefaultPropsField = node =>
createFindPropFn(DEFAULT_PROPS_FIELD)(node);
const filterGetInitialStateField = node =>
createFindPropFn(GET_INITIAL_STATE_FIELD)(node);
const findGetDefaultProps = specPath =>
specPath.properties.find(createFindPropFn(DEFAULT_PROPS_FIELD));
const findGetInitialState = specPath =>
specPath.properties.find(createFindPropFn(GET_INITIAL_STATE_FIELD));
// This is conservative; only check for `setState` and `forceUpdate` literals
// instead of also checking which objects they are called on.
const shouldExtendReactComponent = classPath =>
BASE_COMPONENT_METHODS.some(name => (
j(classPath)
.find(j.Identifier, {name})
.size() > 0
));
const withComments = (to, from) => {
to.comments = from.comments;
return to;
};
// ---------------------------------------------------------------------------
// Collectors
const isFunctionExpression = node => (
node.key &&
node.key.type === 'Identifier' &&
node.value &&
node.value.type === 'FunctionExpression'
);
const collectStatics = specPath => {
const statics = specPath.properties.find(createFindPropFn('statics'));
const staticsObject =
(statics && statics.value && statics.value.properties) || [];
const getDefaultProps = findGetDefaultProps(specPath);
if (getDefaultProps) {
staticsObject.push(createDefaultProps(getDefaultProps));
}
return (
staticsObject.concat(specPath.properties.filter(property =>
property.key && STATIC_KEYS[property.key.name]
))
.sort((a, b) => a.key.name < b.key.name)
);
};
const collectFunctions = specPath => specPath.properties
.filter(prop =>
!(filterDefaultPropsField(prop) || filterGetInitialStateField(prop))
)
.filter(isFunctionExpression);
const findAutobindNamesFor = (subtree, fnNames, literalOrIdentifier) => {
const node = literalOrIdentifier;
const autobindNames = {};
j(subtree)
.find(j.MemberExpression, {
object: node.name ? {
type: node.type,
name: node.name,
} : {type: node.type},
property: {
type: 'Identifier',
},
})
.filter(path => path.value.property && fnNames[path.value.property.name])
.filter(path => {
const call = path.parent.value;
return !(
call &&
call.type === 'CallExpression' &&
call.callee.type === 'MemberExpression' &&
call.callee.object.type === node.type &&
call.callee.object.name === node.name &&
call.callee.property.type === 'Identifier' &&
call.callee.property.name === path.value.property.name
);
})
.forEach(path => autobindNames[path.value.property.name] = true);
return Object.keys(autobindNames);
};
const collectAutoBindFunctions = (functions, classPath) => {
const fnNames = {};
functions
.filter(fn => !AUTOBIND_IGNORE_KEYS[fn.key.name])
.forEach(fn => fnNames[fn.key.name] = true);
const autobindNames = {};
const add = name => autobindNames[name] = true;
// Find `this.<foo>`
findAutobindNamesFor(classPath, fnNames, j.thisExpression()).forEach(add);
// Find `self.<foo>` if `self = this`
j(classPath)
.findVariableDeclarators()
.filter(path => (
path.value.id.type === 'Identifier' &&
path.value.init &&
path.value.init.type === 'ThisExpression'
))
.forEach(path =>
findAutobindNamesFor(
j(path).closest(j.FunctionExpression).get(),
fnNames,
path.value.id
).forEach(add)
);
return Object.keys(autobindNames).sort();
};
// ---------------------------------------------------------------------------
// Boom!
const createMethodDefinition = fn =>
withComments(j.methodDefinition(
'method',
fn.key,
fn.value
), fn);
const createBindAssignment = name =>
j.expressionStatement(
j.assignmentExpression(
'=',
j.memberExpression(
j.thisExpression(),
j.identifier(name),
false
),
j.callExpression(
j.memberExpression(
j.memberExpression(
j.thisExpression(),
j.identifier(name),
false
),
j.identifier('bind'),
false
),
[j.thisExpression()]
)
)
);
const createSuperCall = shouldAddSuperCall =>
!shouldAddSuperCall ?
[] :
[
j.expressionStatement(
j.callExpression(
j.identifier('super'),
[j.identifier('props'), j.identifier('context')]
)
),
];
const updatePropsAccess = getInitialState =>
getInitialState ?
j(getInitialState)
.find(j.MemberExpression, {
object: {
type: 'ThisExpression',
},
property: {
type: 'Identifier',
name: 'props',
},
})
.forEach(path => j(path).replaceWith(j.identifier('props')))
.size() > 0 :
false;
const inlineGetInitialState = getInitialState => {
if (!getInitialState) {
return [];
}
return getInitialState.value.body.body.map(statement => {
if (statement.type === 'ReturnStatement') {
return j.expressionStatement(
j.assignmentExpression(
'=',
j.memberExpression(
j.thisExpression(),
j.identifier('state'),
false
),
statement.argument
)
);
}
return statement;
});
};
const createConstructorArgs = (shouldAddSuperClass, hasPropsAccess) => {
if (shouldAddSuperClass) {
return [j.identifier('props'), j.identifier('context')];
} else if (hasPropsAccess) {
return [j.identifier('props')];
} else {
return [];
}
};
const createConstructor = (
getInitialState,
autobindFunctions,
shouldAddSuperClass
) => {
if (!getInitialState && !autobindFunctions.length) {
return [];
}
const hasPropsAccess = updatePropsAccess(getInitialState);
return [
createMethodDefinition({
key: j.identifier('constructor'),
value: j.functionExpression(
null,
createConstructorArgs(shouldAddSuperClass, hasPropsAccess),
j.blockStatement(
[].concat(
createSuperCall(shouldAddSuperClass),
autobindFunctions.map(createBindAssignment),
inlineGetInitialState(getInitialState)
)
)
),
}),
];
};
const createESClass = (
name,
properties,
getInitialState,
autobindFunctions,
comments,
shouldAddSuperClass
) =>
withComments(j.classDeclaration(
name ? j.identifier(name) : null,
j.classBody(
[].concat(
createConstructor(
getInitialState,
autobindFunctions,
shouldAddSuperClass
),
properties
)
),
shouldAddSuperClass ? j.memberExpression(
j.identifier('React'),
j.identifier('Component'),
false
) : null
), {comments});
const createStaticAssignment = (name, staticProperty) =>
withComments(j.expressionStatement(
j.assignmentExpression(
'=',
j.memberExpression(
name,
j.identifier(staticProperty.key.name),
false
),
staticProperty.value
)
), staticProperty);
const createStaticAssignmentExpressions = (name, statics) =>
statics.map(staticProperty => createStaticAssignment(name, staticProperty));
const createStaticClassProperty = staticProperty =>
withComments(j.classProperty(
j.identifier(staticProperty.key.name),
staticProperty.value,
null,
true
), staticProperty);
const createStaticClassProperties = statics =>
statics.map(createStaticClassProperty);
const hasSingleReturnStatement = value => (
value.type === 'FunctionExpression' &&
value.body &&
value.body.type === 'BlockStatement' &&
value.body.body &&
value.body.body.length === 1 &&
value.body.body[0].type === 'ReturnStatement' &&
value.body.body[0].argument &&
value.body.body[0].argument.type === 'ObjectExpression'
);
const createDefaultPropsValue = value => {
if (hasSingleReturnStatement(value)) {
return value.body.body[0].argument;
} else {
return j.callExpression(
value,
[]
);
}
};
const createDefaultProps = prop =>
withComments(
j.property(
'init',
j.identifier(DEFAULT_PROPS_KEY),
createDefaultPropsValue(prop.value)
),
prop
);
const getComments = classPath => {
if (classPath.value.comments) {
return classPath.value.comments;
}
const declaration = j(classPath).closest(j.VariableDeclaration);
if (declaration.size()) {
return declaration.get().value.comments;
}
return null;
};
const createModuleExportsMemberExpression = () =>
j.memberExpression(
j.identifier('module'),
j.identifier('exports'),
false
);
const updateToClass = (classPath, shouldExtend, type) => {
const specPath = ReactUtils.getReactCreateClassSpec(classPath);
const name = ReactUtils.getComponentName(classPath);
const statics = collectStatics(specPath);
const functions = collectFunctions(specPath);
const comments = getComments(classPath);
const autobindFunctions = collectAutoBindFunctions(functions, classPath);
const getInitialState = findGetInitialState(specPath);
const staticName =
name ? j.identifier(name) : createModuleExportsMemberExpression();
var path;
if (type == 'moduleExports' || type == 'exportDefault') {
path = ReactUtils.findReactCreateClassCallExpression(classPath);
} else {
path = j(classPath).closest(j.VariableDeclaration);
}
const properties =
(type == 'exportDefault') ? createStaticClassProperties(statics) : [];
path.replaceWith(
createESClass(
name,
properties.concat(functions.map(createMethodDefinition)),
getInitialState,
autobindFunctions,
comments,
shouldExtend || shouldExtendReactComponent(classPath)
)
);
if (type == 'moduleExports' || type == 'var') {
const staticAssignments = createStaticAssignmentExpressions(
staticName,
statics
);
if (type == 'moduleExports') {
root.get().value.program.body.push(...staticAssignments);
} else {
path.insertAfter(staticAssignments.reverse());
}
}
};
if (
!options['explicit-require'] || ReactUtils.hasReact(root)
) {
const apply = (path, type) =>
path
.filter(hasMixins)
.filter(callsDeprecatedAPIs)
.filter(canConvertToClass)
.forEach(classPath => updateToClass(
classPath,
!options['super-class'],
type
));
const didTransform = (
apply(ReactUtils.findReactCreateClass(root), 'var')
.size() +
apply(ReactUtils.findReactCreateClassModuleExports(root), 'moduleExports')
.size() +
apply(ReactUtils.findReactCreateClassExportDefault(root), 'exportDefault')
.size()
) > 0;
if (didTransform) {
return root.toSource(printOptions);
}
}
return null;
};

View File

@@ -1,144 +0,0 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
function getDOMNodeToFindDOMNode(file, api, options) {
const j = api.jscodeshift;
require('./utils/array-polyfills');
const ReactUtils = require('./utils/ReactUtils')(j);
const printOptions =
options.printOptions || {quote: 'single', trailingComma: true};
const root = j(file.source);
const createReactFindDOMNodeCall = arg => j.callExpression(
j.memberExpression(
j.identifier('React'),
j.identifier('findDOMNode'),
false
),
[arg]
);
const updateRefCall = (path, refName) => {
j(path)
.find(j.CallExpression, {
callee: {
object: {
type: 'Identifier',
name: refName,
},
property: {
type: 'Identifier',
name: 'getDOMNode',
},
},
})
.forEach(callPath => j(callPath).replaceWith(
createReactFindDOMNodeCall(j.identifier(refName))
));
};
const updateToFindDOMNode = classPath => {
var sum = 0;
// this.getDOMNode()
sum += j(classPath)
.find(j.CallExpression, {
callee: {
object: {
type: 'ThisExpression',
},
property: {
type: 'Identifier',
name: 'getDOMNode',
},
},
})
.forEach(path => j(path).replaceWith(
createReactFindDOMNodeCall(j.thisExpression())
))
.size();
// this.refs.xxx.getDOMNode() or this.refs.xxx.refs.yyy.getDOMNode()
sum += j(classPath)
.find(j.MemberExpression, {
object: {
type: 'MemberExpression',
object: {
type: 'MemberExpression',
object: {
type: 'ThisExpression',
},
property: {
type: 'Identifier',
name: 'refs',
},
},
},
})
.closest(j.CallExpression)
.filter(path => (
path.value.callee.property &&
path.value.callee.property.type === 'Identifier' &&
path.value.callee.property.name === 'getDOMNode'
))
.forEach(path => j(path).replaceWith(
createReactFindDOMNodeCall(path.value.callee.object)
))
.size();
// someVariable.getDOMNode() wherre `someVariable = this.refs.xxx`
sum += j(classPath)
.findVariableDeclarators()
.filter(path => {
const init = path.value.init;
const value = init && init.object;
return (
value &&
value.type === 'MemberExpression' &&
value.object &&
value.object.type === 'ThisExpression' &&
value.property &&
value.property.type === 'Identifier' &&
value.property.name === 'refs' &&
init.property &&
init.property.type === 'Identifier'
);
})
.forEach(path => j(path)
.closest(j.FunctionExpression)
.forEach(fnPath => updateRefCall(fnPath, path.value.id.name))
)
.size();
return sum > 0;
};
if (
!options['explicit-require'] ||
ReactUtils.hasReact(root)
) {
const didTransform = ReactUtils
.findReactCreateClass(root)
.filter(updateToFindDOMNode)
.size() > 0;
if (didTransform) {
return root.toSource(printOptions);
}
}
return null;
}
module.exports = getDOMNodeToFindDOMNode;

View File

@@ -1,188 +0,0 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
function removePureRenderMixin(file, api, options) {
const j = api.jscodeshift;
require('./utils/array-polyfills');
const ReactUtils = require('./utils/ReactUtils')(j);
const printOptions =
options.printOptions || {quote: 'single', trailingComma: true};
const root = j(file.source);
const PURE_RENDER_MIXIN = options['mixin-name'] || 'PureRenderMixin';
const SHOULD_COMPONENT_UPDATE = 'shouldComponentUpdate';
const NEXT_PROPS = 'nextProps';
const NEXT_STATE = 'nextState';
// ---------------------------------------------------------------------------
// shouldComponentUpdate
const createShouldComponentUpdateFunction = () =>
j.functionExpression(
null,
[j.identifier(NEXT_PROPS), j.identifier(NEXT_STATE)],
j.blockStatement([
j.returnStatement(
j.callExpression(
j.memberExpression(
j.identifier('React'),
j.memberExpression(
j.identifier('addons'),
j.identifier('shallowCompare'),
false
),
false
),
[
j.thisExpression(),
j.identifier(NEXT_PROPS),
j.identifier(NEXT_STATE),
]
)
),
])
);
const createShouldComponentUpdateProperty = () =>
j.property(
'init',
j.identifier(SHOULD_COMPONENT_UPDATE),
createShouldComponentUpdateFunction()
);
const hasShouldComponentUpdate = classPath =>
ReactUtils.getReactCreateClassSpec(classPath)
.properties.every(property =>
property.key.name !== SHOULD_COMPONENT_UPDATE
);
// ---------------------------------------------------------------------------
// Mixin related code
const isPureRenderMixin = node => (
node.type === 'Identifier' &&
node.name === PURE_RENDER_MIXIN
);
const hasPureRenderMixin = classPath => {
const spec = ReactUtils.getReactCreateClassSpec(classPath);
const mixin = spec && spec.properties.find(ReactUtils.isMixinProperty);
return mixin && mixin.value.elements.some(isPureRenderMixin);
};
const removeMixin = elements =>
j.property(
'init',
j.identifier('mixins'),
j.arrayExpression(
elements.filter(element => !isPureRenderMixin(element))
)
);
// ---------------------------------------------------------------------------
// Boom!
const insertShouldComponentUpdate = properties => {
const length = properties.length;
const lastProp = properties[length - 1];
// I wouldn't dare insert at the bottom if the last function is render
if (
lastProp.key.type === 'Identifier' &&
lastProp.key.name === 'render'
) {
properties.splice(
length - 1,
1,
createShouldComponentUpdateProperty(),
lastProp
);
} else {
properties.push(createShouldComponentUpdateProperty());
}
return properties;
};
const cleanupReactComponent = classPath => {
const spec = ReactUtils.getReactCreateClassSpec(classPath);
const properties = spec.properties
.map(property => {
if (ReactUtils.isMixinProperty(property)) {
const elements = property.value.elements;
return (elements.length !== 1) ? removeMixin(elements) : null;
}
return property;
})
.filter(property => !!property);
ReactUtils.findReactCreateClassCallExpression(classPath).replaceWith(
ReactUtils.createCreateReactClassCallExpression(
insertShouldComponentUpdate(properties)
)
);
};
// Remove it if only two or fewer are left:
// var PureRenderMixin = React.addons.PureRenderMixin;
const hasPureRenderIdentifiers = path =>
path.find(j.Identifier, {
name: PURE_RENDER_MIXIN,
}).size() > 2;
const deletePureRenderMixin = path => {
if (hasPureRenderIdentifiers(path)) {
return;
}
const declaration = path
.findVariableDeclarators(PURE_RENDER_MIXIN)
.closest(j.VariableDeclaration);
if (declaration.size > 1) {
declaration.forEach(p =>
j(p).replaceWith(
j.variableDeclaration(
'var',
p.value.declarations.filter(isPureRenderMixin)
)
)
);
} else {
// Let's assume the variable declaration happens at the top level
const program = declaration.closest(j.Program).get();
const body = program.value.body;
const index = body.indexOf(declaration.get().value);
if (index !== -1) {
body.splice(index, 1);
}
}
};
if (
!options['explicit-require'] ||
ReactUtils.hasReact(root)
) {
const didTransform = ReactUtils
.findReactCreateClass(root)
.filter(hasPureRenderMixin)
.filter(hasShouldComponentUpdate)
.forEach(cleanupReactComponent)
.size() > 0;
if (didTransform) {
deletePureRenderMixin(root);
return root.toSource(printOptions);
}
}
return null;
}
module.exports = removePureRenderMixin;

View File

@@ -1,321 +0,0 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var CORE_PROPERTIES = [
'Children',
'Component',
'createElement',
'cloneElement',
'isValidElement',
'PropTypes',
'createClass',
'createFactory',
'createMixin',
'DOM',
'__spread',
];
var DOM_PROPERTIES = [
'findDOMNode',
'render',
'unmountComponentAtNode',
'unstable_batchedUpdates',
'unstable_renderSubtreeIntoContainer',
];
var DOM_SERVER_PROPERTIES = [
'renderToString',
'renderToStaticMarkup',
];
function reportError(node, error) {
throw new Error(
`At ${node.loc.start.line}:${node.loc.start.column}: ${error}`
);
}
function isRequire(path, moduleName) {
return (
path.value.type === 'CallExpression' &&
path.value.callee.type === 'Identifier' &&
path.value.callee.name === 'require' &&
path.value.arguments.length === 1 &&
path.value.arguments[0].type === 'Literal' &&
path.value.arguments[0].value === moduleName
);
}
module.exports = function(file, api) {
var j = api.jscodeshift;
var root = j(file.source);
[
['React', 'ReactDOM', 'ReactDOMServer'],
['react', 'react-dom', 'react-dom/server'],
].forEach(function(pair) {
var coreModuleName = pair[0];
var domModuleName = pair[1];
var domServerModuleName = pair[2];
var domAlreadyDeclared = false;
var domServerAlreadyDeclared = false;
var coreRequireDeclarator;
root
.find(j.CallExpression)
.filter(p => isRequire(p, coreModuleName))
.forEach(p => {
var name, scope;
if (p.parent.value.type === 'VariableDeclarator') {
if (p.parent.value.id.type === 'ObjectPattern') {
var pattern = p.parent.value.id;
var all = pattern.properties.every(function(prop) {
if (prop.key.type === 'Identifier') {
name = prop.key.name;
return CORE_PROPERTIES.indexOf(name) !== -1;
}
return false;
});
if (all) {
// var {PropTypes} = require('React'); so leave alone
return;
}
}
if (coreRequireDeclarator) {
reportError(
p.value,
'Multiple declarations of React'
);
}
if (p.parent.value.id.type !== 'Identifier') {
reportError(
p.value,
'Unexpected destructuring in require of ' + coreModuleName
);
}
name = p.parent.value.id.name;
scope = p.scope.lookup(name);
if (scope.declares('ReactDOM')) {
console.log('Using existing ReactDOM var in ' + file.path);
domAlreadyDeclared = true;
}
if (scope.declares('ReactDOMServer')) {
console.log('Using existing ReactDOMServer var in ' + file.path);
domServerAlreadyDeclared = true;
}
coreRequireDeclarator = p.parent;
} else if (p.parent.value.type === 'AssignmentExpression') {
if (p.parent.value.left.type !== 'Identifier') {
reportError(
p.value,
'Unexpected destructuring in require of ' + coreModuleName
);
}
name = p.parent.value.left.name;
scope = p.scope.lookup(name);
var reactBindings = scope.getBindings()[name];
if (reactBindings.length !== 1) {
throw new Error(
'Unexpected number of bindings: ' + reactBindings.length
);
}
coreRequireDeclarator = reactBindings[0].parent;
if (coreRequireDeclarator.value.init &&
!isRequire(coreRequireDeclarator.get('init'), coreModuleName)) {
reportError(
coreRequireDeclarator.value,
'Unexpected initialization of ' + coreModuleName
);
}
if (scope.declares('ReactDOM')) {
console.log('Using existing ReactDOM var in ' + file.path);
domAlreadyDeclared = true;
}
if (scope.declares('ReactDOMServer')) {
console.log('Using existing ReactDOMServer var in ' + file.path);
domServerAlreadyDeclared = true;
}
}
});
if (!coreRequireDeclarator) {
return;
}
if (!domAlreadyDeclared &&
root.find(j.Identifier, {name: 'ReactDOM'}).size() > 0) {
throw new Error(
'ReactDOM is already defined in a different scope than React'
);
}
if (!domServerAlreadyDeclared &&
root.find(j.Identifier, {name: 'ReactDOMServer'}).size() > 0) {
throw new Error(
'ReactDOMServer is already defined in a different scope than React'
);
}
var coreName = coreRequireDeclarator.value.id.name;
var processed = new Set();
var requireAssignments = [];
var coreUses = 0;
var domUses = 0;
var domServerUses = 0;
root
.find(j.Identifier, {name: coreName})
.forEach(p => {
if (processed.has(p.value)) {
// https://github.com/facebook/jscodeshift/issues/36
return;
}
processed.add(p.value);
if (p.parent.value.type === 'MemberExpression' ||
p.parent.value.type === 'QualifiedTypeIdentifier') {
var left;
var right;
if (p.parent.value.type === 'MemberExpression') {
left = p.parent.value.object;
right = p.parent.value.property;
} else {
left = p.parent.value.qualification;
right = p.parent.value.id;
}
if (left === p.value) {
// React.foo (or React[foo])
if (right.type === 'Identifier') {
var name = right.name;
if (CORE_PROPERTIES.indexOf(name) !== -1) {
coreUses++;
} else if (DOM_PROPERTIES.indexOf(name) !== -1) {
domUses++;
j(p).replaceWith(j.identifier('ReactDOM'));
} else if (DOM_SERVER_PROPERTIES.indexOf(name) !== -1) {
domServerUses++;
j(p).replaceWith(j.identifier('ReactDOMServer'));
} else {
throw new Error('Unknown property React.' + name);
}
}
} else if (right === p.value) {
// foo.React, no need to transform
} else {
throw new Error('unimplemented');
}
} else if (p.parent.value.type === 'VariableDeclarator') {
if (p.parent.value.id === p.value) {
// var React = ...;
} else if (p.parent.value.init === p.value) {
// var ... = React;
var pattern = p.parent.value.id;
if (pattern.type === 'ObjectPattern') {
// var {PropTypes} = React;
// Most of these cases will just be looking at {PropTypes} so this
// is usually a no-op.
var coreProperties = [];
var domProperties = [];
pattern.properties.forEach(function(prop) {
if (prop.key.type === 'Identifier') {
var key = prop.key.name;
if (CORE_PROPERTIES.indexOf(key) !== -1) {
coreProperties.push(prop);
} else if (DOM_PROPERTIES.indexOf(key) !== -1) {
domProperties.push(prop);
} else {
throw new Error(
'Unknown property React.' + key + ' while destructuring'
);
}
} else {
throw new Error('unimplemented');
}
});
var domDeclarator = j.variableDeclarator(
j.objectPattern(domProperties),
j.identifier('ReactDOM')
);
if (coreProperties.length && !domProperties.length) {
// nothing to do
coreUses++;
} else if (domProperties.length && !coreProperties.length) {
domUses++;
j(p.parent).replaceWith(domDeclarator);
} else {
coreUses++;
domUses++;
var decl = j(p).closest(j.VariableDeclaration);
decl.insertAfter(j.variableDeclaration(
decl.get().value.kind,
[domDeclarator]
));
}
} else {
throw new Error('unimplemented');
}
} else {
throw new Error('unimplemented');
}
} else if (p.parent.value.type === 'AssignmentExpression') {
if (p.parent.value.left === p.value) {
if (isRequire(p.parent.get('right'), coreModuleName)) {
requireAssignments.push(p.parent);
} else {
reportError(
p.parent.value,
'Unexpected assignment to ' + coreModuleName
);
}
} else {
throw new Error('unimplemented');
}
} else {
reportError(p.value, 'unimplemented ' + p.parent.value.type);
}
});
coreUses += root.find(j.JSXElement).size();
function insertRequire(name, path) {
var req = j.callExpression(
j.identifier('require'),
[j.literal(path)]
);
requireAssignments.forEach(function(requireAssignment) {
requireAssignment.parent.insertAfter(
j.expressionStatement(
j.assignmentExpression('=', j.identifier(name), req)
)
);
});
coreRequireDeclarator.parent.insertAfter(j.variableDeclaration(
coreRequireDeclarator.parent.value.kind,
[j.variableDeclarator(
j.identifier(name),
coreRequireDeclarator.value.init ? req : null
)]
));
}
if (domServerUses > 0 && !domServerAlreadyDeclared) {
insertRequire('ReactDOMServer', domServerModuleName);
}
if (domUses > 0 && !domAlreadyDeclared) {
insertRequire('ReactDOM', domModuleName);
}
if ((domUses > 0 || domServerUses > 0) && coreUses === 0) {
j(coreRequireDeclarator).remove();
requireAssignments.forEach(r => j(r).remove());
}
});
return root.toSource({quote: 'single'});
};

View File

@@ -1,160 +0,0 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
module.exports = function(j) {
const REACT_CREATE_CLASS_MEMBER_EXPRESSION = {
type: 'MemberExpression',
object: {
name: 'React',
},
property: {
name: 'createClass',
},
};
// ---------------------------------------------------------------------------
// Checks if the file requires a certain module
const hasModule = (path, module) =>
path
.findVariableDeclarators()
.filter(j.filters.VariableDeclarator.requiresModule(module))
.size() === 1 ||
path
.find(j.ImportDeclaration, {
type: 'ImportDeclaration',
source: {
type: 'Literal',
},
})
.filter(declarator => declarator.value.source.value === module)
.size() === 1;
const hasReact = path => (
hasModule(path, 'React') ||
hasModule(path, 'react') ||
hasModule(path, 'react/addons')
);
// ---------------------------------------------------------------------------
// Finds all variable declarations that call React.createClass
const findReactCreateClassCallExpression = path =>
j(path).find(j.CallExpression, {
callee: REACT_CREATE_CLASS_MEMBER_EXPRESSION,
});
const findReactCreateClass = path =>
path
.findVariableDeclarators()
.filter(decl => findReactCreateClassCallExpression(decl).size() > 0);
const findReactCreateClassExportDefault = path =>
path.find(j.ExportDefaultDeclaration, {
declaration: {
type: 'CallExpression',
callee: REACT_CREATE_CLASS_MEMBER_EXPRESSION,
},
});
const findReactCreateClassModuleExports = path =>
path
.find(j.AssignmentExpression, {
left: {
type: 'MemberExpression',
object: {
type: 'Identifier',
name: 'module',
},
property: {
type: 'Identifier',
name: 'exports',
},
},
right: {
type: 'CallExpression',
callee: REACT_CREATE_CLASS_MEMBER_EXPRESSION,
},
});
// ---------------------------------------------------------------------------
// Finds all classes that extend React.Component
const findReactES6ClassDeclaration = path =>
path
.find(j.ClassDeclaration, {
superClass: {
type: 'MemberExpression',
object: {
type: 'Identifier',
name: 'React',
},
property: {
type: 'Identifier',
name: 'Component',
},
},
});
// ---------------------------------------------------------------------------
// Checks if the React class has mixins
const isMixinProperty = property => {
const key = property.key;
const value = property.value;
return (
key.name === 'mixins' &&
value.type === 'ArrayExpression' &&
Array.isArray(value.elements) &&
value.elements.length
);
};
const hasMixins = classPath => {
const spec = getReactCreateClassSpec(classPath);
return spec && spec.properties.some(isMixinProperty);
};
// ---------------------------------------------------------------------------
// Others
const getReactCreateClassSpec = classPath => {
var {value} = classPath;
const spec = (value.init || value.right || value.declaration).arguments[0];
if (spec.type === 'ObjectExpression' && Array.isArray(spec.properties)) {
return spec;
}
};
const createCreateReactClassCallExpression = properties =>
j.callExpression(
j.memberExpression(
j.identifier('React'),
j.identifier('createClass'),
false
),
[j.objectExpression(properties)]
);
const getComponentName =
classPath => classPath.node.id && classPath.node.id.name;
return {
createCreateReactClassCallExpression,
findReactES6ClassDeclaration,
findReactCreateClass,
findReactCreateClassCallExpression,
findReactCreateClassModuleExports,
findReactCreateClassExportDefault,
getComponentName,
getReactCreateClassSpec,
hasMixins,
hasModule,
hasReact,
isMixinProperty,
};
};

Some files were not shown because too many files have changed in this diff Show More