Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df17c7efe3 | ||
|
|
2af5be4c4c | ||
|
|
e105cb56e7 | ||
|
|
9757f0a7e7 | ||
|
|
2d677b78ba | ||
|
|
3624afaade | ||
|
|
0fbf7ad4e5 | ||
|
|
9b810bd7b9 | ||
|
|
1c486c40d0 | ||
|
|
376045b401 | ||
|
|
267c97b14f | ||
|
|
9eed65d7db | ||
|
|
f09a068c74 | ||
|
|
8eb46be792 | ||
|
|
7bbe9baf6f | ||
|
|
da9ddffb3a | ||
|
|
388c8a505d | ||
|
|
dadb3f79cd | ||
|
|
dcd85395fd | ||
|
|
c2b4d338ab | ||
|
|
b148b1235e | ||
|
|
83e1dc5618 | ||
|
|
92b795da6a |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,11 +6,13 @@ static
|
||||
.grunt
|
||||
_SpecRunner.html
|
||||
build/
|
||||
.module-cache
|
||||
*.gem
|
||||
docs/code
|
||||
docs/_site
|
||||
docs/.sass-cache
|
||||
docs/css/react.css
|
||||
docs/js/.module-cache
|
||||
docs/js/JSXTransformer.js
|
||||
docs/js/react.min.js
|
||||
docs/js/docs.js
|
||||
|
||||
@@ -5,7 +5,7 @@ description: A JavaScript library for building user interfaces
|
||||
redcarpet:
|
||||
extensions:
|
||||
- fenced_code_blocks
|
||||
react_version: 0.3.2
|
||||
react_version: 0.3.3
|
||||
pygments: true
|
||||
exclude:
|
||||
- Gemfile
|
||||
|
||||
@@ -356,6 +356,22 @@ section.black content {
|
||||
padding-bottom: 18px;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blog
|
||||
*/
|
||||
|
||||
.blogContent {
|
||||
padding-top: 20px;
|
||||
|
||||
blockquote {
|
||||
padding: 5px 15px;
|
||||
margin: 20px 0;
|
||||
background-color: #f8f5ec;
|
||||
border-left: 5px solid #f7ebc6;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Docs
|
||||
*/
|
||||
@@ -495,6 +511,10 @@ p {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
figure {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.inner-content {
|
||||
float: right;
|
||||
width: $skinnyContentWidth;
|
||||
@@ -658,3 +678,7 @@ p code {
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.post {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
@@ -21,4 +21,11 @@
|
||||
<li><a href="/react/docs/api.html"{% if page.id == 'docs-api' %} class="active"{% endif %}>API</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="nav-docs-section">
|
||||
<h3>Appendix</h3>
|
||||
<ul>
|
||||
<li><a href="/react/docs/jsx-is-not-html.html"{% if page.id == 'docs-jsx-is-not-html' %} class="active"{% endif %}>JSX is not HTML</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,48 +6,38 @@ var TODO_COMPONENT = "\
|
||||
/** @jsx React.DOM */\n\
|
||||
var TodoList = React.createClass({\n\
|
||||
render: function() {\n\
|
||||
var items = this.props.items.map(function(item) {\n\
|
||||
return <li>{item}</li>;\n\
|
||||
});\n\
|
||||
return <ul>{items}</ul>;\n\
|
||||
var createItem = function(itemText) {\n\
|
||||
return <li>{itemText}</li>;\n\
|
||||
};\n\
|
||||
return <ul>{this.props.items.map(createItem)}</ul>;\n\
|
||||
}\n\
|
||||
});\n\
|
||||
\n\
|
||||
var TodoCreate = React.createClass({\n\
|
||||
handleSubmit: React.autoBind(function() {\n\
|
||||
var textInput = this.refs.textInput.getDOMNode();\n\
|
||||
this.props.onCreate(textInput.value);\n\
|
||||
textInput.value = '';\n\
|
||||
return false;\n\
|
||||
}),\n\
|
||||
render: function() {\n\
|
||||
return (\n\
|
||||
<form onSubmit={this.handleSubmit}>\n\
|
||||
<input type=\"text\" ref=\"textInput\" />\n\
|
||||
<button>Add</button>\n\
|
||||
</form>\n\
|
||||
);\n\
|
||||
}\n\
|
||||
});\n\
|
||||
\n\
|
||||
var TodoApp = React.createClass({\n\
|
||||
getInitialState: function() {\n\
|
||||
return {items: []};\n\
|
||||
return {items: [], text: ''};\n\
|
||||
},\n\
|
||||
onKey: function(e) {\n\
|
||||
this.setState({text: e.target.value});\n\
|
||||
},\n\
|
||||
handleSubmit: function(e) {\n\
|
||||
e.preventDefault();\n\
|
||||
var nextItems = this.state.items.concat([this.state.text]);\n\
|
||||
var nextText = '';\n\
|
||||
this.setState({items: nextItems, text: nextText});\n\
|
||||
},\n\
|
||||
onItemCreate: React.autoBind(function(value) {\n\
|
||||
this.setState({items: this.state.items.concat([value])});\n\
|
||||
}),\n\
|
||||
render: function() {\n\
|
||||
return (\n\
|
||||
<div>\n\
|
||||
<h3>TODO</h3>\n\
|
||||
<TodoList items={this.state.items} />\n\
|
||||
<TodoCreate onCreate={this.onItemCreate} />\n\
|
||||
<form onSubmit={this.handleSubmit.bind(this)}>\n\
|
||||
<input onKeyUp={this.onKey.bind(this)} value={this.state.text} />\n\
|
||||
<button>{'Add #' + (this.state.items.length + 1)}</button>\n\
|
||||
</form>\n\
|
||||
</div>\n\
|
||||
);\n\
|
||||
}\n\
|
||||
});\n\
|
||||
\n\
|
||||
React.renderComponent(<TodoApp />, mountNode);\
|
||||
";
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<div class="nav-main">
|
||||
<div class="wrap">
|
||||
<a class="nav-home" href="/react/index.html">
|
||||
<img class="nav-logo" alt="" src="/react/img/logo_small.png">
|
||||
<img class="nav-logo" alt="" src="/react/img/logo_small.png" width="38" height="38">
|
||||
React
|
||||
</a>
|
||||
<ul class="nav-site">
|
||||
@@ -72,6 +72,7 @@
|
||||
<div class="right">© 2013 Facebook Inc.</div>
|
||||
</footer>
|
||||
</div>
|
||||
<div id="fb-root"></div>
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
@@ -79,7 +80,16 @@
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
ga('create', 'UA-41298772-1', 'facebook.github.io');
|
||||
ga('send', 'pageview');
|
||||
|
||||
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
|
||||
|
||||
(function(d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) return;
|
||||
js = d.createElement(s); js.id = id;
|
||||
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=623268441017527";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -19,5 +19,7 @@ sectionid: docs
|
||||
<a class="docs-next" href="/react/docs/{{ page.next }}">Next →</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="fb-comments" data-width="650" data-num-posts="10" data-href="{{ site.url }}{{ site.baseurl }}{{ page.url }}"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -3,7 +3,7 @@ layout: default
|
||||
sectionid: blog
|
||||
---
|
||||
|
||||
<section class="content wrap documentationContent">
|
||||
<section class="content wrap blogContent">
|
||||
{% include nav_blog.html %}
|
||||
<div class="inner-content">
|
||||
<h1>{{ page.title }}</h1>
|
||||
@@ -14,5 +14,8 @@ sectionid: blog
|
||||
<div class="post">
|
||||
{{ content }}
|
||||
</div>
|
||||
|
||||
<div class="fb-like" data-send="true" data-width="650" data-show-faces="false"></div>
|
||||
<div class="fb-comments" data-width="650" data-num-posts="10" data-href="{{ site.url }}{{ site.baseurl }}{{ page.url }}"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
48
docs/_posts/2013-06-12-community-roundup.md
Normal file
48
docs/_posts/2013-06-12-community-roundup.md
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
title: "Community Round-up #1"
|
||||
layout: post
|
||||
author: Vjeux
|
||||
---
|
||||
|
||||
React was open sourced two weeks ago and it's time for a little round-up of what has been going on.
|
||||
|
||||
## Khan Academy Question Editor
|
||||
|
||||
It looks like [Ben Alpert](http://benalpert.com/) is the first person outside of Facebook and Instagram to push React code to production. We are very grateful for his contributions in form of pull requests, bug reports and presence on IRC ([#reactjs on Freenode](irc://chat.freenode.net/reactjs)). Ben wrote about his experience using React:
|
||||
|
||||
> I just rewrote a 2000-line project in React and have now made a handful of pull requests to React. Everything about React I've seen so far seems really well thought-out and I'm proud to be the first non-FB/IG production user of React.
|
||||
>
|
||||
> The project that I rewrote in React (and am continuing to improve) is the Khan Academy question editor which content creators can use to enter questions and hints that will be presented to students:
|
||||
> <figure>[](http://benalpert.com/2013/06/09/using-react-to-speed-up-khan-academy.html)</figure>
|
||||
>
|
||||
> [Read the full post...](http://benalpert.com/2013/06/09/using-react-to-speed-up-khan-academy.html)
|
||||
|
||||
## Pimp my Backbone.View (by replacing it with React)
|
||||
|
||||
[Paul Seiffert](https://blog.mayflower.de/) wrote a blog post that explains how to integrate React into Backbone applications.
|
||||
|
||||
> React has some interesting concepts for JavaScript view objects that can be used to eliminate this one big problem I have with Backbone.js.
|
||||
>
|
||||
> As in most MVC implementations (although React is probably just a VC implementation), a view is one portion of the screen that is managed by a controlling object. This object is responsible for deciding when to re-render the view and how to react to user input. With React, these view-controllers objects are called components. A component knows how to render its view and how to handle to the user's interaction with it.
|
||||
>
|
||||
> The interesting thing is that React is figuring out by itself when to re-render a view and how to do this in the most efficient way.
|
||||
>
|
||||
> [Read the full post...](https://blog.mayflower.de/3937-Backbone-React.html)
|
||||
|
||||
## Using facebook's React with require.js
|
||||
|
||||
[Mario Mueller](http://blog.xenji.com/) wrote a menu component in React and was able to easily integrate it with require.js, EventEmitter2 and bower.
|
||||
|
||||
> I recently stumbled upon facebook's React library, which is a Javascript library for building reusable frontend components. Even if this lib is only at version 0.3.x it behaves very stable, it is fast and is fun to code. I'm a big fan of require.js, so I tried to use React within the require.js eco system. It was not as hard as expected and here are some examples and some thoughts about it.
|
||||
>
|
||||
> [Read the full post...](http://blog.xenji.com/2013/06/facebooks-react-require-js.html)
|
||||
|
||||
## Origins of React
|
||||
|
||||
[Pete Hunt](http://www.petehunt.net/blog/) explained what differentiates React from other JavaScript libraries in [a previous blog post](http://facebook.github.io/react/blog/2013/06/05/why-react.html). [Lee Byron](http://leebyron.com/) gives another perspective on Quora:
|
||||
|
||||
> React isn't quite like any other popular Javascript libraries, and it solves a very specific problem: complex UI rendering. It's also intended to be used along side many other popular libraries. For example, React works well with Backbone.js, amongst many others.
|
||||
>
|
||||
> React was born out of frustrations with the common pattern of writing two-way data bindings in complex MVC apps. React is an implementation of one-way data bindings.
|
||||
>
|
||||
> [Read the full post...](http://www.quora.com/React-JS-Library/How-is-Facebooks-React-JavaScript-library/answer/Lee-Byron?srid=3DcX)
|
||||
71
docs/_posts/2013-06-19-community-roundup-2.md
Normal file
71
docs/_posts/2013-06-19-community-roundup-2.md
Normal file
@@ -0,0 +1,71 @@
|
||||
---
|
||||
title: "Community Round-up #2"
|
||||
layout: post
|
||||
author: Vjeux
|
||||
---
|
||||
|
||||
Since the launch we have received a lot of feedback and are actively working on React 0.4. In the meantime, here are the highlights of this week.
|
||||
|
||||
## Some quick thoughts on React
|
||||
|
||||
[Andrew Greig](http://www.andrewgreig.com/) made a blog post that gives a high level description of what React is.
|
||||
|
||||
> I have been using Facebooks recently released Javascript framework called React.js for the last few days and have managed to obtain a rather high level understanding of how it works and formed a good perspective on how it fits in to the entire javascript framework ecosystem.
|
||||
>
|
||||
> Basically, React is not an MVC framework. It is not a replacement for Backbone or Knockout or Angular, instead it is designed to work with existing frameworks and help extend their functionality.
|
||||
>
|
||||
> It is designed for building big UIs. The type where you have lots of reusable components that are handling events and presenting and changing some backend data. In a traditional MVC app, React fulfils the role of the View. So you would still need to handle the Model and Controller on your own.
|
||||
>
|
||||
> I found the best way to utilise React was to pair it with Backbone, with React replacing the Backbone View, or to write your own Model/Data object and have React communicate with that.
|
||||
>
|
||||
> [Read the full post...](http://www.andrewgreig.com/637/)
|
||||
|
||||
## React and Socket.IO Chat Application
|
||||
|
||||
[Danial Khosravi](http://danialk.github.io/) made a real-time chat application that interacts with the back-end using Socket.IO.
|
||||
|
||||
> A week ago I was playing with AngularJS and [this little chat application](https://github.com/btford/angular-socket-io-im) which uses socket.io and nodejs for realtime communication. Yesterday I saw a post about ReactJS in [EchoJS](http://www.echojs.com/) and started playing with this UI library. After playing a bit with React, I decided to write and chat application using React and I used Bran Ford's Backend for server side of this little app.
|
||||
> <figure>[](http://danialk.github.io/blog/2013/06/16/reactjs-and-socket-dot-io-chat-application/)</figure>
|
||||
>
|
||||
> [Read the full post...](http://danialk.github.io/blog/2013/06/16/reactjs-and-socket-dot-io-chat-application/)
|
||||
|
||||
## React and Other Frameworks
|
||||
|
||||
[Pete Hunt](http://www.petehunt.net/blog/) wrote an answer on Quora comparing React and Angular directives. At the end, he explains how you can make an Angular directive that is in fact being rendered with React.
|
||||
|
||||
> To set the record straight: React components are far more powerful than Angular templates; they should be compared with Angular's directives instead. So I took the first Google hit for "AngularJS directive tutorial" (AngularJS Directives Tutorial - Fundoo Solutions), rewrote it in React and compared them. [...]
|
||||
>
|
||||
> We've designed React from the beginning to work well with other libraries. Angular is no exception. Let's take the original Angular example and use React to implement the fundoo-rating directive.
|
||||
>
|
||||
> [Read the full post...](http://www.quora.com/Pete-Hunt/Posts/Facebooks-React-vs-AngularJS-A-Closer-Look)
|
||||
|
||||
In the same vein, [Markov Twain](https://twitter.com/markov_twain/status/345702941845499906) re-implemented the examples on the front-page [with Ember](http://jsbin.com/azihiw/2/edit) and [Vlad Yazhbin](https://twitter.com/vla) re-implemented the tutorial [with Angular](http://jsfiddle.net/vla/Cdrse/).
|
||||
|
||||
## Web Components: React & x-tags
|
||||
|
||||
Mozilla and Google are actively working on Web Components. [Vjeux](http://blog.vjeux.com/) wrote a proof of concept that shows how to implement them using React.
|
||||
|
||||
> Using [x-tags](http://www.x-tags.org/) from Mozilla, we can write custom tags within the DOM. This is a great opportunity to be able to write reusable components without being tied to a particular library. I wrote [x-react](https://github.com/vjeux/react-xtags/) to have them being rendered in React.
|
||||
> <figure>[](http://blog.vjeux.com/2013/javascript/custom-components-react-x-tags.html)</figure>
|
||||
>
|
||||
> [Read the full post...](http://blog.vjeux.com/2013/javascript/custom-components-react-x-tags.html)
|
||||
|
||||
## React TodoMVC Example
|
||||
|
||||
[TodoMVC.com](http://todomvc.com/) is a website that collects various implementations of the same basic Todo app. [Pete Hunt](http://www.petehunt.net/blog/) wrote an idiomatic React version.
|
||||
|
||||
> Developers these days are spoiled with choice when it comes to selecting an MV* framework for structuring and organizing their JavaScript web apps.
|
||||
>
|
||||
> To help solve this problem, we created TodoMVC - a project which offers the same Todo application implemented using MV* concepts in most of the popular JavaScript MV* frameworks of today.
|
||||
> <figure>[](http://todomvc.com/labs/architecture-examples/react/)</figure>
|
||||
>
|
||||
> [Read the source code...](https://github.com/tastejs/todomvc/tree/gh-pages/labs/architecture-examples/react)
|
||||
|
||||
## JSX is not HTML
|
||||
|
||||
Many of you pointed out differences between JSX and HTML. In order to clear up some confusion, we have added some documentation that covers the four main differences:
|
||||
|
||||
- [Whitespace removal](http://facebook.github.io/react/docs/jsx-is-not-html.html)
|
||||
- [HTML Entities](http://facebook.github.io/react/docs/jsx-is-not-html.html)
|
||||
- [Comments](http://facebook.github.io/react/docs/jsx-is-not-html.html)
|
||||
- [Custom HTML Attributes](http://facebook.github.io/react/docs/jsx-is-not-html.html)
|
||||
@@ -4,7 +4,7 @@ layout: default
|
||||
sectionid: blog
|
||||
---
|
||||
|
||||
<section class="content wrap documentationContent">
|
||||
<section class="content wrap blogContent">
|
||||
{% include nav_blog.html %}
|
||||
<div class="inner-content">
|
||||
{% for page in site.posts %}
|
||||
|
||||
@@ -3,6 +3,7 @@ id: docs-api
|
||||
title: React API
|
||||
layout: docs
|
||||
prev: mixins.html
|
||||
next: jsx-is-not-html.html
|
||||
---
|
||||
|
||||
## React
|
||||
|
||||
@@ -22,7 +22,7 @@ In this one simple line, we have accomplished the following:
|
||||
- The component is **mounted** into `document.body`.
|
||||
|
||||
**Mounting** is the process of initializing a React component by creating its
|
||||
DOM nodes and inserting the them into a supplied container node.
|
||||
DOM nodes and inserting them into a supplied container node.
|
||||
|
||||
At this point, the entire page consists of a single `<div>` with "Hello,
|
||||
world!".
|
||||
|
||||
95
docs/docs/jsx-is-not-html.md
Normal file
95
docs/docs/jsx-is-not-html.md
Normal file
@@ -0,0 +1,95 @@
|
||||
---
|
||||
id: docs-jsx-is-not-html
|
||||
title: JSX is not HTML
|
||||
description: Differences between JSX and HTML.
|
||||
layout: docs
|
||||
prev: api.html
|
||||
---
|
||||
|
||||
JSX looks like HTML but there are some important differences you may run into.
|
||||
|
||||
## Whitespace removal
|
||||
|
||||
JSX doesn't follow the same whitespace elimination rules as HTML. JSX removes all whitespace between two curly braces expressions. If you want to have whitespace, simply add `{' '}`.
|
||||
|
||||
```javascript
|
||||
<div>{this.props.name} {' '} {this.props.surname}</div>
|
||||
```
|
||||
|
||||
Follow [Issue #65](https://github.com/facebook/react/issues/65) for discussion on this behavior.
|
||||
|
||||
## HTML Entities
|
||||
|
||||
You can insert HTML entities within literal text in JSX:
|
||||
|
||||
```javascript
|
||||
<div>First · Second</div>
|
||||
```
|
||||
|
||||
If you want to display an HTML entity within dynamic content, you will run into double escaping issues as React escapes all the strings you are displaying in order to prevent a wide range of XSS attacks by default.
|
||||
|
||||
```javascript
|
||||
// Bad: It displays "First · Second"
|
||||
<div>{'First · Second'}</div>
|
||||
```
|
||||
|
||||
There are various ways to work-around this issue. The easiest one is to write unicode character directly in Javascript. You need to make sure that the file is saved as UTF-8 and that the proper UTF-8 directives are set so the browser will display it correctly.
|
||||
|
||||
```javascript
|
||||
<div>{'First · Second'}</div>
|
||||
```
|
||||
|
||||
A safer alternative is to find the [unicode number corresponding to the entity](http://www.fileformat.info/info/unicode/char/b7/index.htm) and use it inside of a JavaScript string.
|
||||
|
||||
```javascript
|
||||
<div>{'First \u00b7 Second'}</div>
|
||||
<div>{'First ' + String.fromCharCode(183) + ' Second'}</div>
|
||||
```
|
||||
|
||||
You can use mixed arrays with strings and JSX elements.
|
||||
|
||||
```javascript
|
||||
<div>{['First ', <span>·</span>, ' Second']}</div>
|
||||
```
|
||||
|
||||
As a last resort, you always have the ability to insert raw HTML.
|
||||
|
||||
```javascript
|
||||
<div dangerouslySetInnerHTML={{'{{'}}__html: 'First · Second'}} />
|
||||
```
|
||||
|
||||
## Comments
|
||||
|
||||
JSX supports both single-line and multi-line JavaScript comments within a tag declaration:
|
||||
|
||||
```javascript
|
||||
<div // This is a single-line comment:
|
||||
/*
|
||||
And a multi-line
|
||||
comment
|
||||
*/
|
||||
/>
|
||||
```
|
||||
|
||||
As of React 0.3, there is no good way to insert comments within the children section. [Issue #82](https://github.com/facebook/react/issues/82) is tracking progress to enable the following:
|
||||
|
||||
```javascript
|
||||
// Note: This is not implemented yet!
|
||||
<div>
|
||||
{/* This is a comment */}
|
||||
</div>
|
||||
```
|
||||
|
||||
## Custom HTML Attributes
|
||||
|
||||
If you pass properties to native HTML elements that do not exist in the HTML specification, React will not render them. If you want to use a custom attribute, you should prefix it with `data-`.
|
||||
|
||||
```javascript
|
||||
<div data-custom-attribute="foo" />
|
||||
```
|
||||
|
||||
[Web Accessibility](http://www.w3.org/WAI/intro/aria) attributes starting with `aria-` will be rendered properly.
|
||||
|
||||
```javascript
|
||||
<div aria-hidden={true} />
|
||||
```
|
||||
@@ -53,7 +53,7 @@ var app = Nav({color:'blue'}, Profile({}, 'click'));
|
||||
```
|
||||
|
||||
Use the [JSX Compiler](/react/jsx-compiler.html) to try out JSX and see how it
|
||||
desguars into native JavaScript.
|
||||
desugars into native JavaScript.
|
||||
|
||||
If you want to use JSX, the [Getting Started](getting-started.html) guide shows
|
||||
how to setup compilation.
|
||||
|
||||
@@ -435,7 +435,7 @@ React.renderComponent(
|
||||
|
||||
```
|
||||
|
||||
All we have done here is move the AJAX call to a separate method and call it when the component is first loaded and every 60 seconds after that. Try running this in your browser and changing the `comments.json` file; within 5 seconds, the changes will show!
|
||||
All we have done here is move the AJAX call to a separate method and call it when the component is first loaded and every 5 seconds after that. Try running this in your browser and changing the `comments.json` file; within 5 seconds, the changes will show!
|
||||
|
||||
## Adding new comments
|
||||
|
||||
|
||||
BIN
docs/img/blog/chatapp.png
Normal file
BIN
docs/img/blog/chatapp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
BIN
docs/img/blog/khan-academy-editor.png
Normal file
BIN
docs/img/blog/khan-academy-editor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
docs/img/blog/todomvc.png
Normal file
BIN
docs/img/blog/todomvc.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
BIN
docs/img/blog/xreact.png
Normal file
BIN
docs/img/blog/xreact.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.7 KiB |
@@ -56,10 +56,11 @@ id: home
|
||||
<div class="example">
|
||||
<h3>An Application</h3>
|
||||
<p>
|
||||
Using properties and state, we can put together a small Todo
|
||||
application. React provides an interface to the DOM via `refs`. Although
|
||||
event handlers appear to be rendered inline, they will be
|
||||
collected and implemented using event delegation.
|
||||
Using `props` and `state`, we can put together a small Todo application.
|
||||
This example uses `state` to track the current list of items as well as
|
||||
the text that the user has entered. Although event handlers appear to be
|
||||
rendered inline, they will be collected and implemented using event
|
||||
delegation.
|
||||
</p>
|
||||
<div id="todoExample"></div>
|
||||
</div>
|
||||
|
||||
@@ -13,3 +13,9 @@ id: support
|
||||
## IRC
|
||||
|
||||
Many developers and users idle on Freenode.net's IRC network in **[#reactjs on freenode](irc://chat.freenode.net/reactjs)**.
|
||||
|
||||
## Twitter
|
||||
|
||||
[**#reactjs** hash tag on Twitter](https://twitter.com/search?q=%23reactjs) is used to keep up with the latest React news.
|
||||
|
||||
<center><a class="twitter-timeline" data-dnt="true" data-chrome="nofooter noheader transparent" href="https://twitter.com/search?q=%23reactjs" data-widget-id="342522405270470656"></a></center>
|
||||
|
||||
@@ -9,6 +9,8 @@ module.exports = function() {
|
||||
|
||||
var args = [
|
||||
"bin/jsx",
|
||||
"--cache-dir", ".module-cache",
|
||||
"--relativize",
|
||||
config.sourceDir,
|
||||
config.outputDir
|
||||
];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-tools",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"keywords": [
|
||||
"react",
|
||||
"jsx",
|
||||
@@ -36,9 +36,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"base62": "~0.1.1",
|
||||
"commoner": "~0.6.8",
|
||||
"esprima": "git://github.com/facebook/esprima#fb-harmony",
|
||||
"recast": "~0.3.3",
|
||||
"commoner": "~0.7.0",
|
||||
"esprima": "https://github.com/facebook/esprima/tarball/ca28795124d45968e62a7b4b336d23a053ac3a84",
|
||||
"recast": "~0.4.8",
|
||||
"source-map": "~0.1.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -106,11 +106,15 @@ var ReactMount = {
|
||||
renderComponent: function(nextComponent, container) {
|
||||
var prevComponent = instanceByReactRootID[getReactRootID(container)];
|
||||
if (prevComponent) {
|
||||
var nextProps = nextComponent.props;
|
||||
ReactMount.scrollMonitor(container, function() {
|
||||
prevComponent.replaceProps(nextProps);
|
||||
});
|
||||
return prevComponent;
|
||||
if (prevComponent.constructor === nextComponent.constructor) {
|
||||
var nextProps = nextComponent.props;
|
||||
ReactMount.scrollMonitor(container, function() {
|
||||
prevComponent.replaceProps(nextProps);
|
||||
});
|
||||
return prevComponent;
|
||||
} else {
|
||||
ReactMount.unmountAndReleaseReactRootNode(container);
|
||||
}
|
||||
}
|
||||
|
||||
ReactMount.prepareTopLevelEvents(ReactEventTopLevelCallback);
|
||||
|
||||
22
src/core/__tests__/ReactMount-test.js
Normal file
22
src/core/__tests__/ReactMount-test.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* @jsx React.DOM
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
describe('ReactMount', function() {
|
||||
var React = require('React');
|
||||
var ReactMount = require('ReactMount');
|
||||
|
||||
it('should render different components in same root', function() {
|
||||
var container = document.createElement('container');
|
||||
document.documentElement.appendChild(container);
|
||||
|
||||
ReactMount.renderComponent(<div></div>, container);
|
||||
expect(container.firstChild.nodeName).toBe('DIV');
|
||||
|
||||
ReactMount.renderComponent(<span></span>, container);
|
||||
expect(container.firstChild.nodeName).toBe('SPAN');
|
||||
});
|
||||
});
|
||||
68
vendor/browser-transforms.js
vendored
68
vendor/browser-transforms.js
vendored
@@ -24,22 +24,22 @@ var visitors = require('./fbtransform/visitors').transformVisitors;
|
||||
var transform = transform.bind(null, visitors.react);
|
||||
var docblock = require('./fbtransform/lib/docblock');
|
||||
|
||||
var headEl = document.getElementsByTagName('head')[0];
|
||||
|
||||
exports.transform = transform;
|
||||
|
||||
exports.exec = function(code) {
|
||||
return eval(transform(code));
|
||||
};
|
||||
var run = exports.run = function(code) {
|
||||
var moduleName =
|
||||
docblock.parseAsObject(docblock.extract(code)).providesModule;
|
||||
var jsx =
|
||||
docblock.parseAsObject(docblock.extract(code)).jsx;
|
||||
|
||||
window.moduleLoads = (window.moduleLoads || []).concat(moduleName);
|
||||
window.startTime = Date.now();
|
||||
var run = exports.run = function(code) {
|
||||
var jsx = docblock.parseAsObject(docblock.extract(code)).jsx;
|
||||
|
||||
var functionBody = jsx ? transform(code).code : code;
|
||||
Function('require', 'module', 'exports', functionBody)(require, module, exports);
|
||||
window.endTime = Date.now();
|
||||
require[moduleName] = module.exports;
|
||||
var scriptEl = document.createElement('script');
|
||||
|
||||
scriptEl.innerHTML = functionBody;
|
||||
headEl.appendChild(scriptEl);
|
||||
};
|
||||
|
||||
if (typeof window === "undefined" || window === null) {
|
||||
@@ -48,15 +48,17 @@ if (typeof window === "undefined" || window === null) {
|
||||
|
||||
var load = exports.load = function(url, callback) {
|
||||
var xhr;
|
||||
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
|
||||
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP')
|
||||
: new XMLHttpRequest();
|
||||
// Disable async since we need to execute scripts in the order they are in the
|
||||
// DOM to mirror normal script loading.
|
||||
xhr.open('GET', url, false);
|
||||
if ('overrideMimeType' in xhr) {
|
||||
xhr.overrideMimeType('text/plain');
|
||||
}
|
||||
xhr.onreadystatechange = function() {
|
||||
var _ref;
|
||||
if (xhr.readyState === 4) {
|
||||
if ((_ref = xhr.status) === 0 || _ref === 200) {
|
||||
if (xhr.status === 0 || xhr.status === 200) {
|
||||
run(xhr.responseText);
|
||||
} else {
|
||||
throw new Error("Could not load " + url);
|
||||
@@ -70,37 +72,19 @@ var load = exports.load = function(url, callback) {
|
||||
};
|
||||
|
||||
runScripts = function() {
|
||||
var jsxes, execute, index, length, s, scripts;
|
||||
scripts = document.getElementsByTagName('script');
|
||||
jsxes = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
|
||||
s = scripts[_i];
|
||||
if (s.type === 'text/jsx') {
|
||||
_results.push(s);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
index = 0;
|
||||
length = jsxes.length;
|
||||
(execute = function(j) {
|
||||
var script;
|
||||
script = jsxes[j];
|
||||
if ((script != null ? script.type : void 0) === 'text/jsx') {
|
||||
if (script.src) {
|
||||
return load(script.src, execute);
|
||||
} else {
|
||||
run(script.innerHTML);
|
||||
return execute();
|
||||
}
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
scripts = Array.prototype.slice.call(scripts);
|
||||
var jsxScripts = scripts.filter(function(script) {
|
||||
return script.type === 'text/jsx';
|
||||
});
|
||||
|
||||
jsxScripts.forEach(function(script) {
|
||||
if (script.src) {
|
||||
load(script.src);
|
||||
} else {
|
||||
run(script.innerHTML);
|
||||
}
|
||||
});
|
||||
for (var i = 0; i < jsxes.length; i++) {
|
||||
execute(i);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
if (window.addEventListener) {
|
||||
|
||||
Reference in New Issue
Block a user