Skip to content

Commit e47256e

Browse files
author
nostophilia
committed
Revise "Hello World" Redux example
1 parent 5e5b92e commit e47256e

File tree

20 files changed

+92
-199
lines changed

20 files changed

+92
-199
lines changed

lib/generators/react_on_rails/base_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def template_base_files
7777
Procfile.dev
7878
app/views/hello_world/index.html.erb
7979
package.json
80-
client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx
80+
client/app/bundles/HelloWorld/components/HelloWorld.jsx
8181
client/package.json).each { |file| template(base_path + file + ".tt", file) }
8282
end
8383

lib/generators/react_on_rails/react_no_redux_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ReactNoReduxGenerator < Rails::Generators::Base
1010

1111
def copy_base_files
1212
base_path = "no_redux/base/"
13-
file = "client/app/bundles/HelloWorld/containers/HelloWorld.jsx"
13+
file = "client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx"
1414
copy_file(base_path + file, file)
1515
end
1616

lib/generators/react_on_rails/react_with_redux_generator.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ def create_redux_directories
1414
def copy_base_redux_files
1515
base_path = "redux/base/"
1616
%w(client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx
17-
client/app/bundles/HelloWorld/containers/HelloWorld.jsx
17+
client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx
1818
client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx
1919
client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
20-
client/app/bundles/HelloWorld/reducers/index.jsx
2120
client/app/bundles/HelloWorld/store/helloWorldStore.jsx).each do |file|
2221
copy_file(base_path + file, file)
2322
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<h1 class="alert alert-info this-works">Hello World</h1>
1+
<h1>Hello World</h1>
22
<%%= react_component("HelloWorldApp", props: @hello_world_props, prerender: false) %>
33

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { PropTypes } from 'react';
2+
3+
// Simple example of a React "dumb" component
4+
const HelloWorld = ({ name, updateName }) => (
5+
<div className="container">
6+
<h3>
7+
Hello, {name}!
8+
</h3>
9+
<hr />
10+
<form className="form-horizontal">
11+
<label htmlFor="name">
12+
Say hello to:
13+
</label>
14+
<input
15+
type="text" value={name} id="name"
16+
onChange={(e) => updateName(e.target.value)}
17+
/>
18+
</form>
19+
</div>
20+
);
21+
22+
HelloWorld.propTypes = {
23+
// If you have lots of data or action properties, you should consider grouping them by
24+
// passing two properties: "data" and "actions".
25+
updateName: PropTypes.func.isRequired,
26+
name: PropTypes.string.isRequired,
27+
};
28+
29+
export default HelloWorld;

lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt

Lines changed: 0 additions & 42 deletions
This file was deleted.

lib/generators/react_on_rails/templates/base/base/client/package.json.tt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
"name": "react-webpack-rails-tutorial",
44
"version": "0.0.1",
5+
"private": true,
56
"engines": {
67
"node": "5.10.0",
78
"npm": "3.5.0"
@@ -24,21 +25,13 @@
2425
"babel-preset-stage-0": "^6.5.0",
2526
"es5-shim": "^4.5.7",
2627
"expose-loader": "^0.7.1",
27-
<%- if options.redux? -%>
28-
"immutable": "^3.7.6",
29-
<%- end -%>
3028
"imports-loader": "^0.6.5",
31-
<%- if options.redux? -%>
32-
"mirror-creator": "1.1.0",
33-
<%- end -%>
34-
"react": "^0.14.8 || ^15.0.0",
35-
"react-dom": "^0.14.8 || ^15.0.0",
29+
"react": "^15.0.0",
30+
"react-dom": "^15.0.0",
3631
"react-on-rails": "<%= VersionSyntaxConverter.new.rubygem_to_npm %>",
3732
<%- if options.redux? -%>
3833
"react-redux": "^4.4.1",
3934
"redux": "^3.3.1",
40-
"redux-promise": "^0.5.3",
41-
"redux-thunk": "^2.0.1",
4235
<%- end -%>
4336
"webpack": "^1.12.14"
4437
},

lib/generators/react_on_rails/templates/base/base/package.json.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "react-webpack-rails-tutorial",
33
"version": "0.0.1",
4+
"private": true,
45
"engines": {
56
"node": "5.10.0",
67
"npm": "3.5.0"
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { PropTypes } from 'react';
2-
import HelloWorldWidget from '../components/HelloWorldWidget';
2+
import HelloWorld from '../components/HelloWorld';
33

44
// Simple example of a React "smart" component
5-
export default class HelloWorld extends React.Component {
5+
export default class HelloWorldContainer extends React.Component {
66
static propTypes = {
77
name: PropTypes.string.isRequired, // this is passed from the Rails view
88
};
@@ -15,14 +15,12 @@ export default class HelloWorld extends React.Component {
1515
this.state = { name: this.props.name };
1616
}
1717

18-
updateName(name) {
19-
this.setState({ name });
20-
}
18+
updateName = (name) => { this.setState({ name }); };
2119

2220
render() {
2321
return (
2422
<div>
25-
<HelloWorldWidget name={this.state.name} updateName={e => this.updateName(e)} />
23+
<HelloWorld name={this.state.name} updateName={this.updateName} />
2624
</div>
2725
);
2826
}

lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import ReactOnRails from 'react-on-rails';
33

4-
import HelloWorld from '../containers/HelloWorld';
4+
import HelloWorldContainer from '../containers/HelloWorldContainer';
55

66
const HelloWorldApp = (props) => (
7-
<HelloWorld {...props} />
7+
<HelloWorldContainer {...props} />
88
);
99

1010
// This is how react_on_rails can see the HelloWorldApp in the browser.

0 commit comments

Comments
 (0)