react_on_rails 6.1.2 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -3
- data/KUDOS.md +13 -0
- data/PROJECTS.md +8 -1
- data/README.md +11 -6
- data/docs/additional-reading/heroku-deployment.md +1 -1
- data/docs/additional-reading/hot-reloading-rails-development.md +1 -1
- data/docs/additional-reading/rspec-configuration.md +1 -1
- data/docs/additional-reading/turbolinks.md +5 -0
- data/docs/basics/installation-overview.md +2 -2
- data/lib/generators/react_on_rails/base_generator.rb +5 -5
- data/lib/generators/react_on_rails/react_no_redux_generator.rb +1 -1
- data/lib/generators/react_on_rails/react_with_redux_generator.rb +1 -2
- data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorld.jsx.tt +29 -0
- data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +3 -10
- data/lib/generators/react_on_rails/templates/base/base/package.json.tt +1 -0
- data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/{HelloWorld.jsx → HelloWorldContainer.jsx} +4 -6
- data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt +2 -2
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx +7 -7
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx +2 -12
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx +13 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx +12 -16
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt +7 -11
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +6 -30
- data/lib/react_on_rails/version.rb +1 -1
- data/package.json +1 -1
- data/yarn.lock +4254 -0
- metadata +6 -6
- data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt +0 -42
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +0 -42
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 927cff08d14b0f5875a696442e239299c6c5ef44
|
4
|
+
data.tar.gz: ed6c65a5ae8e5bb967642f93b5d28f99545f6102
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ccfae9da543407ff18f1455510b3520836f8e940efb74828f0a91a9e57c4b79ae6c1a083cb293c31d050b07b94753d10cc7eaea37e47ec808593dad6b5dd1b8
|
7
|
+
data.tar.gz: 19f01977f909f9e51bc0dc9a1c35ec138c877c33611ded1af59fdb9cb20b293a24803f25b851ac64b83e549db30980dbf42fce4021e7b818a678c80486d680d5
|
data/CHANGELOG.md
CHANGED
@@ -4,14 +4,20 @@ All notable changes to this project will be documented in this file. Items under
|
|
4
4
|
Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
|
+
|
8
|
+
## [6.2.0] - 2016-11-19
|
9
|
+
##### Changed
|
10
|
+
- Updated the generator templates to reflect current best practices, especially for the redux version. [#584](https://github.com/shakacode/react_on_rails/pull/584) by [nostophilia](https://github.com/nostophilia).
|
11
|
+
|
12
|
+
## [6.1.2] - 2016-10-24
|
7
13
|
##### Fixed
|
8
14
|
- Added compatibility with older manifest.yml files produced by Rails 3 Sprockets when symlinking digested assets during precompilation [#566](https://github.com/shakacode/react_on_rails/pull/566) by [etripier](https://github.com/etripier).
|
9
15
|
|
10
|
-
## [6.1.1] 2016-09-09
|
16
|
+
## [6.1.1] - 2016-09-09
|
11
17
|
##### Fixed
|
12
18
|
- React on Rails was incorrectly failing to create symlinks when a file existed in the location for the new symlink. [#491](https://github.com/shakacode/react_on_rails/pull/541) by [robwise ](https://github.com/robwise) and [justin808](https://github.com/justin808).
|
13
19
|
|
14
|
-
## [6.1.0] 2016-08-21
|
20
|
+
## [6.1.0] - 2016-08-21
|
15
21
|
|
16
22
|
##### Added
|
17
23
|
- Node option for installer added as alternative for server rendering [#469](https://github.com/shakacode/react_on_rails/pull/469) by [jbhatab](https://github.com/jbhatab).
|
@@ -372,7 +378,9 @@ Best done with Object destructing:
|
|
372
378
|
##### Fixed
|
373
379
|
- Fix several generator related issues.
|
374
380
|
|
375
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.
|
381
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.2.0...master
|
382
|
+
[6.2.0]: https://github.com/shakacode/react_on_rails/compare/6.1.2...6.2.0
|
383
|
+
[6.1.2]: https://github.com/shakacode/react_on_rails/compare/6.1.1...6.1.2
|
376
384
|
[6.1.1]: https://github.com/shakacode/react_on_rails/compare/6.1.0...6.1.1
|
377
385
|
[6.1.0]: https://github.com/shakacode/react_on_rails/compare/6.0.5...6.1.0
|
378
386
|
[6.0.5]: https://github.com/shakacode/react_on_rails/compare/6.0.4...6.0.5
|
data/KUDOS.md
CHANGED
@@ -25,3 +25,16 @@ https://twitter.com/ollieglass/status/713372606804729856
|
|
25
25
|
![2016-06-15_08-57-25](https://cloud.githubusercontent.com/assets/1118459/16093324/33077310-32d7-11e6-88f3-69aa73bd7d9f.png)
|
26
26
|
|
27
27
|
![2016-09-11_17-55-46](https://cloud.githubusercontent.com/assets/1118459/18424209/0c8bdade-7849-11e6-96a7-3b58b26308ce.png)
|
28
|
+
|
29
|
+
### October 29, 2016 by Email
|
30
|
+
![2016-10-29_17-10-25](https://cloud.githubusercontent.com/assets/1118459/20163712/72307a82-a6b3-11e6-9c46-aee526192b23.png)
|
31
|
+
|
32
|
+
### November 6, 2016
|
33
|
+
https://github.com/shakacode/react_on_rails/pull/591#issuecomment-258685925
|
34
|
+
![2016-11-15_08-36-29](https://cloud.githubusercontent.com/assets/1118459/20318599/ec4882b0-ab0e-11e6-83e2-7f398e2cdf5b.png)
|
35
|
+
|
36
|
+
### November 9, 2016, in our Slack Room for ShakaCode
|
37
|
+
![2016-11-09_19-28-32](https://cloud.githubusercontent.com/assets/1118459/20163679/405229ca-a6b3-11e6-8dff-6dc3f59bf341.png)
|
38
|
+
|
39
|
+
### November 15, 2016
|
40
|
+
![2016-11-15_18-15-31](https://cloud.githubusercontent.com/assets/1118459/20334680/23eaab0c-ab60-11e6-8830-8528c2f829a3.png)
|
data/PROJECTS.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
*Please add your project to this list.*
|
4
4
|
|
5
5
|
## Commercial Products Live
|
6
|
-
* **[Friends and Guests](https://www.friendsandguests.com/
|
6
|
+
* **[Friends and Guests](https://www.friendsandguests.com/)**, the signature product of [ShakaCode](http://www.shakacode.com), which is a "Network Connecting Hosts and Guests".
|
7
7
|
* **[Blink Inc](https://www.blinkinc.com)**: Website and more built by [ShakaCode](http://www.shakacode.com).
|
8
8
|
* **[Madrone Analytics](http://madroneco.com/)**: The original client of [ShakaCode](http://www.shakacode.com) that led to the development of React on Rails, as described in [Fast Rich Client Rails Development With Webpack and the ES6 Transpiler](http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/).
|
9
9
|
* **[Deliveroo](https://deliveroo.co.uk/)**: The leading food delivery site in Europe has gone live with React on Rails, with multi-lingual JavaScript support!
|
@@ -27,3 +27,10 @@
|
|
27
27
|
## Demos and Tutorials
|
28
28
|
* [reactrails.com](http://www.reactrails.com), source code [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/)
|
29
29
|
* [Relay Rails Blog](https://github.com/gauravtiwari/relay-rails-blog): Tutorial to learn Relay with Rails.
|
30
|
+
|
31
|
+
--------
|
32
|
+
|
33
|
+
## Projects Based on React on Rails
|
34
|
+
|
35
|
+
* [github.com/Limenius/symfony-react-sandbox](https://github.com/Limenius/symfony-react-sandbox)
|
36
|
+
* [github.com/tswayne/react-helper](https://github.com/tswayne/react-helper)
|
data/README.md
CHANGED
@@ -12,19 +12,23 @@ Your support keeps this project going.
|
|
12
12
|
|
13
13
|
(Want to become a contributor? [Contact us](mailto:contact@shakacode.com) for an Slack team invite! Also, see ["easy" issues](https://github.com/shakacode/react_on_rails/labels/easy) and [issues for the full tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/issues?q=is%3Aissue+is%3Aopen+label%3Aeasy).)
|
14
14
|
|
15
|
-
# Articles
|
15
|
+
# Articles, Videos, and Podcasts
|
16
|
+
|
17
|
+
### Articles
|
16
18
|
* [React on Rails, 2000+ 🌟 Stars](https://medium.com/shakacode/react-on-rails-2000-stars-32ff5cfacfbf#.6gmfb2gpy)
|
17
19
|
* [The React on Rails Doctrine](https://medium.com/@railsonmaui/the-react-on-rails-doctrine-3c59a778c724)
|
18
20
|
|
19
|
-
# Videos
|
20
|
-
|
21
21
|
### [React On Rails Tutorial Series](https://www.youtube.com/playlist?list=PL5VAKH-U1M6dj84BApfUtvBjvF-0-JfEU)
|
22
22
|
|
23
23
|
1. [History and Motivation](https://youtu.be/F4oymbUHvoY)
|
24
24
|
2. [Basic Tutorial Walkthrough](https://youtu.be/_bjScw60FBk)
|
25
25
|
3. [Code Walkthrough](https://youtu.be/McQ9UM-_ocQ)
|
26
26
|
|
27
|
+
### Podcasts
|
28
|
+
* [284 Ruby Rogues: React on Rails with Justin Gordon and Rob Wise](https://devchat.tv/ruby-rogues/284-rr-react-on-rails-with-justin-gordon-and-rob-wise)
|
29
|
+
|
27
30
|
# NEWS
|
31
|
+
* 2016-11-03: Speaking at [LA Ruby, 7pm, Thursday, November 10 in Venice, CA: "React on Rails: Why, What, and How?"](http://www.meetup.com/laruby/events/234825187/)
|
28
32
|
* 2016-08-27: We now have a [Documentation Gitbook](https://shakacode.gitbooks.io/react-on-rails/content/) for improved readability & reference.
|
29
33
|
* 2016-08-21: v6.1 ships with serveral new features and bug fixes. See the [Changelog](CHANGELOG.md).
|
30
34
|
* 2016-07-28: If you're doing server rendering, be sure to use mini\_racer! See [issues/428](https://github.com/shakacode/react_on_rails/issues/428). It's supposedly much faster than `therubyracer`.
|
@@ -85,7 +89,8 @@ We're definitely not doing that. With react_on_rails, webpack is mainly generati
|
|
85
89
|
## Getting Started
|
86
90
|
|
87
91
|
**For more detailed instructions**, see the [React on Rails Basic Tutorial](docs/tutorial.md).
|
88
|
-
|
92
|
+
|
93
|
+
1. Add the following to your Gemfile and `bundle install`.
|
89
94
|
|
90
95
|
```ruby
|
91
96
|
gem "react_on_rails", "~> 6"
|
@@ -430,7 +435,7 @@ See [ReactOnRails JavaScript API](docs/api/javascript-api.md).
|
|
430
435
|
|
431
436
|
#### Using Rails built-in CSRF protection in JavaScript
|
432
437
|
|
433
|
-
Rails has built-in protection for Cross-Site Request Forgery (CSRF), see [Rails Documentation](http://guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf). To nicely utilize this feature in JavaScript requests, React on Rails is offerring two helpers that can be used as following for POST,
|
438
|
+
Rails has built-in protection for Cross-Site Request Forgery (CSRF), see [Rails Documentation](http://guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf). To nicely utilize this feature in JavaScript requests, React on Rails is offerring two helpers that can be used as following for POST, PUT or DELETE requests:
|
434
439
|
|
435
440
|
```
|
436
441
|
import ReactOnRails from 'react-on-rails';
|
@@ -543,7 +548,7 @@ We owe much gratitude to the work of the [react-rails gem](https://github.com/re
|
|
543
548
|
|
544
549
|
# FINAL NOTES
|
545
550
|
* See [Projects](PROJECTS.md) using and [KUDOS](./KUDOS.md) for React on Rails. Please submit yours! Please edit either page or [email us](mailto:contact@shakacode.com) and we'll add your info. We also **love stars** as it helps us attract new users and contributors.
|
546
|
-
* Follow [@railsonmaui](https://twitter.com/railsonmaui) and [@shakacode](https://twitter.com/shakacode) on Twitter for updates on releases. We've also got a forum category dedicated to [react_on_rails](
|
551
|
+
* Follow [@railsonmaui](https://twitter.com/railsonmaui) and [@shakacode](https://twitter.com/shakacode) on Twitter for updates on releases. We've also got a forum category dedicated to [react_on_rails](https://forum.shakacode.com/c/rails/reactonrails).
|
547
552
|
|
548
553
|
---
|
549
554
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
The generator has created the necessary files and gems for deployment to Heroku. If you have installed manually, you will need to provide these files yourself:
|
3
3
|
|
4
4
|
+ `Procfile`: used by Heroku and Foreman to start the Puma server
|
5
|
-
+ `12factor` gem: required by Heroku
|
5
|
+
+ `12factor` gem: required by Heroku if using a version before Rails 5 (see their [README](https://github.com/heroku/rails_12factor#rails-5) for more information if upgrading from a lower version)
|
6
6
|
+ `'puma'` gem: recommended Heroku webserver
|
7
7
|
+ `config/puma.rb`: Puma webserver config file
|
8
8
|
+ `lib/tasks/assets.rake`: This rake task file is provided by the generator regardless of whether the user chose Heroku Deployment as an option. It is highlighted here because it is helpful to understand that this task is what generates your JavaScript bundles in production. Previously, users of this gem had to create a file `lib/tasks/assets.rake` to modify the Rails precompile task to deploy assets for production. However, we add this automatically in newer versions of React on Rails. If you need to customize this file, see [lib/tasks/assets.rake from React on Rails](https://github.com/shakacode/react_on_rails/blob/master/lib/tasks/assets.rake) as an example.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This document outlines the steps to setup your React On Rails Environment so that you can experience the pleasure of hot reloading of JavaScript and Sass during your Rails development work. There are 2 examples of this setup:
|
4
4
|
|
5
|
-
1. [spec/dummy](
|
5
|
+
1. [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy): Simpler setup used for integration testing this gem.
|
6
6
|
1. [shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/). Full featured setup using Twitter bootstrap.
|
7
7
|
|
8
8
|
## High Level Strategy
|
@@ -12,7 +12,7 @@ RSpec.configure do |config|
|
|
12
12
|
You can pass an RSpec metatag as an optional second parameter to this helper method if you want this helper to run on examples other than where `js: true` (default). The helper will compile webpack files at most once per test run. The helper will not compile the webpack files unless they are out of date (stale). The helper is configurable in terms of what command is used to prepare the files.
|
13
13
|
|
14
14
|
Please take note of the following:
|
15
|
-
- This utility uses your `npm_build_test_command
|
15
|
+
- This utility uses your `npm_build_test_command` to build the static generated files. This command **must** not include the `--watch` option. If you have different server and client bundle files, this command **must** create all the bundles.
|
16
16
|
- By default, the webpack processes look for the `app/assets/webpack` folders (configured as setting `webpack_generated_files` in the `config/react_on_rails.rb`. If this folder is missing, is empty, or contains files in the `config.webpack_generated_files` list with `mtime`s older than any of the files in your `client` folder, the helper will recompile your assets. You can override the location of these files inside of `config/initializers/react_on_rails.rb` by passing a filepath (relative to the root of the app) to the `generated_assets_dir` configuration option.
|
17
17
|
|
18
18
|
The following `config/react_on_rails.rb` settings **must** match your setup:
|
@@ -17,6 +17,11 @@ the JavaScript and stylesheets are cached by the browser, as they will still req
|
|
17
17
|
1. [react-router](https://github.com/ReactTraining/react-router) handles the back and forward buttons, as does TurboLinks. You *might* be able to make this work. *Please share your findings.*
|
18
18
|
1. You want to do code splitting to minimize the JavaScript loaded.
|
19
19
|
|
20
|
+
## More Information
|
21
|
+
* CSRF tokens need thorough checking with Turbolinks5. Turbolinks5 changes the head element by JavaScript (not only body) on page changes with the correct csrf meta tag, but if the JS code parsed this from head when several windows were opened, then our specs were not all passing. I didn't look details however, may be it is app code related, not library code. Anyway it may need additional check because there is CSRF helper in ReactOnRails and it need to work with Turbolinks5.
|
22
|
+
* Turbolinks5 send requests without the `Accept: */*` in the header, only exactly like `Accept: text/html` which makes Rails behave a bit specifically compared to normal and mime-parsing, which is skipped by when Rails see */*. For some more details on Rails and */* can read [Mime Type Resolution in Rails](http://blog.bigbinary.com/2010/11/23/mime-type-resolution-in-rails.html)
|
23
|
+
* If you're using multiple Webpack bundles, be sure to ensure that there are no name conflicts between JS objects or redux store paths.
|
24
|
+
|
20
25
|
### Install Checklist
|
21
26
|
1. Include turbolinks via npm as shown in the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/blob/8a6c8aa2e3b7ae5b08b0a9744fb3a63a2fe0f002/client/webpack.client.base.config.js#L22) or include the gem "turbolinks".
|
22
27
|
1. Included the proper "track" tags when you include the javascript and stylesheet:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Here's an overview of installation if you're not using the generator.
|
4
4
|
|
5
|
-
Note, the best to understand how to use ReactOnRails is to study the examples:
|
5
|
+
Note, the best way to understand how to use ReactOnRails is to study the examples:
|
6
6
|
|
7
7
|
1. [spec/dummy](../../spec/dummy): Simple, no DB example.
|
8
8
|
2. [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial): Full featured example.
|
@@ -24,7 +24,7 @@ The only requirements within this directory for basic React on Rails integration
|
|
24
24
|
1. Configure the `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [spec/dummy/config/initializers/react_on_rails.rb](../../spec/dummy/config/initializers/react_on_rails.rb) for a detailed example of configuration, including comments on the different values to configure.
|
25
25
|
1. Configure your Procfiles per the example apps. These are at the root of your Rails installation.
|
26
26
|
1. Configure `config/initializers/assets.rb` probably like [spec/dummy/config/initializers/assets.rb](../../spec/dummy/config/initializers/assets.rb). This example shows what's necessary if you're enabling the hot-reloading Rails development option.
|
27
|
-
1. Configure your top level JavaScript files for inclusion in your layout. You'll want a version that you use for static assets, and you want a file for any files in your setup that are not part of your webpack build. The reason for this is for use with hot-reloading. If you are not using hot reloading, then you only need to configure your `application.js` file to include your Webpack generated files. For more information on hot reloading, see [Hot Reloading of Assets For Rails Development](hot-reloading-rails-development.md)
|
27
|
+
1. Configure your top level JavaScript files for inclusion in your layout. You'll want a version that you use for static assets, and you want a file for any files in your setup that are not part of your webpack build. The reason for this is for use with hot-reloading. If you are not using hot reloading, then you only need to configure your `application.js` file to include your Webpack generated files. For more information on hot reloading, see [Hot Reloading of Assets For Rails Development](../additional-reading/hot-reloading-rails-development.md)
|
28
28
|
|
29
29
|
1. Configure your `lib/tasks/assets.rake` file to run webpack during asset precompilation.
|
30
30
|
1. If you are deploying to Heroku, see [heroku-deployment.md](/docs/additional-reading/heroku-deployment.md)
|
@@ -77,7 +77,7 @@ module ReactOnRails
|
|
77
77
|
Procfile.dev
|
78
78
|
app/views/hello_world/index.html.erb
|
79
79
|
package.json
|
80
|
-
client/app/bundles/HelloWorld/components/
|
80
|
+
client/app/bundles/HelloWorld/components/HelloWorld.jsx
|
81
81
|
client/package.json).each { |file| template(base_path + file + ".tt", file) }
|
82
82
|
end
|
83
83
|
|
@@ -99,11 +99,11 @@ Rails.application.config.assets.paths << Rails.root.join("app", "assets", "webpa
|
|
99
99
|
DATA
|
100
100
|
|
101
101
|
def append_to_assets_initializer
|
102
|
-
|
103
|
-
if File.exist?(
|
104
|
-
append_to_file(
|
102
|
+
assets_initializer = File.join(destination_root, "config/initializers/assets.rb")
|
103
|
+
if File.exist?(assets_initializer)
|
104
|
+
append_to_file(assets_initializer, ASSETS_RB_APPEND)
|
105
105
|
else
|
106
|
-
create_file(
|
106
|
+
create_file(assets_initializer, ASSETS_RB_APPEND)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -10,7 +10,7 @@ module ReactOnRails
|
|
10
10
|
|
11
11
|
def copy_base_files
|
12
12
|
base_path = "no_redux/base/"
|
13
|
-
file = "client/app/bundles/HelloWorld/containers/
|
13
|
+
file = "client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx"
|
14
14
|
copy_file(base_path + file, file)
|
15
15
|
end
|
16
16
|
|
@@ -14,10 +14,9 @@ module ReactOnRails
|
|
14
14
|
def copy_base_redux_files
|
15
15
|
base_path = "redux/base/"
|
16
16
|
%w(client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx
|
17
|
-
client/app/bundles/HelloWorld/containers/
|
17
|
+
client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx
|
18
18
|
client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx
|
19
19
|
client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
|
20
|
-
client/app/bundles/HelloWorld/reducers/index.jsx
|
21
20
|
client/app/bundles/HelloWorld/store/helloWorldStore.jsx).each do |file|
|
22
21
|
copy_file(base_path + file, file)
|
23
22
|
end
|
@@ -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;
|
@@ -2,6 +2,7 @@
|
|
2
2
|
{
|
3
3
|
"name": "react-webpack-rails-tutorial",
|
4
4
|
"version": "0.0.1",
|
5
|
+
"private": true,
|
5
6
|
"engines": {
|
6
7
|
"node": "5.10.0",
|
7
8
|
"npm": "3.5.0"
|
@@ -24,21 +25,13 @@
|
|
24
25
|
"babel-preset-stage-0": "^6.5.0",
|
25
26
|
"es5-shim": "^4.5.7",
|
26
27
|
"expose-loader": "^0.7.1",
|
27
|
-
<%- if options.redux? -%>
|
28
|
-
"immutable": "^3.7.6",
|
29
|
-
<%- end -%>
|
30
28
|
"imports-loader": "^0.6.5",
|
31
|
-
|
32
|
-
"
|
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",
|
36
31
|
"react-on-rails": "<%= VersionSyntaxConverter.new.rubygem_to_npm %>",
|
37
32
|
<%- if options.redux? -%>
|
38
33
|
"react-redux": "^4.4.1",
|
39
34
|
"redux": "^3.3.1",
|
40
|
-
"redux-promise": "^0.5.3",
|
41
|
-
"redux-thunk": "^2.0.1",
|
42
35
|
<%- end -%>
|
43
36
|
"webpack": "^1.12.14"
|
44
37
|
},
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import React, { PropTypes } from 'react';
|
2
|
-
import
|
2
|
+
import HelloWorld from '../components/HelloWorld';
|
3
3
|
|
4
4
|
// Simple example of a React "smart" component
|
5
|
-
export default class
|
5
|
+
export default class HelloWorldContainer extends React.Component {
|
6
6
|
static propTypes = {
|
7
7
|
name: PropTypes.string.isRequired, // this is passed from the Rails view
|
8
8
|
};
|
@@ -15,14 +15,12 @@ export default class HelloWorld extends React.Component {
|
|
15
15
|
this.state = { name: this.props.name };
|
16
16
|
}
|
17
17
|
|
18
|
-
updateName(name) {
|
19
|
-
this.setState({ name });
|
20
|
-
}
|
18
|
+
updateName = (name) => { this.setState({ name }); };
|
21
19
|
|
22
20
|
render() {
|
23
21
|
return (
|
24
22
|
<div>
|
25
|
-
<
|
23
|
+
<HelloWorld name={this.state.name} updateName={this.updateName} />
|
26
24
|
</div>
|
27
25
|
);
|
28
26
|
}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import ReactOnRails from 'react-on-rails';
|
3
3
|
|
4
|
-
import
|
4
|
+
import HelloWorldContainer from '../containers/HelloWorldContainer';
|
5
5
|
|
6
6
|
const HelloWorldApp = (props) => (
|
7
|
-
<
|
7
|
+
<HelloWorldContainer {...props} />
|
8
8
|
);
|
9
9
|
|
10
10
|
// This is how react_on_rails can see the HelloWorldApp in the browser.
|
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
}
|
3
|
+
import { HELLO_WORLD_NAME_UPDATE } from '../constants/helloWorldConstants';
|
4
|
+
|
5
|
+
export const updateName = (text) => ({
|
6
|
+
type: HELLO_WORLD_NAME_UPDATE,
|
7
|
+
text,
|
8
|
+
});
|
@@ -1,13 +1,3 @@
|
|
1
|
-
|
2
|
-
// Allows us to set up constants in a slightly more concise syntax. See:
|
3
|
-
// client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx
|
4
|
-
import mirrorCreator from 'mirror-creator';
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
5
2
|
|
6
|
-
const
|
7
|
-
'HELLO_WORLD_NAME_UPDATE',
|
8
|
-
]);
|
9
|
-
|
10
|
-
// actionTypes = {HELLO_WORLD_NAME_UPDATE: "HELLO_WORLD_NAME_UPDATE"}
|
11
|
-
// Notice how we don't have to duplicate HELLO_WORLD_NAME_UPDATE twice
|
12
|
-
// thanks to mirror-creator.
|
13
|
-
export default actionTypes;
|
3
|
+
export const HELLO_WORLD_NAME_UPDATE = 'HELLO_WORLD_NAME_UPDATE';
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// Simple example of a React "smart" component
|
2
|
+
|
3
|
+
import { connect } from 'react-redux';
|
4
|
+
import HelloWorld from '../components/HelloWorld';
|
5
|
+
import * as actions from '../actions/helloWorldActionCreators';
|
6
|
+
|
7
|
+
// Which part of the Redux global state does our component want to receive as props?
|
8
|
+
const mapStateToProps = (state) => ({ name: state.name });
|
9
|
+
|
10
|
+
// Don't forget to actually use connect!
|
11
|
+
// Note that we don't export HelloWorld, but the redux "connected" version of it.
|
12
|
+
// See https://github.com/reactjs/react-redux/blob/master/docs/api.md#examples
|
13
|
+
export default connect(mapStateToProps, actions)(HelloWorld);
|
@@ -1,19 +1,15 @@
|
|
1
|
-
import
|
2
|
-
|
3
|
-
import actionTypes from '../constants/helloWorldConstants';
|
4
|
-
|
5
|
-
export const $$initialState = Immutable.fromJS({
|
6
|
-
name: '', // this is the default state that would be used if one were not passed into the store
|
7
|
-
});
|
8
|
-
|
9
|
-
export default function helloWorldReducer($$state = $$initialState, action) {
|
10
|
-
const { type, name } = action;
|
11
|
-
|
12
|
-
switch (type) {
|
13
|
-
case actionTypes.HELLO_WORLD_NAME_UPDATE:
|
14
|
-
return $$state.set('name', name);
|
1
|
+
import { combineReducers } from 'redux';
|
2
|
+
import { HELLO_WORLD_NAME_UPDATE } from '../constants/helloWorldConstants';
|
15
3
|
|
4
|
+
const name = (state = '', action) => {
|
5
|
+
switch (action.type) {
|
6
|
+
case HELLO_WORLD_NAME_UPDATE:
|
7
|
+
return action.text;
|
16
8
|
default:
|
17
|
-
return
|
9
|
+
return state;
|
18
10
|
}
|
19
|
-
}
|
11
|
+
};
|
12
|
+
|
13
|
+
const helloWorldReducer = combineReducers({ name });
|
14
|
+
|
15
|
+
export default helloWorldReducer;
|