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

Added errors if a null component is registered #273

Merged
merged 4 commits into from
Feb 14, 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
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: required
language: ruby

rvm:
- 2.2.3
- 2.2.4

services:
- docker
Expand All @@ -22,9 +22,10 @@ before_install:
- sudo apt-get install -y xvfb

install:
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 4.2.0
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 5.5.0
- npm install -g npm
- npm install -g poltergeist
- gem install bundler
- bundle install
- ENABLE_TURBOLINKS_5=TRUE bundle install
- npm install
Expand Down
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ All notable changes to this project will be documented in this file. Items under

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.

## [3.0.0-rc.1] - 2016-02-09
## [3.0.0-rc.2] - 2016-02-09
##### Fixed
- Fix Bootstrap Sass Append to Gemfile, missing new line. [#262](https://github.com/shakacode/react_on_rails/pull/262).

##### Added
- Added helper `redux_store` and associated JavaScript APIs that allow multiple React components to use the same store. Thus, you initialize the store, with props, separately from the components.
- Added forman to gemspec in case new dev does not have it globally installed. [#248](https://github.com/shakacode/react_on_rails/pull/248)

- Added forman to gemspec in case new dev does not have it globally installed. [#248](https://github.com/shakacode/react_on_rails/pull/248).
- Support for Turbolinks 5! [#270](https://github.com/shakacode/react_on_rails/pull/270).
- Added better error messages for `ReactOnRails.register()`. [#273](https://github.com/shakacode/react_on_rails/pull/273).

##### Breaking Change
- Calls to `react_component` should use a named argument of props. For example, change this:
```ruby
Expand All @@ -23,6 +25,7 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
```
You'll get a deprecation message to change this.
- Renamed `ReactOnRails.configure_rspec_to_compile_assets` to `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`. The code has also been optimized to check for whether or not the compiled webpack bundles are up to date or not and will not run if not necessary. If you are using non-standard directories for your generated webpack assets (`app/assets/javascripts/generated` and `app/assets/stylesheets/generated`) or have additional directories you wish the helper to check, you need to update your ReactOnRails configuration accordingly. See [documentation](https://github.com/shakacode/react_on_rails/blob/master/docs/additional_reading/rspec_configuration.md) for how to do this. [#253](https://github.com/shakacode/react_on_rails/pull/253).
- You have to call `ReactOnRails.register` to register react components. This was deprecated in v2. [#273](https://github.com/shakacode/react_on_rails/pull/273).

##### Migration Steps v2 to v3
- [spec/dummy/spec/rails_helper.rb](https://github.com/shakacode/react_on_rails/blob/master/spec%2Fdummy%2Fspec%2Frails_helper.rb#L36..38) for an example. Add this line to your `rails_helper.rb`:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* 3.0.0 Highlights:
1. Support for ensuring JavaScript is current when running tests.
2. Support for multiple React components with one Redux store. So you can have a header React component and different body React components talking to the same Redux store!
* There was a fatal error when using the lastest version of Redux for server rendering. See [Redux #1335](https://github.com/rackt/redux/issues/1335). See [diff 3.1.6...3.1.4](https://github.com/rackt/redux/commit/e2e14d26f09ca729ae0555442f50fcfc45bfb423#diff-1fdf421c05c1140f6d71444ea2b27638). Workaround for server rendering: Use Redux 3.1.7 or upgrade to React On Rails v2.3.0. [this commit](https://github.com/shakacode/react_on_rails/commit/59f1e68d3d233775e6abc63bff180ea59ac2d79e) on [PR #244](https://github.com/shakacode/react_on_rails/pull/244/).
* There was a fatal error when using the lastest version of Redux for server rendering. See [Redux #1335](https://github.com/reactjs/redux/issues/1335). See [diff 3.1.6...3.1.4](https://github.com/reactjs/redux/commit/e2e14d26f09ca729ae0555442f50fcfc45bfb423#diff-1fdf421c05c1140f6d71444ea2b27638). Workaround for server rendering: Use Redux 3.1.7 or upgrade to React On Rails v2.3.0. [this commit](https://github.com/shakacode/react_on_rails/commit/59f1e68d3d233775e6abc63bff180ea59ac2d79e) on [PR #244](https://github.com/shakacode/react_on_rails/pull/244/).
* 2.x Highlights:
1. Fixed a **critical** problem with TurboLinks. Be sure to see [turbolinks docs](docs/additional_reading/turbolinks.md) for more information on how to debug TurboLinks issues.
2. Provides a convenient helper to ensure that JavaScript assets are compiled before running tests.
Expand All @@ -18,9 +18,9 @@

# React on Rails

**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://github.com/rackt/react-router), [**Redux**](https://github.com/rackt/redux), [**React-Router**](https://github.com/rackt/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).
**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://github.com/reactjs/react-router), [**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/rackt/redux) and [React-Router](https://github.com/rackt/react-redux) are supported as well. 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 is supported, with server rendering. [Redux](https://github.com/reactjs/redux) and [React-Router](https://github.com/reactjs/react-redux) are supported as well. 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!

Be sure to see:

Expand Down Expand Up @@ -103,10 +103,10 @@ Please see [Getting Started](#getting-started) for how to set up your Rails proj
## Features
Like the [react-rails](https://github.com/reactjs/react-rails) gem, React on Rails is capable of server-side rendering with fragment caching and is compatible with [turbolinks](https://github.com/rails/turbolinks). Unlike react-rails, which depends heavily on sprockets and jquery-ujs, React on Rails uses [webpack](http://webpack.github.io/) and does not depend on jQuery. While the initial setup is slightly more involved, it allows for advanced functionality such as:

+ [Redux](https://github.com/rackt/redux)
+ [Redux](https://github.com/reactjs/redux)
+ [Webpack dev server](https://webpack.github.io/docs/webpack-dev-server.html) with [hot module replacement](https://webpack.github.io/docs/hot-module-replacement-with-webpack.html)
+ [Webpack optimization functionality](https://github.com/webpack/docs/wiki/optimization)
+ [React Router](https://github.com/rackt/react-router)
+ [React Router](https://github.com/reactjs/react-router)

See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.

Expand Down
2 changes: 1 addition & 1 deletion docs/additional_reading/react_router.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const RouterApp = (props, location) => {
let redirectLocation;
let routeProps;

// See https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ServerRendering.md
// See https://github.com/reactjs/react-router/blob/master/docs/guides/advanced/ServerRendering.md
match({ routes, location }, (_error, _redirectLocation, _routeProps) => {
error = _error;
redirectLocation = _redirectLocation;
Expand Down
4 changes: 2 additions & 2 deletions docs/doctrine.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Here's the chef's selection from the React on Rails community:
* [Bootstrap](http://getbootstrap.com/), loaded from [bootstrap-loader](https://github.com/shakacode/bootstrap-loader/). Common UI styles.
* [Lodash](https://lodash.com/): Swiss army knife of utilities.
* [React](https://facebook.github.io/react/): UI components.
* [React-Router](https://github.com/rackt/react-router): Provider of deep links for client-side application.
* [Redux](https://github.com/rackt/redux): Flux implementation (aka "state container").
* [React-Router](https://github.com/reactjs/react-router): Provider of deep links for client-side application.
* [Redux](https://github.com/reactjs/redux): Flux implementation (aka "state container").

### JavaScript Tooling
* [Babel](https://babeljs.io/): Transpiler for ES6 into ES5 and much more.
Expand Down
2 changes: 1 addition & 1 deletion docs/recommended-project-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ While React On Rails does not *enforce* a specific project structure, we do *rec
* `/containers`: "smart" components. These components are bound to Redux.
* `/reducers`: Reducers for redux.
* `/routes`: Routes for React Router.
* `/store`: Store, which might be [configured differently for dev vs. production](https://github.com/rackt/redux/tree/master/examples/real-world/store).
* `/store`: Store, which might be [configured differently for dev vs. production](https://github.com/reactjs/redux/tree/master/examples/real-world/store).
* `/startup`: Component bindings to stores, with registration of components and stores.
* `/schemas`: Schemas for AJAX JSON requests and responses, as used by the [Normalizr](https://github.com/gaearon/normalizr) package.
1. `/client/app/assets`: Assets for CSS for client app.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 class="alert alert-info this-works"><%= options.server_rendering? ? "Server Rendering" : "Client Rendering" %></h1>
<%%= react_component("HelloWorldApp",
@hello_world_props,
props: @hello_world_props,
prerender: <%= options.server_rendering? %>) %>
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,47 @@
<%- end -%>
},
"dependencies": {
"babel": "^6.3.26",
"babel-cli": "^6.4.5",
"babel-core": "^6.4.5",
"babel-loader": "^6.2.1",
"babel-plugin-syntax-decorators": "^6.3.13",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-types": "^6.4.5",
"es5-shim": "^4.5.0",
"autoprefixer": "^6.3.2",
"axios": "^0.9.1",
"babel": "^6.5.1",
"babel-cli": "^6.5.1",
"babel-core": "^6.5.1",
"babel-loader": "^6.2.2",
"babel-polyfill": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"css-loader": "^0.23.1",
"es5-shim": "^4.5.2",
"expose-loader": "^0.7.1",
<%- if options.redux? -%>
"immutable": "^3.7.6",
<%- end -%>
"imports-loader": "^0.6.5",
"jquery": "^2.2.0",
"jquery-ujs": "^1.1.0-1",
"jquery-ujs": "^1.2.0",
"loader-utils": "^0.2.12",
"lodash": "^4.0.0",
"lodash": "^4.3.0",
<%- if options.redux? -%>
"mirror-creator": "1.0.0",
<%- end -%>
"react": "^0.14.6",
"react": "^0.14.7",
<%- unless options.skip_bootstrap? -%>
"react-bootstrap": "^0.28.2",
"react-bootstrap": "^0.28.3",
<%- end -%>
"react-dom": "^0.14.6",
"react-dom": "^0.14.7",
"react-on-rails": "<%= VersionSyntaxConverter.new.rubygem_to_npm %>",
<%- if options.redux? -%>
"react-redux": "^4.0.6",
"redux": "^3.0.6",
"react-redux": "^4.4.0",
"redux": "^3.3.1",
"redux-promise": "^0.5.1",
"redux-thunk": "^1.0.3",
<%- end -%>
"webpack": "^1.12.12"
"webpack": "^1.12.13"
},
"devDependencies": {
<%- unless options.skip_js_linters? -%>
"babel-eslint": "^5.0.0-beta6",
"babel-eslint": "^5.0.0-beta8",
<%- end -%>
"babel-plugin-react-transform": "^2.0.0",
<%- unless options.skip_bootstrap? -%>
Expand All @@ -86,18 +87,18 @@
"css-loader": "^0.23.1",
<%- unless options.skip_js_linters? -%>
"eslint": "^1.10.3",
"eslint-config-airbnb": "^4.0.0",
"eslint-config-airbnb": "^5.0.0",
"eslint-config-shakacode": "^1.0.0",
"eslint-plugin-react": "^3.16.1",
<%- end -%>
"express": "^4.13.4",
"file-loader": "^0.8.5",
"jade": "^1.11.0",
<%- unless options.skip_js_linters? -%>
"jscs": "^2.8.0",
"jscs": "^2.9.0",
<%- end -%>
"node-sass": "^3.4.2",
"react-transform-hmr": "^1.0.1",
"react-transform-hmr": "^1.0.2",
"sass-loader": "^3.1.2",
"style-loader": "^0.13.0",
"url-loader": "^0.5.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ class HelloWorld extends React.Component {

// Don't forget to actually use connect!
// Note that we don't export HelloWorld, but the redux "connected" version of it.
// See https://github.com/rackt/react-redux/blob/master/docs/api.md#examples
// See https://github.com/reactjs/react-redux/blob/master/docs/api.md#examples
export default connect(select)(HelloWorld);
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Provider } from 'react-redux';
import createStore from '../store/helloWorldStore';
import HelloWorld from '../containers/HelloWorld';

// See documentation for https://github.com/rackt/react-redux.
// See documentation for https://github.com/reactjs/react-redux.
// This is how you get props from the Rails view into the redux store.
// This code here binds your smart component to the redux store.
export default (props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Provider } from 'react-redux';
import createStore from '../store/helloWorldStore';
import HelloWorld from '../containers/HelloWorld';

// See documentation for https://github.com/rackt/react-redux.
// See documentation for https://github.com/reactjs/react-redux.
// This is how you get props from the Rails view into the redux store.
// This code here binds your smart component to the redux store.
// This is how the server redux gets hydrated with data.
Expand Down
17 changes: 6 additions & 11 deletions node_package/src/ComponentRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const _components = new Map();

export default {
/**
* @param components { name: component }
* @param components { component1: component1, component2: component2, etc. }
*/
register(components) {
Object.keys(components).forEach(name => {
Expand All @@ -15,6 +15,10 @@ export default {
}

const component = components[name];
if (!component) {
throw new Error(`Called register with null component named ${name}`);
}

const isGeneratorFunction = generatorFunction(component);

_components.set(name, {
Expand All @@ -30,22 +34,13 @@ export default {
* @returns { name, component, generatorFunction }
*/
get(name) {
const ctx = context();
if (_components.has(name)) {
return _components.get(name);
}

// Backwards compatability. Remove for v3.0.
if (!ctx[name]) {
} else {
const keys = Array.from(_components.keys()).join(', ');
throw new Error(`Could not find component registered with name ${name}. \
Registered component names include [ ${keys} ]. Maybe you forgot to register the component?`);
}

console.warn(
'WARNING: Global components are deprecated support will be removed from a future version. ' +
'Use ReactOnRails.register');
return { name, component: ctx[name] };
},

/**
Expand Down
9 changes: 9 additions & 0 deletions node_package/tests/ComponentRegistry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,12 @@ test('ComponentRegistry throws error for retrieving unregistered component', (as
);
});

test('ComponentRegistry throws error for setting null component', (assert) => {
assert.plan(1);
const C6 = null;
assert.throws(() => ComponentRegistry.register({ C6 }),
/Called register with null component named C6/,
'Expected an exception for calling ComponentRegistry.set with a null component.'
);
});

2 changes: 1 addition & 1 deletion spec/dummy/client/app/startup/ServerRouterApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default (props, location) => {
let redirectLocation;
let routeProps;

// See https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ServerRendering.md
// See https://github.com/reactjs/react-router/blob/master/docs/guides/advanced/ServerRendering.md
match({ routes, location }, (_error, _redirectLocation, _routeProps) => {
error = _error;
redirectLocation = _redirectLocation;
Expand Down
22 changes: 10 additions & 12 deletions spec/dummy/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
},
"main": "js/app.js",
"dependencies": {
"babel": "^6.3.26",
"babel-cli": "^6.4.5",
"babel-core": "^6.4.5",
"babel-loader": "^6.2.1",
"babel-plugin-syntax-decorators": "^6.3.13",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-types": "^6.4.5",
"babel": "^6.5.1",
"babel-cli": "^6.5.1",
"babel-core": "^6.5.1",
"babel-loader": "^6.2.2",
"babel-polyfill": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"es5-shim": "^4.5.2",
"expose-loader": "^0.7.1",
"history": "^2.0.0-rc2",
Expand All @@ -28,15 +26,15 @@
"react-dom": "^0.14.7",
"react-on-rails": "../../..",
"react-redux": "^4.1.2",
"react-router": "^2.0.0-rc5",
"react-router": "^2.0.0",
"redux": "^3.1.7",
"redux-thunk": "^1.0.3",
"webpack": "^1.12.12"
},
"devDependencies": {
"babel-eslint": "^5.0.0-beta8",
"eslint": "^1.10.3",
"eslint-config-airbnb": "4.0.0",
"eslint-config-airbnb": "5.0.0",
"eslint-plugin-react": "^3.16.1",
"jscs": "^2.9.0"
},
Expand Down