react_on_rails 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +19 -11
- data/app/assets/javascripts/debug_turbolinks.js +4 -0
- data/docs/additional_reading/rails_view_rendering_from_inline_javascript.md +35 -0
- data/docs/additional_reading/rspec_configuration.md +11 -1
- data/docs/additional_reading/turbolinks.md +5 -18
- data/docs/doctrine.md +1 -1
- data/lib/react_on_rails/version.rb +1 -1
- data/package.json +3 -2
- data/rakelib/run_rspec.rake +8 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b65b6529dca9ed1cf1b205cec960efe38885a17
|
4
|
+
data.tar.gz: e5d5bf65c4c63282de650747d26795f7517b4d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f9cbb2bada17276368ebae143d7a16c72c7f5fcda30f06bcbaf42049f4bf427af6e3d98f55ed651a212dfd9591f40ac37bbed52adbd2e36b869ca2f86962806
|
7
|
+
data.tar.gz: e440d984febebef5f5685f447788e83caf01cd1be2486c091a5a6ae5db6fc723a67ff40347098ae95ae5ac94f97790612107e39d35e018fa3bb8afa308af1dc2
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@ 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
|
+
##### Fixed
|
8
|
+
- Fixed regression where apps that were not using Turbolinks would not render components on page load.
|
9
|
+
|
10
|
+
##### Added
|
11
|
+
- `debug_turbolinks` helper for debugging turbolinks issues. See [turbolinks](docs/additional_reading/turbolinks.md).
|
12
|
+
- Enhanced regression testing for non-turbolinks apps. Runs all tests for dummy app with turbolinks both disabled and enabled.
|
7
13
|
|
8
14
|
## [2.1.0] - 2016-01-26
|
9
15
|
##### Added
|
data/README.md
CHANGED
@@ -2,8 +2,13 @@
|
|
2
2
|
|
3
3
|
# NEWS
|
4
4
|
|
5
|
-
* 2.1
|
5
|
+
* 2.1 has shipped on Tuesday, 2/26/2016. Please see the [Changelog](CHANGELOG.md) for details, and let us know if you see any issues! [Migration steps from 1.x](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md#migration-steps).
|
6
|
+
* Highlights:
|
7
|
+
1. Fixed a **critical** problem with TurboLinks.
|
8
|
+
2. Provides a convenient helper to ensure that JavaScript assets are compiled before running tests.
|
6
9
|
* React on Rails does not yet have *generator* support for building new apps that use CSS modules and hot reloading via the Rails server as is demonstrated in the [shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/). *We do support this, but we don't generate the code.* If you did generate a fresh app from react_on_rails and want to move to CSS Modules, then see [PR 175: Babel 6 / CSS Modules / Rails hot reloading](https://github.com/shakacode/react-webpack-rails-tutorial/pull/175). Note, while there are probably fixes after this PR was accepted, this has the majority of the changes. See [the tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/#news) for more information. Ping us if you want to help!
|
10
|
+
* [ShakaCode](http://www.shakacode.com) is doing Skype plus Slack/Github based coaching for "React on Rails". [Click here](http://www.shakacode.com/work/index.html) for more information.
|
11
|
+
* Be sure to read our new article [The React on Rails Doctrine](http://www.shakacode.com/2016/01/26/the-react-on-rails-doctrine.html).
|
7
12
|
|
8
13
|
# React on Rails
|
9
14
|
|
@@ -13,7 +18,7 @@ React on Rails integrates Facebook's [React](https://github.com/facebook/react)
|
|
13
18
|
|
14
19
|
Be sure to see:
|
15
20
|
|
16
|
-
* [The React on Rails Doctrine](
|
21
|
+
* [The React on Rails Doctrine](http://www.shakacode.com/2016/01/26/the-react-on-rails-doctrine.html)
|
17
22
|
* [React Webpack Rails Tutorial Code](https://github.com/shakacode/react-webpack-rails-tutorial) along with the live example at [www.reactrails.com](http://www.reactrails.com).
|
18
23
|
|
19
24
|
## Including your React Component in your Rails Views
|
@@ -166,15 +171,15 @@ Now the server will interpret your JavaScript using [ExecJS](https://github.com/
|
|
166
171
|
|
167
172
|
Note that **server-rendering requires globally exposing your components by setting them to `global`, not `window`** (as is the case with client-rendering). If using the generator, you can pass the `--server-rendering` option to configure your application for server-side rendering.
|
168
173
|
|
169
|
-
In the following screenshot you can see the 3 parts of
|
174
|
+
In the following screenshot you can see the 3 parts of React on Rails rendering:
|
170
175
|
|
171
|
-
1.
|
172
|
-
2. The wrapper div `<div id="HelloWorld-react-component-0">`
|
173
|
-
3. Additional JavaScript to console log any messages, such as server rendering errors.
|
176
|
+
1. A hidden HTML div that contains the properties of the React component, such as the registered name and any props. A JavaScript function runs after the page loads to convert take this data and build initialize React components.
|
177
|
+
2. The wrapper div `<div id="HelloWorld-react-component-0">` specifies the div where to place the React rendering. It encloses the server-rendered HTML for the React component
|
178
|
+
3. Additional JavaScript is placed to console log any messages, such as server rendering errors. Note, these server side logs can be configured to only be sent to the server logs.
|
174
179
|
|
175
|
-
**Note**: If server rendering is not used (prerender: false), then the major difference is that the HTML rendered
|
180
|
+
**Note**: If server rendering is not used (prerender: false), then the major difference is that the HTML rendered for the React component only contains the outer div: `<div id="HelloWorld-react-component-0"/>`. The first specification of the React component is just the same.
|
176
181
|
|
177
|
-
![Comparison of a normal React Component with its server-rendered version](https://cloud.githubusercontent.com/assets/1118459/
|
182
|
+
![Comparison of a normal React Component with its server-rendered version](https://cloud.githubusercontent.com/assets/1118459/12607542/a959d5c8-c48a-11e5-8187-2433d543ccaa.png)
|
178
183
|
|
179
184
|
### Building the Bundles
|
180
185
|
Each time you change your client code, you will need to re-generate the bundles (the webpack-created JavaScript files included in application.js). The included Foreman `Procfile.dev` will take care of this for you by watching your JavaScript code files for changes. Simply run `foreman start -f Procfile.dev`.
|
@@ -359,7 +364,7 @@ If you are using [react-rails](https://github.com/reactjs/react-rails) in your p
|
|
359
364
|
|
360
365
|
- Remove the 'react-rails' gem from your Gemfile.
|
361
366
|
|
362
|
-
- Remove the generated generated lines for react-rails in your application.js file.
|
367
|
+
- Remove the generated generated lines for react-rails in your application.js file.
|
363
368
|
|
364
369
|
```
|
365
370
|
//= require react
|
@@ -372,6 +377,7 @@ If you are using [react-rails](https://github.com/reactjs/react-rails) in your p
|
|
372
377
|
Note: If you have components from react-rails you want to use, then you will need to port them into react_on_rails which uses webpack instead of the asset pipeline.
|
373
378
|
|
374
379
|
## Additional Reading
|
380
|
+
+ [The React on Rails Doctrine](http://www.shakacode.com/2016/01/26/the-react-on-rails-doctrine.html)
|
375
381
|
+ [Generated Client Code](docs/additional_reading/generated_client_code.md)
|
376
382
|
+ [Heroku Deployment](docs/additional_reading/heroku_deployment.md)
|
377
383
|
+ [Manual Installation](docs/additional_reading/manual_installation.md)
|
@@ -380,14 +386,16 @@ Note: If you have components from react-rails you want to use, then you will nee
|
|
380
386
|
+ [React Router](docs/additional_reading/react_router.md)
|
381
387
|
+ [RSpec Configuration](docs/additional_reading/rspec_configuration.md)
|
382
388
|
+ [Server Rendering Tips](docs/additional_reading/server_rendering_tips.md)
|
389
|
+
+ [Rails View Rendering from Inline JavaScript](docs/additional_reading/rails_view_rendering_from_inline_javascript.md)
|
383
390
|
+ [Tips](docs/additional_reading/tips.md)
|
384
391
|
+ [Tutorial for v2.0](docs/tutorial-v2.md), deployed [here](https://shakacode-react-on-rails.herokuapp.com/).
|
385
392
|
+ [Turbolinks](docs/additional_reading/turbolinks.md)
|
386
393
|
+ [Webpack Configuration](docs/additional_reading/webpack.md)
|
387
394
|
+ [Webpack Cookbook](https://christianalfoni.github.io/react-webpack-cookbook/index.html)
|
395
|
+
+ [Changelog](CHANGELOG.md)
|
388
396
|
|
389
397
|
## Demos
|
390
|
-
+ [www.reactrails.com](http://www.reactrails.com)
|
398
|
+
+ [www.reactrails.com](http://www.reactrails.com) with source at [shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/).
|
391
399
|
+ [spec app](spec/dummy): Great simple examples used for our tests.
|
392
400
|
```
|
393
401
|
cd spec/dummy
|
@@ -406,7 +414,7 @@ The gem is available as open source under the terms of the [MIT License](docs/LI
|
|
406
414
|
## Authors
|
407
415
|
[The Shaka Code team!](http://www.shakacode.com/about/)
|
408
416
|
|
409
|
-
The project started with [Justin Gordon](https://github.com/justin808/) pairing with [Samnang Chhun](https://github.com/samnang) to figure out how to do server rendering with Webpack plus Rails. [Alex Fedoseev](https://github.com/alexfedoseev) then joined in. [Rob Wise](https://github.com/robwise), [Aaron Van Bokhoven](https://github.com/aaronvb), and [Andy Wang](https://github.com/yorzi) did the bulk of the generators.
|
417
|
+
The project started with [Justin Gordon](https://github.com/justin808/) pairing with [Samnang Chhun](https://github.com/samnang) to figure out how to do server rendering with Webpack plus Rails. [Alex Fedoseev](https://github.com/alexfedoseev) then joined in. [Rob Wise](https://github.com/robwise), [Aaron Van Bokhoven](https://github.com/aaronvb), and [Andy Wang](https://github.com/yorzi) did the bulk of the generators. Many others have [contributed](https://github.com/shakacode/react_on_rails/graphs/contributors).
|
410
418
|
|
411
419
|
We owe much gratitude to the work of the [react-rails gem](https://github.com/reactjs/react-rails). We've also been inspired by the [react_webpack_rails gem](https://github.com/netguru/react_webpack_rails).
|
412
420
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Using ReactOnRails in JavaScript
|
2
|
+
You can easily render React components in your JavaScript with `render` method that returns a [reference to the component](https://facebook.github.io/react/docs/more-about-refs.html) (virtual DOM element).
|
3
|
+
|
4
|
+
```js
|
5
|
+
/**
|
6
|
+
* ReactOnRails.render("HelloWorldApp", {name: "Stranger"}, 'app');
|
7
|
+
*
|
8
|
+
* Does this:
|
9
|
+
* ReactDOM.render(React.createElement(HelloWorldApp, {name: "Stranger"}),
|
10
|
+
* document.getElementById('app'))
|
11
|
+
*
|
12
|
+
* @param name Name of your registered component
|
13
|
+
* @param props Props to pass to your component
|
14
|
+
* @param domNodeId
|
15
|
+
* @returns {virtualDomElement} Reference to your component's backing instance
|
16
|
+
*/
|
17
|
+
ReactOnRails.render(componentName, props, elementId)
|
18
|
+
```
|
19
|
+
|
20
|
+
## Why do we need this?
|
21
|
+
Imagine that we have some event with jQuery, it allows us to set component state manually.
|
22
|
+
|
23
|
+
```html
|
24
|
+
<input id="input" type="range" min="0" max="100" />
|
25
|
+
<div id="root"></div>
|
26
|
+
|
27
|
+
<script>
|
28
|
+
var input = $("#input");
|
29
|
+
var component = ReactOnRails.render("componentName", { value: input.val() }, "root");
|
30
|
+
|
31
|
+
input.on("change", function(e) {
|
32
|
+
component.setState({ value: input.val() });
|
33
|
+
});
|
34
|
+
</script>
|
35
|
+
```
|
@@ -3,8 +3,18 @@ Because you will probably want to run RSpec tests that rely on compiled webpack
|
|
3
3
|
|
4
4
|
ReactOnRails provides a helper method called `configure_rspec_to_compile_assets`. Call this method from inside of the `RSpec.configure` block in your `spec/rails_helper.rb` file, passing the config as an argument.
|
5
5
|
|
6
|
-
|
6
|
+
```ruby
|
7
|
+
RSpec.configure do |config|
|
8
|
+
# Next line will ensure that assets are built if webpack -w is not running
|
9
|
+
ReactOnRails.configure_rspec_to_compile_assets(config)
|
10
|
+
```
|
11
|
+
|
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.
|
7
13
|
|
8
14
|
If you do not want to be slowed down by re-compiling webpack assets from scratch every test run, you can call `npm run build:client` (and `npm run build:server` if doing server rendering) to have webpack recompile these files in the background, which will be much faster. The helper looks for these processes and will abort recompiling if it finds them to be running.
|
9
15
|
|
10
16
|
If you want to use a testing framework other than RSpec, we suggest you implement similar logic.
|
17
|
+
|
18
|
+
![2016-01-27_02-36-43](https://cloud.githubusercontent.com/assets/1118459/12611951/7c56d070-c4a4-11e5-8a80-9615f99960d9.png)
|
19
|
+
|
20
|
+
![2016-01-27_03-18-05](https://cloud.githubusercontent.com/assets/1118459/12611975/a8011654-c4a4-11e5-84f9-1baca4835b4b.png)
|
@@ -4,8 +4,8 @@
|
|
4
4
|
* Currently support 2.5.x of Turbolinks. We plan to update to Turbolinks 5 soon.
|
5
5
|
|
6
6
|
## Why Turbolinks?
|
7
|
-
As you switch between Rails HTML controller requests, you will only load the HTML and you will
|
8
|
-
not reload JavaScript and stylesheets. This definitely can make an app perform better, even if
|
7
|
+
As you switch between Rails HTML controller requests, you will only load the HTML and you will
|
8
|
+
not reload JavaScript and stylesheets. This definitely can make an app perform better, even if
|
9
9
|
the JavaScript and stylesheets are cached by the browser, as they will still require parsing.
|
10
10
|
|
11
11
|
### Install Checklist
|
@@ -19,21 +19,8 @@ the JavaScript and stylesheets are cached by the browser, as they will still req
|
|
19
19
|
```javascript
|
20
20
|
//= require turbolinks
|
21
21
|
```
|
22
|
-
|
23
|
-
## Troubleshooting
|
24
22
|
|
25
|
-
|
26
|
-
|
23
|
+
## Troubleshooting
|
24
|
+
To turn on tracing of Turbolinks events, require `debug_turbolinks` (provided by ReactOnRails) inside of `app/assets/javascripts/application.js` **at the beginning of the file**. This will print out events related to the initialization of the components created with the view helper `react_component`.
|
27
25
|
|
28
|
-
|
29
|
-
```javascript
|
30
|
-
//= require testGlobals
|
31
|
-
```
|
32
|
-
2. Initialie the global debug value of `DEBUG_TURBOLINKS` like this:
|
33
|
-
```javascript
|
34
|
-
window.DEBUG_TURBOLINKS = true;
|
35
|
-
console.log('window.DEBUG_TURBOLINKS = true;');
|
36
|
-
```
|
37
|
-
|
38
|
-
This will print out events related to the initialization of the components created with the view
|
39
|
-
helper `react_component`.
|
26
|
+
We've noticed that Turbolinks doesn't work if you use the ruby gem version of jQuery and jQuery ujs. Therefore we recommend using the node packages instead. See the [tutorial app](https://github.com/shakacode/react-webpack-rails-tutorial) for how to accomplish this.
|
data/docs/doctrine.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# The React on Rails Doctrine
|
2
2
|
|
3
|
-
By Justin Gordon, January
|
3
|
+
By Justin Gordon, January 26, 2016
|
4
4
|
|
5
5
|
This document is an extension and complement to [The Rails Doctrine](http://rubyonrails.org/doctrine/). If you haven't read that document, I suggest you do so first.
|
6
6
|
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-on-rails",
|
3
|
-
"version": "2.1.
|
3
|
+
"version": "2.1.1",
|
4
4
|
"description": "react-on-rails JavaScript for react_on_rails Ruby gem",
|
5
5
|
"main": "node_package/lib/ReactOnRails.js",
|
6
6
|
"directories": {
|
@@ -34,7 +34,8 @@
|
|
34
34
|
"react-transform-hmr": "^1.0.1",
|
35
35
|
"tap-spec": "^4.1.1",
|
36
36
|
"tape": "^4.4.0",
|
37
|
-
"webpack": "^1.12.12"
|
37
|
+
"webpack": "^1.12.12",
|
38
|
+
"jsdom": "^8.0.0-0"
|
38
39
|
},
|
39
40
|
"peerDependencies": {
|
40
41
|
"react": ">= 0.14",
|
data/rakelib/run_rspec.rake
CHANGED
@@ -16,6 +16,12 @@ namespace :run_rspec do
|
|
16
16
|
run_tests_in(File.join("spec", "dummy"), env_vars: "DRIVER=selenium_firefox")
|
17
17
|
end
|
18
18
|
|
19
|
+
task dummy_no_turbolinks: ["dummy_apps:dummy_app"] do
|
20
|
+
run_tests_in(File.join("spec", "dummy"),
|
21
|
+
env_vars: "DRIVER=selenium_firefox DISABLE_TURBOLINKS=TRUE",
|
22
|
+
command_name: "dummy_no_turbolinks")
|
23
|
+
end
|
24
|
+
|
19
25
|
# Dynamically define Rake tasks for each example app found in the examples directory
|
20
26
|
ExampleType.all.each do |example_type|
|
21
27
|
desc "Runs RSpec for #{example_type.name_pretty} only"
|
@@ -37,7 +43,7 @@ namespace :run_rspec do
|
|
37
43
|
Coveralls::RakeTask.new
|
38
44
|
|
39
45
|
desc "run all tests"
|
40
|
-
task run_rspec: [:gem, :dummy, :examples, :empty, :js_tests] do
|
46
|
+
task run_rspec: [:gem, :dummy, :dummy_no_turbolinks, :examples, :empty, :js_tests] do
|
41
47
|
puts "Completed all RSpec tests"
|
42
48
|
end
|
43
49
|
end
|
@@ -69,6 +75,6 @@ def run_tests_in(dir, options = {})
|
|
69
75
|
|
70
76
|
command_name = options.fetch(:command_name, path.basename)
|
71
77
|
rspec_args = options.fetch(:rspec_args, "")
|
72
|
-
env_vars = %(#{options.fetch(env_vars, '')} COVERAGE=true TEST_ENV_COMMAND_NAME="#{command_name}")
|
78
|
+
env_vars = %(#{options.fetch(:env_vars, '')} COVERAGE=true TEST_ENV_COMMAND_NAME="#{command_name}")
|
73
79
|
sh_in_dir(path.realpath, "#{env_vars} bundle exec rspec #{rspec_args}")
|
74
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|
@@ -285,6 +285,7 @@ files:
|
|
285
285
|
- Gemfile
|
286
286
|
- README.md
|
287
287
|
- Rakefile
|
288
|
+
- app/assets/javascripts/debug_turbolinks.js
|
288
289
|
- app/helpers/react_on_rails_helper.rb
|
289
290
|
- docker-compose.yml
|
290
291
|
- docs/LICENSE
|
@@ -292,6 +293,7 @@ files:
|
|
292
293
|
- docs/additional_reading/manual_installation.md
|
293
294
|
- docs/additional_reading/node_dependencies_and_npm.md
|
294
295
|
- docs/additional_reading/optional_configuration.md
|
296
|
+
- docs/additional_reading/rails_view_rendering_from_inline_javascript.md
|
295
297
|
- docs/additional_reading/react-and-redux.md
|
296
298
|
- docs/additional_reading/react_router.md
|
297
299
|
- docs/additional_reading/rspec_configuration.md
|