forked from ruanyf/react-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
353 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// copied from https://github.com/mhart/react-server-example | ||
|
||
$ npm install | ||
$ jsx src/ . | ||
$ node server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var React = require('react'); | ||
|
||
module.exports = React.createClass({displayName: "exports", | ||
|
||
getInitialState: function() { | ||
return { | ||
items: this.props.items, | ||
disabled: true | ||
} | ||
}, | ||
|
||
componentDidMount: function() { | ||
this.setState({ | ||
disabled: false | ||
}) | ||
}, | ||
|
||
handleClick: function() { | ||
this.setState({ | ||
items: this.state.items.concat('Item ' + this.state.items.length) | ||
}) | ||
}, | ||
|
||
render: function() { | ||
return ( | ||
React.createElement("div", null, | ||
React.createElement("button", {onClick: this.handleClick, disabled: this.state.disabled}, "Add Item"), | ||
React.createElement("ul", null, | ||
|
||
this.state.items.map(function(item) { | ||
return React.createElement("li", null, item) | ||
}) | ||
|
||
) | ||
) | ||
) | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var React = require('react'); | ||
var App = require('./app'); | ||
|
||
React.render(React.createElement(App, {items: window.APP_PROPS.items}), document.getElementById('content')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "react-server", | ||
"version": "1.0.0", | ||
"description": "an example of react.js in server", | ||
"main": "server.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "ruanyf", | ||
"license": "ISC", | ||
"dependencies": { | ||
"browserify": "~9.0.3", | ||
"literalify": "~0.4.0", | ||
"react": "~0.13.1" | ||
}, | ||
"devDependencies": { | ||
"react-tools": "~0.13.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var http = require('http'), | ||
browserify = require('browserify'), | ||
literalify = require('literalify'), | ||
React = require('react'); | ||
|
||
var App = require('./app'); | ||
|
||
http.createServer(function(req, res) { | ||
if (req.url == '/') { | ||
res.setHeader('Content-Type', 'text/html'); | ||
var props = { | ||
items: [ | ||
'Item 0', | ||
'Item 1' | ||
] | ||
}; | ||
var html = React.renderToStaticMarkup( | ||
React.createElement("body", null, | ||
React.createElement("div", {id: "content", dangerouslySetInnerHTML: {__html: | ||
React.renderToString(React.createElement(App, {items: props.items})) | ||
}}), ",", | ||
|
||
React.createElement("script", {dangerouslySetInnerHTML: {__html: | ||
'var APP_PROPS = ' + JSON.stringify(props) + ';' | ||
}}), | ||
React.createElement("script", {src: "//fb.me/react-0.13.1.min.js"}), | ||
React.createElement("script", {src: "/bundle.js"}) | ||
) | ||
); | ||
res.end(html); | ||
|
||
} else if (req.url == '/bundle.js') { | ||
res.setHeader('Content-Type', 'text/javascript'); | ||
browserify() | ||
.add('./browser.js') | ||
.transform(literalify.configure({react: 'window.React'})) | ||
.bundle() | ||
.pipe(res); | ||
|
||
} else { | ||
res.statusCode = 404; | ||
res.end(); | ||
} | ||
}).listen(3000, function(err) { | ||
if (err) throw err; | ||
console.log('Listening on 3000...'); | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var React = require('react'); | ||
|
||
module.exports = React.createClass({ | ||
|
||
getInitialState: function() { | ||
return { | ||
items: this.props.items, | ||
disabled: true | ||
} | ||
}, | ||
|
||
componentDidMount: function() { | ||
this.setState({ | ||
disabled: false | ||
}) | ||
}, | ||
|
||
handleClick: function() { | ||
this.setState({ | ||
items: this.state.items.concat('Item ' + this.state.items.length) | ||
}) | ||
}, | ||
|
||
render: function() { | ||
return ( | ||
<div> | ||
<button onClick={this.handleClick} disabled={this.state.disabled}>Add Item</button> | ||
<ul> | ||
{ | ||
this.state.items.map(function(item) { | ||
return <li>{item}</li> | ||
}) | ||
} | ||
</ul> | ||
</div> | ||
) | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var React = require('react'); | ||
var App = require('./app'); | ||
|
||
React.render(<App items={window.APP_PROPS.items} />, document.getElementById('content')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var http = require('http'), | ||
browserify = require('browserify'), | ||
literalify = require('literalify'), | ||
React = require('react'); | ||
|
||
var App = require('./app'); | ||
|
||
http.createServer(function(req, res) { | ||
if (req.url == '/') { | ||
res.setHeader('Content-Type', 'text/html'); | ||
var props = { | ||
items: [ | ||
'Item 0', | ||
'Item 1' | ||
] | ||
}; | ||
var html = React.renderToStaticMarkup( | ||
<body> | ||
<div id="content" dangerouslySetInnerHTML={{__html: | ||
React.renderToString(<App items={props.items}/>) | ||
}} />, | ||
|
||
<script dangerouslySetInnerHTML={{__html: | ||
'var APP_PROPS = ' + JSON.stringify(props) + ';' | ||
}}/> | ||
<script src="//fb.me/react-0.13.1.min.js"/> | ||
<script src="/bundle.js"/> | ||
</body> | ||
); | ||
res.end(html); | ||
|
||
} else if (req.url == '/bundle.js') { | ||
res.setHeader('Content-Type', 'text/javascript'); | ||
browserify() | ||
.add('./browser.js') | ||
.transform(literalify.configure({react: 'window.React'})) | ||
.bundle() | ||
.pipe(res); | ||
|
||
} else { | ||
res.statusCode = 404; | ||
res.end(); | ||
} | ||
}).listen(3000, function(err) { | ||
if (err) throw err; | ||
console.log('Listening on 3000...'); | ||
}) | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.