Compare commits

...

23 Commits

Author SHA1 Message Date
Paul O’Shannessy
df17c7efe3 v0.3.3 2013-06-20 15:14:18 -07:00
CommitSyncScript
2af5be4c4c Support rendering different components into same node
var container = ...; // some DOM node
React.renderComponent(<div />, container);
React.renderComponent(<span />, container);

This should replace the rendered <div> with a <span>, effectively
reconciling at the root level.
(cherry picked from commit 100af48f53)
2013-06-20 10:57:26 -07:00
Paul O’Shannessy
e105cb56e7 Improve JSXTransformer
The biggest improvement is that we'll now insert each parsed JSX script
back into a `<script>` tag with the body set. This allows the browser to
execute these scripts normally. Using `Function(functionBody)` or
`eval(functionBody)` both execute in window scope, but `var` assignments
don't actually get set on window (unlike everywhere else).

I also did some cleanup to make the code a little bit more readable.
In my minimal test cases this didn't break anything (scripts loaded in
the right order).
(cherry picked from commit c79a59b599)
2013-06-19 17:29:05 -07:00
Paul O’Shannessy
9757f0a7e7 Use github tarball link for esprima dependency
It turns out that (at least for local development) npm has a long
standing bug where it doesn't recognize changing dependencies stored as
git urls (see https://github.com/isaacs/npm/issues/1727). Luckily npm
understand tarballs and GitHub provides tarballs for every commit, so
the workaround is easy, though unfortunate.
(cherry picked from commit bd044fc919)
2013-06-19 17:29:05 -07:00
Ben Newman
2d677b78ba Upgrade Recast to 0.4.8 to fix options.writeback bug.
Bug introduced by: https://github.com/benjamn/recast/commit/e913b22f8f
Bug fixed by: https://github.com/benjamn/recast/commit/170e18091e
(cherry picked from commit 2383fd8813)
2013-06-19 17:29:04 -07:00
Ben Newman
3624afaade Upgrade Commoner and Recast to latest versions.
The Commoner upgrade is a big one because it makes bin/jsx no longer
rewrite module identifiers to be relative by default, which should
reduce confusion for people trying to use it as a standalone
transformer.

Closes #80.
(cherry picked from commit 15360056bd)
2013-06-19 17:29:04 -07:00
Paul O’Shannessy
0fbf7ad4e5 Ignore .module-cache directories
(cherry picked from commit 5bd449c157)
2013-06-19 17:29:04 -07:00
Ben Newman
9b810bd7b9 Cache modules for jsx grunt tasks in react-tools/.module-cache.
As of Commoner v0.6.11, the default is to put the cache files in
output/.module-cache, which used to be build/modules/.module-cache
before this commit. That still happens when you run bin/jsx directly,
just not for grunt tasks anymore.

The module cache needs to be cleared much less often than
build/modules, so it doesn't make sense to throw away all that work.
(cherry picked from commit 880ada0a1c)
2013-06-19 17:29:04 -07:00
Vjeux
1c486c40d0 Community Roundup #2 2013-06-19 12:33:14 -07:00
Christopher Chedeau
376045b401 Fix dangerouslySetInnerHTML 2013-06-19 12:32:50 -07:00
Paul O’Shannessy
267c97b14f Use absolute URLs for FB comments box 2013-06-18 10:21:28 -07:00
petehunt
9eed65d7db Update jsx-is-not-html.md 2013-06-17 17:18:48 -07:00
Ben Alpert
f09a068c74 Link to my own blog 2013-06-17 17:18:42 -07:00
Greg Roodt
8eb46be792 Minor grammar. 2013-06-17 17:18:36 -07:00
Greg Roodt
7bbe9baf6f Minor typo. 2013-06-17 17:18:29 -07:00
Greg Roodt
da9ddffb3a Update tutorial.md
The ajax call happens every 5 seconds, not every 60 seconds.
2013-06-17 17:18:23 -07:00
Vjeux
388c8a505d Adding JSX pitfalls section in the docs 2013-06-17 17:17:20 -07:00
Vjeux
dadb3f79cd Facebook comments integration on Docs and Blog 2013-06-17 17:17:07 -07:00
Vjeux
dcd85395fd Using markdown instead of html 2013-06-12 14:05:33 -07:00
Vjeux
c2b4d338ab Integrate twitter in the support page 2013-06-12 14:05:21 -07:00
petehunt
b148b1235e Fixed width/height on React logo 2013-06-12 14:00:33 -07:00
Vjeux
83e1dc5618 Community round-up blog post 2013-06-12 14:00:22 -07:00
jordow
92b795da6a Make todo example shorter and not rely on the DOM. 2013-06-07 15:40:09 -07:00
27 changed files with 363 additions and 91 deletions

2
.gitignore vendored
View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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>

View File

@@ -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);\
";

View File

@@ -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">&copy; 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>

View File

@@ -19,5 +19,7 @@ sectionid: docs
<a class="docs-next" href="/react/docs/{{ page.next }}">Next &rarr;</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>

View File

@@ -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>

View 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>[![](/react/img/blog/khan-academy-editor.png)](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)

View 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>[![](/react/img/blog/chatapp.png)](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>[![](/react/img/blog/xreact.png)](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>[![](/react/img/blog/todomvc.png)](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)

View File

@@ -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 %}

View File

@@ -3,6 +3,7 @@ id: docs-api
title: React API
layout: docs
prev: mixins.html
next: jsx-is-not-html.html
---
## React

View File

@@ -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!".

View 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 &middot; 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 &middot; Second"
<div>{'First &middot; 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>&middot;</span>, ' Second']}</div>
```
As a last resort, you always have the ability to insert raw HTML.
```javascript
<div dangerouslySetInnerHTML={{'{{'}}__html: 'First &middot; 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} />
```

View File

@@ -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.

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@@ -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>

View File

@@ -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>

View File

@@ -9,6 +9,8 @@ module.exports = function() {
var args = [
"bin/jsx",
"--cache-dir", ".module-cache",
"--relativize",
config.sourceDir,
config.outputDir
];

View File

@@ -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": {

View File

@@ -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);

View 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');
});
});

View File

@@ -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) {