Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ReactOnRail.reactOnRailsPageLoaded #417

Merged
merged 4 commits into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ env:

rules:
no-console: 0

no-unused-vars:
- 2
- argsIgnorePattern: ^_
25 changes: 14 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
All notable changes to this project will be documented in this file. Items under `Unreleased` is upcoming features that will be out in next version.

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.

## [Unreleased]

## [6.0.0-rc1]
##### Breaking Changes
- Added automatic compilation of assets at precompile is now done by ReactOnRails. Thus, you don't need to provide your own assets.rake file that does the precompilation.
[#398](https://github.com/shakacode/react_on_rails/pull/398).
- Migration: you can either
[#398](https://github.com/shakacode/react_on_rails/pull/398) by [robwise](https://github.com/robwise), [jbhatab](https://github.com/jbhatab), and [justin808](https://github.com/justin808).
- **Migration to v6: you can either:**

1. Specify a `config/react_on_rails` setting for `npm_build_production_command` to be nil to turn this feature off.
2. Specify the script command you want to run to build your production assets, and remove your assets.rake file.
Expand All @@ -20,26 +21,26 @@ Here is the addition to the generated config file:
```

##### Fixed
- Fixed errors when server rendered props contain \u2028 or \u2029 characters [#375](https://github.com/shakacode/react_on_rails/pull/375) by [mariusandra]
- Fixed errors when server rendered props contain \u2028 or \u2029 characters [#375](https://github.com/shakacode/react_on_rails/pull/375) by [mariusandra](https://github.com/mariusandra)

##### Added
- Non-digested version of assets in public folder [#413](https://github.com/shakacode/react_on_rails/pull/413) by [alleycat-at-git](https://github.com/alleycat-at-git)
- Cache client/node_modules directory to prevent Heroku from reinstalling all modules from scratch [#324](https://github.com/shakacode/react_on_rails/pull/324) by [modosc](https://github.com/modosc)
- Experimental ability to use node.js process for server rendering. See [#380](https://github.com/shakacode/react_on_rails/pull/380) by [alleycat-at-git](https://github.com/alleycat-at-git).
- Non-digested version of assets in public folder [#413](https://github.com/shakacode/react_on_rails/pull/413) by [alleycat-at-git](https://github.com/alleycat-at-git).
- Cache client/node_modules directory to prevent Heroku from reinstalling all modules from scratch [#324](https://github.com/shakacode/react_on_rails/pull/324) by [modosc](https://github.com/modosc).
- ReactOnRails.reactOnRailsPageLoaded() is exposed in case one needs to call this manually and information on async script loading added. See [#315](https://github.com/shakacode/react_on_rails/pull/315) by [SqueezedLight](https://github.com/SqueezedLight).

##### Changed
- [#398](https://github.com/shakacode/react_on_rails/pull/398) by Rob, Blaine, and Justin has:
- [#398](https://github.com/shakacode/react_on_rails/pull/398) by [robwise](https://github.com/robwise), [jbhatab](https://github.com/jbhatab), and [justin808](https://github.com/justin808) contains:
- Only one webpack config is generated for server and client config. Package.json files were changed to reflect this.
- Added npm_build_test_command to allow developers to change what npm command is automatically run from rspec.
- Replace URI with Addressable gem. See [#405](https://github.com/shakacode/react_on_rails/pull/405) by [lucke84](https://github.com/lucke84)

##### Removed
- [#398](https://github.com/shakacode/react_on_rails/pull/398) by Rob, Blaine, and Justin has:
- [#398](https://github.com/shakacode/react_on_rails/pull/398) by [robwise](https://github.com/robwise), [jbhatab](https://github.com/jbhatab), and [justin808](https://github.com/justin808) contains:
- Server rendering is no longer an option in the generator and is always accessible.
- Removed lodash, jquery, and loggerMiddleware from the generated code.
- Removed webpack watch check for test helper automatic compilation.

##### Changed
- Replace URI with Addressable gem. See [#405](https://github.com/shakacode/react_on_rails/pull/405) by [lucke84]

## [5.2.0] - 2016-04-08
##### Added
- Support for React 15.0 to react_on_rails. See [#379](https://github.com/shakacode/react_on_rails/pull/379) by [brucek](https://github.com/brucek).
Expand Down Expand Up @@ -316,7 +317,9 @@ Best done with Object destructing:

##### Fixed
- Fix several generator related issues.

[Unreleased]: https://github.com/shakacode/react_on_rails/compare/5.2.0...master
[6.0.0-rc.1]: https://github.com/shakacode/react_on_rails/compare/5.2.0...6.0.0-rc.1
[5.2.0]: https://github.com/shakacode/react_on_rails/compare/5.1.1...5.2.0
[5.1.1]: https://github.com/shakacode/react_on_rails/compare/5.1.0...5.1.1
[5.1.0]: https://github.com/shakacode/react_on_rails/compare/5.0.0...5.1.0
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*We'll keep a history of the news. A few bullets at the top will also show on the [README.md](./README.md).*

* Always see the [CHANGELOG.md](./CHANGELOG.md) for the latest project changes.

* 2016-04-08: 5.2.0 Released! Support for React 15.0 and updates to the Generator.
* 2016-03-17: **4.0.3** Shipped! Includes using the new Heroku buildpack steps, several smaller changes detailed in the [CHANGELOG.md](./CHANGELOG.md).
* 2016-03-17: **4.0.2** Shipped! Includes using the new Heroku buildpack steps.
* Better support for hot reloading of assets from Rails with new helpers and updates to the sample testing app, [spec/dummy](spec/dummy).
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Dependency Status](https://gemnasium.com/shakacode/react_on_rails.svg)](https://gemnasium.com/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master)

# NEWS
* 2016-04-08: 5.2.0 Released! Support for React 15.0 and updates to the Generator. See the [CHANGELOG.md](./CHANGELOG.md) for details.
* 2016-05-11: 6.0.0-rc.1 Released! Simplified generator and install process! See the [CHANGELOG.md](./CHANGELOG.md) for details.
* [New slides on React on Rails](http://www.slideshare.net/justingordon/react-on-rails-v4032).
* 2016-02-28: We added a [Projects page](./PROJECTS.md) and a [Kudos page](./KUDOS.md). Please edit the page and add your project or [email us](mailto:[email protected]) and we'll add you. We also love stars as it helps us attract new users and contributors.
* *See [NEWS.md](NEWS.md) for more notes over time.*
Expand All @@ -18,7 +18,7 @@

**Project Objective**: To provide an opinionated and optimal framework for integrating **Ruby on Rails** with modern JavaScript tooling and libraries, including [**Webpack**](http://webpack.github.io/), [**Babel**](https://babeljs.io/), [**React**](https://facebook.github.io/react/), [**Redux**](https://github.com/reactjs/redux), [**React-Router**](https://github.com/reactjs/react-router). This differs significantly from typical Rails. When considering what goes into **react_on_rails**, we ask ourselves, is the functionality related to the intersection of using Rails and with modern JavaScript? If so, then the functionality belongs right here. In other cases, we're releasing separate npm packages or Ruby gems. If you are interested in implementing React using traditional Rails architecture, see [react-rails](https://github.com/reactjs/react-rails).

React on Rails integrates Facebook's [React](https://github.com/facebook/react) front-end framework with Rails. React v0.14.x is supported, with server rendering. [Redux](https://github.com/reactjs/redux) and [React-Router](https://github.com/reactjs/react-redux) are supported as well, also with server rendering. See the Rails on Maui [blog post](http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/) that started it all!
React on Rails integrates Facebook's [React](https://github.com/facebook/react) front-end framework with Rails. React v0.14.x and greate is supported, with server rendering. [Redux](https://github.com/reactjs/redux) and [React-Router](https://github.com/reactjs/react-redux) are supported as well, also with server rendering. See the Rails on Maui [blog post](http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/) that started it all!

## Including your React Component in your Rails Views
Please see [Getting Started](#getting-started) for how to set up your Rails project for React on Rails to understand how `react_on_rails` can see your ReactComponents.
Expand Down Expand Up @@ -71,6 +71,7 @@ Please see [Getting Started](#getting-started) for how to set up your Rails proj
- [ReactOnRails View Helpers API](#reactonrails-view-helpers-api)
- [ReactOnRails JavaScript API](#reactonrails-javascript-api)
- [React-Router](#react-router)
- [Deployment](#deployment)
+ [Adding Additional Routes for the Dev Server](#adding-additional-routes-for-the-dev-server)
+ [Migrate From react-rails](#migrate-from-react-rails)
+ [Additional Reading](#additional-reading)
Expand Down Expand Up @@ -407,6 +408,11 @@ Components are created as [stateless function(al) components](https://facebook.g
1. [React on Rails docs for react-router](docs/additional-reading/react-router.md)
1. Examples in [spec/dummy/app/views/react_router](spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/ServerRouterApp.jsx](spec/dummy/client/app/startup/ServerRouterApp.jsx).

## Deployment
* Version 6.0 puts the necessary precompile steps automatically in the rake precompile step. You can, however, disable this by setting certain values to nil in the [config/react_on_rails.rb](config/react_on_rails.rb).
* See the [Heroku Deployment](docs/additional-reading/heroku-deployment.md) doc for specifics regarding Heroku.
* If you're using the node server for server rendering, you may want to do your own AWS install. We'll have more docs on this in the future.

## Additional Reading
+ [JavaScript API](docs/api/javascript-api.md)
+ [Ruby API](docs/api/ruby-api.md)
Expand Down
18 changes: 18 additions & 0 deletions docs/additional-reading/turbolinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ Turbolinks 5 is now being supported. React on Rails will automatically detect wh

For more information on Turbolinks 5: [https://github.com/turbolinks/turbolinks](https://github.com/turbolinks/turbolinks)

### async script loading
Generally async script loading can be done like:
```erb
<%= javascript_include_tag 'application', async: Rails.env.production? %>
```
If you use ```document.addEventListener("turbolinks:load", function() {...});``` somewhere in your code, you will notice, that Turbolinks 5 does not fire ```turbolinks:load``` on initial page load. A quick workaround is to use ```defer``` instead of ```async```:
```erb
<%= javascript_include_tag 'application', defer: Rails.env.production? %>
```
More information on this issue can be found here: https://github.com/turbolinks/turbolinks/issues/28

When loading your scripts asynchronously you may experience, that your Components are not registered correctly. Call ```ReactOnRails.reactOnRailsPageLoaded()``` to re-initialize like so:
```
document.addEventListener("turbolinks:load", function() {
ReactOnRails.reactOnRailsPageLoaded();
});
```

## Troubleshooting
To turn on tracing of Turbolinks events, put this in your registration file, where you register your components.

Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module ReactOnRails
VERSION = "6.0.0.beta.4".freeze
VERSION = "6.0.0.beta.5".freeze
end
8 changes: 6 additions & 2 deletions node_package/src/ReactOnRails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import clientStartup from './clientStartup';
import * as ClientStartup from './clientStartup';
import handleError from './handleError';
import ComponentRegistry from './ComponentRegistry';
import StoreRegistry from './StoreRegistry';
Expand Down Expand Up @@ -63,6 +63,10 @@ ctx.ReactOnRails = {
}
},

reactOnRailsPageLoaded() {
ClientStartup.reactOnRailsPageLoaded();
},

////////////////////////////////////////////////////////////////////////////////
// INTERNALLY USED APIs
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -175,6 +179,6 @@ ctx.ReactOnRails = {

ReactOnRails.resetOptions();

clientStartup(ctx);
ClientStartup.clientStartup(ctx);

export default ctx.ReactOnRails;
4 changes: 2 additions & 2 deletions node_package/src/clientStartup.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function parseRailsContext() {
}
}

function reactOnRailsPageLoaded() {
export function reactOnRailsPageLoaded() {
debugTurbolinks('reactOnRailsPageLoaded');

const railsContext = parseRailsContext();
Expand All @@ -114,7 +114,7 @@ function reactOnRailsPageUnloaded() {
forEachComponent(unmount);
}

export default function clientStartup(context) {
export function clientStartup(context) {
const document = context.document;

// Check if server rendering
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-on-rails",
"version": "6.0.0-beta.4",
"version": "6.0.0-beta.5",
"description": "react-on-rails JavaScript for react_on_rails Ruby gem",
"main": "node_package/lib/ReactOnRails.js",
"directories": {
Expand Down
10 changes: 0 additions & 10 deletions spec/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
PATH
remote: ../..
specs:
react_on_rails (6.0.0.beta.4)
addressable
connection_pool
execjs (~> 2.5)
foreman
rails (>= 3.2)
rainbow (~> 2.1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -85,7 +78,6 @@ GEM
execjs
coffee-script-source (1.10.0)
concurrent-ruby (1.0.2)
connection_pool (2.2.0)
coveralls (0.8.13)
json (~> 1.8)
simplecov (~> 0.11.0)
Expand All @@ -98,8 +90,6 @@ GEM
erubis (2.7.0)
execjs (2.6.0)
ffi (1.9.10)
foreman (0.81.0)
thor (~> 0.19.1)
generator_spec (0.9.3)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
Expand Down