Skip to content

Commit 6dc5a3e

Browse files
committed
Merge pull request #198 from shakacode/react_on_rails_v2
React on rails v2
2 parents 2f8cf33 + 5347c83 commit 6dc5a3e

19 files changed

+53
-41
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ gem "sdoc", group: :doc
3737
# Use Rails Html Sanitizer for HTML sanitization
3838
gem "rails-html-sanitizer"
3939

40-
gem "react_on_rails"
40+
gem "react_on_rails", "2.0.0.rc.4"
4141

4242
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
4343
gem "therubyracer"

Gemfile.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,11 @@ GEM
201201
rainbow (2.0.0)
202202
rake (10.4.2)
203203
rdoc (4.2.0)
204-
react_on_rails (1.2.0)
204+
react_on_rails (2.0.0.rc.4)
205205
connection_pool
206206
execjs (~> 2.5)
207207
rails (>= 3.2)
208+
rainbow (~> 2.0)
208209
ref (2.0.0)
209210
rest-client (1.8.0)
210211
http-cookie (>= 1.0.2, < 2.0)
@@ -346,7 +347,7 @@ DEPENDENCIES
346347
rails-html-sanitizer
347348
rails_12factor
348349
rainbow
349-
react_on_rails
350+
react_on_rails (= 2.0.0.rc.4)
350351
rspec-rails
351352
rspec-retry
352353
rubocop
@@ -364,4 +365,4 @@ DEPENDENCIES
364365
web-console
365366

366367
BUNDLED WITH
367-
1.10.6
368+
1.11.2

app/assets/javascripts/application_dev.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,4 @@
1717
// This one depends on jQuery
1818
//= require turbolinks
1919

20-
// This will soon be removed as it will be in vendor-bundle with react_on_rails 2.0
21-
//= require react_on_rails
22-
2320
//= require rails_startup

app/controllers/pages_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def index
77
# app/views/pages/index.html.erb:20
88
#
99
# <%= react_component('App', render(template: "/comments/index.json.jbuilder"),
10-
# generator_function: true, prerender: true) %>
10+
# prerender: true) %>
1111
#
1212
#
1313
# NOTE: this could be an alternate syntax if you wanted to pass comments as a variable to a partial

app/views/pages/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
<%= render "header" %>
44

55
<%= react_component('RouterApp', render(template: "/comments/index.json.jbuilder"),
6-
generator_function: true, prerender: true, raise_on_prerender_error: true) %>
6+
prerender: true, raise_on_prerender_error: true) %>

app/views/pages/no_router.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
<%= render "header" %>
44

55
<%= react_component('App', render(template: "/comments/index.json.jbuilder"),
6-
generator_function: true, prerender: false) %>
6+
prerender: false) %>

app/views/pages/simple.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
</ul>
1010
<hr/>
1111

12-
<%= react_component('SimpleCommentScreen', {}, generator_function: false, prerender: false) %>
12+
<%= react_component('SimpleCommentScreen', {}, prerender: false) %>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import App from './ClientApp';
22
import RouterApp from './ClientRouterApp';
33
import SimpleCommentScreen from '../components/SimpleCommentScreen/SimpleCommentScreen';
4+
import ReactOnRails from 'react-on-rails';
45

5-
window.App = App;
6-
window.RouterApp = RouterApp;
7-
window.SimpleCommentScreen = SimpleCommentScreen;
6+
ReactOnRails.register(
7+
{
8+
App,
9+
RouterApp,
10+
SimpleCommentScreen,
11+
}
12+
);

client/app/bundles/comments/startup/serverGlobals.jsx

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Example of React + Redux
2+
import App from './ServerApp';
3+
import RouterApp from './ServerRouterApp';
4+
import ReactOnRails from 'react-on-rails';
5+
6+
ReactOnRails.register(
7+
{
8+
App,
9+
RouterApp,
10+
}
11+
);

client/index.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ html
1111
script(src="vendor-bundle.js")
1212
script(src="app-bundle.js")
1313
script.
14-
ReactDOM.render(RouterApp(!{props}), document.getElementById('app'));
14+
ReactOnRails.render("RouterApp", !{props}, 'app');

client/npm-shrinkwrap.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"react-addons-pure-render-mixin": "^0.14.3",
7070
"react-bootstrap": "^0.28.1",
7171
"react-dom": "^0.14.3",
72+
"react-on-rails": "^2.0.0-rc.4",
7273
"react-redux": "^4.0.0",
7374
"react-router": "^2.0.0-rc4",
7475
"redux": "^3.0.4",

client/webpack.client.base.config.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ module.exports = {
1717
vendor: [
1818
'babel-polyfill',
1919
'jquery',
20-
'react',
21-
'react-dom',
2220
],
2321

2422
// This will contain the app entry points defined by webpack.hot.config and webpack.rails.config
2523
app: [
26-
'./app/bundles/comments/startup/clientGlobals',
24+
'./app/bundles/comments/startup/clientRegistration',
2725
],
2826
},
2927
resolve: {
3028
extensions: ['', '.js', '.jsx'],
3129
alias: {
3230
libs: path.join(process.cwd(), 'app', 'libs'),
31+
react: path.resolve('./node_modules/react'),
32+
'react-dom': path.resolve('./node_modules/react-dom'),
3333
},
3434
},
3535
plugins: [
@@ -59,10 +59,6 @@ module.exports = {
5959
{ test: /\.(ttf|eot)$/, loader: 'file' },
6060
{ test: /\.(jpe?g|png|gif|svg|ico)$/, loader: 'url?limit=10000' },
6161

62-
// React is necessary for the client rendering
63-
{ test: require.resolve('react'), loader: 'expose?React' },
64-
{ test: require.resolve('react-dom'), loader: 'expose?ReactDOM' },
65-
{ test: require.resolve('jquery-ujs'), loader: 'imports?jQuery=jquery' },
6662
{ test: require.resolve('jquery'), loader: 'expose?jQuery' },
6763
{ test: require.resolve('jquery'), loader: 'expose?$' },
6864

client/webpack.client.rails.build.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ config.entry.vendor.unshift(
2727
// See webpack.common.config for adding modules common to both the webpack dev server and rails
2828

2929
config.module.loaders.push(
30-
{ test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
30+
{
31+
test: /\.jsx?$/,
32+
loader: 'babel-loader',
33+
exclude: /node_modules/,
34+
},
3135
{
3236
test: /\.css$/,
3337
loader: ExtractTextPlugin.extract(
@@ -49,6 +53,10 @@ config.module.loaders.push(
4953
{
5054
test: require.resolve('react'),
5155
loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham',
56+
},
57+
{
58+
test: require.resolve('jquery-ujs'),
59+
loader: 'imports?jQuery=jquery',
5260
}
5361
);
5462

client/webpack.client.rails.hot.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ config.module.loaders.push(
6767
'sass',
6868
'sass-resources',
6969
],
70+
},
71+
{
72+
test: require.resolve('jquery-ujs'),
73+
loader: 'imports?jQuery=jquery',
7074
}
7175
);
7276

client/webpack.server.rails.build.config.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ module.exports = {
1111
// the project dir
1212
context: __dirname,
1313
entry: [
14-
'react',
15-
'react-dom/server',
16-
'./app/bundles/comments/startup/serverGlobals',
14+
'babel-polyfill',
15+
'./app/bundles/comments/startup/serverRegistration',
1716
],
1817
output: {
1918
filename: 'server-bundle.js',
@@ -49,10 +48,6 @@ module.exports = {
4948
'sass-resources',
5049
],
5150
},
52-
53-
// React is necessary for the client rendering:
54-
{ test: require.resolve('react'), loader: 'expose?React' },
55-
{ test: require.resolve('react-dom/server'), loader: 'expose?ReactDOMServer' },
5651
],
5752
},
5853

config/initializers/react_on_rails.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
# Below options can be overriden by passing to the helper method.
1010
config.prerender = true # default is false
11-
config.generator_function = true # default is false, meaning that you expose ReactComponents directly
1211
config.trace = Rails.env.development? # default is true for development, off otherwise
1312

1413
# For server rendering. This can be set to false so that server side messages are discarded.

docs/jbuilder.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ There's a bunch of gotchas with using [Jbuilder](https://github.com/rails/jbuild
33

44
```erb
55
<%= react_component('App', render(template: "/comments/index.json.jbuilder"),
6-
generator_function: true, prerender: true) %>
6+
prerender: true) %>
77
```
88

99
However, if you try to set the value of the JSON string inside of the controller, then you will run into several issues with rendering the Jbuilder template from the controller. See the notes in this the example code for app/controllers/pages_controller.rb.

0 commit comments

Comments
 (0)