Skip to content

Commit a488445

Browse files
committed
Merge remote-tracking branch 'shakacode/master'
2 parents 88d3370 + 546dddb commit a488445

38 files changed

+1047
-1028
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ gem "rails-html-sanitizer"
4040
# Use Unicorn as the app server
4141
gem "unicorn"
4242

43-
gem "react_on_rails", "~> 1.0.0.pre"
43+
gem "react_on_rails"
44+
4445
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
4546
gem "therubyracer"
4647

Gemfile.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ GEM
4343
ast (2.1.0)
4444
astrolabe (1.3.1)
4545
parser (~> 2.2)
46-
autoprefixer-rails (6.1.0.1)
46+
autoprefixer-rails (6.1.1)
4747
execjs
4848
json
4949
awesome_print (1.6.1)
5050
binding_of_caller (0.7.2)
5151
debug_inspector (>= 0.0.1)
52-
bootstrap-sass (3.3.5.1)
53-
autoprefixer-rails (>= 5.0.0.1)
54-
sass (>= 3.3.0)
52+
bootstrap-sass (3.3.6)
53+
autoprefixer-rails (>= 5.2.1)
54+
sass (>= 3.3.4)
5555
brakeman (3.1.2)
5656
erubis (~> 2.6)
5757
fastercsv (~> 1.5)
@@ -139,12 +139,12 @@ GEM
139139
mail (2.6.3)
140140
mime-types (>= 1.16, < 3)
141141
method_source (0.8.2)
142-
mime-types (2.6.2)
142+
mime-types (2.99)
143143
mini_portile (0.6.2)
144-
minitest (5.8.2)
144+
minitest (5.8.3)
145145
multi_json (1.11.2)
146146
netrc (0.11.0)
147-
nokogiri (1.6.6.3)
147+
nokogiri (1.6.6.4)
148148
mini_portile (~> 0.6.0)
149149
parser (2.2.3.0)
150150
ast (>= 1.1, < 3.0)
@@ -204,7 +204,7 @@ GEM
204204
raindrops (0.15.0)
205205
rake (10.4.2)
206206
rdoc (4.2.0)
207-
react_on_rails (1.0.3)
207+
react_on_rails (1.1.0)
208208
connection_pool
209209
execjs (~> 2.5)
210210
rails (>= 3.2)
@@ -213,7 +213,7 @@ GEM
213213
http-cookie (>= 1.0.2, < 2.0)
214214
mime-types (>= 1.16, < 3.0)
215215
netrc (~> 0.7)
216-
rspec-core (3.4.0)
216+
rspec-core (3.4.1)
217217
rspec-support (~> 3.4.0)
218218
rspec-expectations (3.4.0)
219219
diff-lcs (>= 1.2.0, < 2.0)
@@ -229,7 +229,7 @@ GEM
229229
rspec-expectations (~> 3.4.0)
230230
rspec-mocks (~> 3.4.0)
231231
rspec-support (~> 3.4.0)
232-
rspec-support (3.4.0)
232+
rspec-support (3.4.1)
233233
rubocop (0.35.1)
234234
astrolabe (~> 1.3)
235235
parser (>= 2.2.3.0, < 3.0)
@@ -255,7 +255,7 @@ GEM
255255
sprockets (>= 2.8, < 4.0)
256256
sprockets-rails (>= 2.0, < 4.0)
257257
tilt (>= 1.1, < 3)
258-
scss_lint (0.42.2)
258+
scss_lint (0.43.0)
259259
rainbow (~> 2.0)
260260
sass (~> 3.4.15)
261261
sdoc (0.4.1)
@@ -276,10 +276,10 @@ GEM
276276
temple (~> 0.7.3)
277277
tilt (>= 1.3.3, < 2.1)
278278
slop (3.6.0)
279-
spring (1.4.3)
279+
spring (1.4.4)
280280
spring-commands-rspec (1.0.4)
281281
spring (>= 0.9.1)
282-
sprockets (3.4.0)
282+
sprockets (3.4.1)
283283
rack (> 1, < 3)
284284
sprockets-rails (2.3.3)
285285
actionpack (>= 3.0)
@@ -307,7 +307,7 @@ GEM
307307
unf (0.1.4)
308308
unf_ext
309309
unf_ext (0.0.7.1)
310-
unicorn (5.0.0)
310+
unicorn (5.0.1)
311311
kgio (~> 2.6)
312312
rack
313313
raindrops (~> 0.7)
@@ -350,7 +350,7 @@ DEPENDENCIES
350350
rails (~> 4.2)
351351
rails-html-sanitizer
352352
rails_12factor
353-
react_on_rails (~> 1.0.0.pre)
353+
react_on_rails
354354
rspec-rails
355355
rubocop
356356
ruby-lint

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Coverage Status](https://coveralls.io/repos/shakacode/react-webpack-rails-tutorial/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react-webpack-rails-tutorial?branch=master)
44
[![Dependency Status](https://gemnasium.com/shakacode/react-webpack-rails-tutorial.svg)](https://gemnasium.com/shakacode/react-webpack-rails-tutorial)
55
# React, Redux, React-Bootstrap, ES7, Webpack Rails
6-
## Servering Rendering via the react_on_rails gem
6+
## Server Rendering via the react_on_rails gem
77

88
By Justin Gordon and the Shaka Code Team, http://www.shakacode.com
99

app/controllers/pages_controller.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class PagesController < ApplicationController
2-
def index
3-
@comments = Comment.all
2+
before_action :set_comments
43

4+
def index
55
# NOTE: The below notes apply if you want to set the value of the props in the controller, as
66
# compared to he view. However, it's more convenient to use Jbuilder from the view. See
77
# app/views/pages/index.html.erb:20
@@ -22,6 +22,16 @@ def index
2222
# end
2323
end
2424

25+
# Declaring no_router and simple to indicate we have views for them
26+
def no_router
27+
end
28+
2529
def simple
2630
end
31+
32+
private
33+
34+
def set_comments
35+
@comments = Comment.all
36+
end
2737
end

app/views/layouts/application.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
<!-- Collect the nav links, forms, and other content for toggling -->
2323
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
2424
<ul class="nav navbar-nav">
25-
<li class="active"><%= link_to "React Demo", root_path %></li>
25+
<li class="active"><%= link_to "React Router Demo", root_path %></li>
26+
<li><%= link_to "React Demo", no_router_path %></li>
2627
<li><%= link_to "Simple React", simple_path %></li>
2728
<li><%= link_to "Classic Rails", comments_path %></li>
2829
<li><%= link_to "www.shakacode.com", "http://www.shakacode.com" %></li>

app/views/pages/_header.html.erb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<p>Current Commit:
2+
<%= link_to git_commit_sha_short,
3+
"https://github.com/shakacode/react-webpack-rails-tutorial/commit/#{git_commit_sha}",
4+
id: "git-commit-sha" %>
5+
</p>
6+
<ul>
7+
<li>
8+
If this work interests you and you're a developer or designer looking for full or part-time remote work: please
9+
<%= link_to "click here",
10+
"http://forum.shakacode.com/t/railsonmaui-is-hiring-and-partnering-part-time-remote-is-ok/156/3" %>
11+
and
12+
<%= link_to "here",
13+
"http://forum.shakacode.com/t/railsonmaui-is-hiring-and-partnering-part-time-remote-is-ok/156/2" %>.
14+
</li>
15+
<li>
16+
Please see the
17+
<%= link_to "github.com/shakacode/react-webpack-rails-tutorial/README.md",
18+
"https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/README.md" %>
19+
for details of how this example site was built.
20+
</li>
21+
</ul>
22+
<hr/>
23+

app/views/pages/index.html.erb

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
1-
<h2>Using React (Server rendering) + Redux + Rails Backend (using the
1+
<h2>Using React (Server rendering) + Redux + React Router + Rails Backend (using the
22
<a href="https://github.com/shakacode/react_on_rails">react_on_rails gem</a>)</h2>
3-
<p>Current Commit:
4-
<%= link_to git_commit_sha_short,
5-
"https://github.com/shakacode/react-webpack-rails-tutorial/commit/#{git_commit_sha}",
6-
id: "git-commit-sha" %>
7-
</p>
8-
<ul>
9-
<li>
10-
If this work interests you and you're a developer or designer looking for full or part-time remote work: please
11-
<%= link_to "click here",
12-
"http://forum.shakacode.com/t/railsonmaui-is-hiring-and-partnering-part-time-remote-is-ok/156/3" %>
13-
and
14-
<%= link_to "here",
15-
"http://forum.shakacode.com/t/railsonmaui-is-hiring-and-partnering-part-time-remote-is-ok/156/2" %>.
16-
</li>
17-
<li>
18-
Please see the
19-
<%= link_to "github.com/shakacode/react-webpack-rails-tutorial/README.md",
20-
"https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/README.md" %>
21-
for details of how this example site was built.
22-
</li>
23-
</ul>
24-
<hr/>
3+
<%= render "header" %>
254

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

app/views/pages/no_router.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<h2>Using React (Server rendering) + Redux + Rails Backend (using the
2+
<a href="https://github.com/shakacode/react_on_rails">react_on_rails gem</a>)</h2>
3+
<%= render "header" %>
4+
5+
<%= react_component('App', render(template: "/comments/index.json.jbuilder"),
6+
generator_function: true, prerender: true) %>

client/app/actions/commentsActionCreators.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import commentsManager from '../utils/commentsManager';
22
import * as actionTypes from '../constants/commentsConstants';
33

4-
export function incrementAjaxCounter() {
4+
export function setIsFetching() {
55
return {
6-
type: actionTypes.INCREMENT_AJAX_COUNTER,
6+
type: actionTypes.SET_IS_FETCHING,
77
};
88
}
99

10-
export function decrementAjaxCounter() {
10+
export function setIsSaving() {
1111
return {
12-
type: actionTypes.DECREMENT_AJAX_COUNTER,
12+
type: actionTypes.SET_IS_SAVING,
1313
};
1414
}
1515

@@ -43,6 +43,7 @@ export function submitCommentFailure(error) {
4343

4444
export function fetchComments() {
4545
return dispatch => {
46+
dispatch(setIsFetching());
4647
return (
4748
commentsManager
4849
.fetchComments()
@@ -54,13 +55,12 @@ export function fetchComments() {
5455

5556
export function submitComment(comment) {
5657
return dispatch => {
57-
dispatch(incrementAjaxCounter());
58+
dispatch(setIsSaving());
5859
return (
5960
commentsManager
6061
.submitComment(comment)
6162
.then(res => dispatch(submitCommentSuccess(res.data)))
6263
.catch(res => dispatch(submitCommentFailure(res.data)))
63-
.then(() => dispatch(decrementAjaxCounter()))
6464
);
6565
};
6666
}

client/app/components/CommentBox.jsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import React, { PropTypes } from 'react';
22

33
import CommentForm from './CommentForm';
44
import CommentList from './CommentList';
5-
import _ from 'lodash';
65

76
class CommentBox extends React.Component {
87
constructor(props, context) {
98
super(props, context);
109
this.state = {};
11-
12-
_.bindAll(this, '_ajaxCounter', '_isSendingAjax');
1310
}
1411

1512
static displayName = 'CommentBox';
@@ -22,15 +19,11 @@ class CommentBox extends React.Component {
2219
componentDidMount() {
2320
const { fetchComments } = this.props.actions;
2421
fetchComments();
25-
setInterval(fetchComments, this.props.pollInterval);
26-
}
27-
28-
_ajaxCounter() {
29-
return this.props.data.get('ajaxCounter');
22+
this.intervalId = setInterval(fetchComments, this.props.pollInterval);
3023
}
3124

32-
_isSendingAjax() {
33-
return this._ajaxCounter() > 0;
25+
componentWillUnmount() {
26+
clearInterval(this.intervalId);
3427
}
3528

3629
render() {
@@ -39,14 +32,14 @@ class CommentBox extends React.Component {
3932
return (
4033
<div className="commentBox container">
4134
<h2>
42-
Comments {this._isSendingAjax() && `SENDING AJAX REQUEST! Ajax Counter is ${this._ajaxCounter()}`}
35+
Comments {data.get('isFetching') && 'Loading...'}
4336
</h2>
4437
<p>
45-
Text take Github Flavored Markdown. Comments older than 24 hours are deleted.
46-
<b>Name</b> is preserved, <b>Text</b> is reset, between submits.
38+
Text take Github Flavored Markdown. Comments older than 24 hours are deleted.<br/>
39+
<b>Name</b> is preserved. <b>Text</b> is reset, between submits.
4740
</p>
4841
<CommentForm
49-
ajaxSending={this._isSendingAjax()}
42+
isSaving={data.get('isSaving')}
5043
error={data.get('submitCommentError')}
5144
actions={actions}
5245
/>

0 commit comments

Comments
 (0)