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
15 changed files
with
354 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
examples/remount/assets |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
examples/remount/assets |
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 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 Hapi = require('hapi'); | ||
var Vision = require('vision'); | ||
var HapiReactViews = require('../..'); | ||
|
||
|
||
var server = new Hapi.Server(); | ||
server.connection(); | ||
server.register(Vision, function (err) { | ||
|
||
if (err) { | ||
console.log('Failed to load vision.'); | ||
} | ||
|
||
server.views({ | ||
engines: { | ||
jsx: HapiReactViews | ||
}, | ||
relativeTo: __dirname, | ||
path: 'views' | ||
}); | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/', | ||
handler: function (request, reply) { | ||
|
||
reply.view('home'); | ||
} | ||
}); | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/about', | ||
handler: function (request, reply) { | ||
|
||
reply.view('about'); | ||
} | ||
}); | ||
|
||
server.start(function (err) { | ||
|
||
if (err) { | ||
throw err; | ||
} | ||
|
||
console.log('Server is listening at ' + server.info.uri); | ||
}); | ||
}); |
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,17 @@ | ||
var React = require('react'); | ||
var Layout = require('./layout.jsx'); | ||
|
||
|
||
var Component = React.createClass({ | ||
render: function () { | ||
|
||
return ( | ||
<Layout title="About Us"> | ||
<h1>About the plot device.</h1> | ||
</Layout> | ||
); | ||
} | ||
}); | ||
|
||
|
||
module.exports = Component; |
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,17 @@ | ||
var React = require('react'); | ||
var Layout = require('./layout.jsx'); | ||
|
||
|
||
var Component = React.createClass({ | ||
render: function () { | ||
|
||
return ( | ||
<Layout title="Home Page"> | ||
<h1>Welcome to the plot device.</h1> | ||
</Layout> | ||
); | ||
} | ||
}); | ||
|
||
|
||
module.exports = Component; |
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,25 @@ | ||
var React = require('react'); | ||
|
||
|
||
var Component = React.createClass({ | ||
render: function () { | ||
|
||
return ( | ||
<html> | ||
<head> | ||
<title>{this.props.title}</title> | ||
</head> | ||
<body> | ||
{this.props.children} | ||
<hr /> | ||
<p> | ||
<a href="/">Home</a> | <a href="/about">About Us</a> | ||
</p> | ||
</body> | ||
</html> | ||
); | ||
} | ||
}); | ||
|
||
|
||
module.exports = Component; |
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,10 @@ | ||
var React = require('react'); | ||
var AppComponent = require('./components/app.jsx'); | ||
|
||
|
||
var App = React.createFactory(AppComponent); | ||
var mountNode = document.getElementById('app-mount'); | ||
var serverState = window.state; | ||
|
||
|
||
React.render(App(serverState), mountNode); |
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,14 @@ | ||
var React = require('react'); | ||
|
||
|
||
var Component = React.createClass({ | ||
render: function () { | ||
|
||
return ( | ||
<div>Foo: {this.props.foo}</div> | ||
); | ||
} | ||
}); | ||
|
||
|
||
module.exports = Component; |
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,27 @@ | ||
var React = require('react'); | ||
|
||
|
||
var Component = React.createClass({ | ||
render: function () { | ||
|
||
return ( | ||
<html> | ||
<head> | ||
<title>Remount Example</title> | ||
</head> | ||
<body> | ||
<div id="app-mount" | ||
dangerouslySetInnerHTML={{ __html: this.props.remount }}> | ||
</div> | ||
<script id="app-state" | ||
dangerouslySetInnerHTML={{ __html: this.props.state }}> | ||
</script> | ||
<script src="/assets/client.js"></script> | ||
</body> | ||
</html> | ||
); | ||
} | ||
}); | ||
|
||
|
||
module.exports = Component; |
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,69 @@ | ||
var Path = require('path'); | ||
var Hapi = require('hapi'); | ||
var Inert = require('inert'); | ||
var Vision = require('vision'); | ||
var HapiReactViews = require('../..'); | ||
|
||
|
||
var server = new Hapi.Server(); | ||
server.connection(); | ||
server.register([Inert, Vision], function (err) { | ||
|
||
if (err) { | ||
console.log('Failed to load plugins.'); | ||
} | ||
|
||
server.views({ | ||
engines: { | ||
jsx: HapiReactViews | ||
}, | ||
relativeTo: __dirname, | ||
path: 'components' | ||
}); | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/assets/client.js', | ||
handler: { | ||
file: Path.join(__dirname, './assets/client.js') | ||
} | ||
}); | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/', | ||
handler: function (request, reply) { | ||
|
||
var appContext = { | ||
foo: 'bar' | ||
}; | ||
var renderOpts = { | ||
runtimeOptions: { | ||
renderMethod: 'renderToString' | ||
} | ||
}; | ||
|
||
server.render('app', appContext, renderOpts, function (err, appOutput) { | ||
|
||
var htmlContext = { | ||
remount: appOutput, | ||
state: 'window.state = ' + JSON.stringify(appContext) + ';' | ||
}; | ||
|
||
server.render('html', htmlContext, function (err, htmlOutput) { | ||
|
||
reply(htmlOutput); | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
server.start(function (err) { | ||
|
||
if (err) { | ||
throw err; | ||
} | ||
|
||
console.log('Server is listening at ' + server.info.uri); | ||
}); | ||
}); |
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,17 @@ | ||
var Path = require('path'); | ||
|
||
|
||
module.exports = { | ||
entry: Path.join(__dirname, './client.js'), | ||
resolve: { | ||
extensions: ['', '.js', '.jsx'] | ||
}, | ||
output: { | ||
filename: Path.join(__dirname, './assets/client.js') | ||
}, | ||
module: { | ||
loaders: [ | ||
{ test: /\.jsx$/, loader: 'jsx-loader' } | ||
] | ||
} | ||
}; |
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,39 @@ | ||
var Hapi = require('hapi'); | ||
var Vision = require('vision'); | ||
var HapiReactViews = require('../..'); | ||
|
||
|
||
var server = new Hapi.Server(); | ||
server.connection(); | ||
server.register(Vision, function (err) { | ||
|
||
if (err) { | ||
console.log('Failed to load vision.'); | ||
} | ||
|
||
server.views({ | ||
engines: { | ||
jsx: HapiReactViews | ||
}, | ||
relativeTo: __dirname, | ||
path: 'views' | ||
}); | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/', | ||
handler: function (request, reply) { | ||
|
||
reply.view('home'); | ||
} | ||
}); | ||
|
||
server.start(function (err) { | ||
|
||
if (err) { | ||
throw err; | ||
} | ||
|
||
console.log('Server is listening at ' + server.info.uri); | ||
}); | ||
}); |
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,21 @@ | ||
var React = require('react'); | ||
|
||
|
||
var Component = React.createClass({ | ||
render: function () { | ||
|
||
return ( | ||
<html> | ||
<head> | ||
<title>{this.props.title}</title> | ||
</head> | ||
<body> | ||
<h1>Activate the plot device.</h1> | ||
</body> | ||
</html> | ||
); | ||
} | ||
}); | ||
|
||
|
||
module.exports = Component; |
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