Skip to content

Commit

Permalink
Merge c9af94a into 03c5e96
Browse files Browse the repository at this point in the history
  • Loading branch information
Judahmeek committed Nov 28, 2016
2 parents 03c5e96 + c9af94a commit 2e42088
Show file tree
Hide file tree
Showing 30 changed files with 180 additions and 169 deletions.
30 changes: 0 additions & 30 deletions .jscsrc

This file was deleted.

1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ gem "web-console", "~> 2.0", group: :development

# below are copied from spec/dummy/Gemfile
gem "rspec-rails"
gem "rspec-retry"
gem "capybara"
gem "capybara-screenshot"
gem "capybara-webkit"
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/react_on_rails/base_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def strip_application_js_of_double_blank_lines
end

def create_react_directories
dirs = %w(components containers startup)
dirs = %w(components startup)
dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
end

Expand All @@ -77,7 +77,6 @@ def template_base_files
Procfile.dev
app/views/hello_world/index.html.erb
package.json
client/app/bundles/HelloWorld/components/HelloWorld.jsx
client/package.json).each { |file| template(base_path + file + ".tt", file) }
end

Expand Down
14 changes: 5 additions & 9 deletions lib/generators/react_on_rails/react_no_redux_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ class ReactNoReduxGenerator < Rails::Generators::Base
Rails::Generators.hide_namespace(namespace)
source_root(File.expand_path("../templates", __FILE__))

def copy_base_files
def copy_react_files
base_path = "no_redux/base/"
file = "client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx"
copy_file(base_path + file, file)
end

def template_appropriate_version_of_hello_world_app
filename = "HelloWorldApp.jsx"
location = "client/app/bundles/HelloWorld/startup"
template("no_redux/base/#{location}/HelloWorldApp.jsx.tt", "#{location}/#{filename}")
%w(client/app/bundles/HelloWorld/components/HelloWorldApp.jsx
client/app/bundles/HelloWorld/startup/registration.jsx).each do |file|
copy_file(base_path + file, file)
end
end
end
end
Expand Down
13 changes: 5 additions & 8 deletions lib/generators/react_on_rails/react_with_redux_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ class ReactWithReduxGenerator < Rails::Generators::Base
source_root(File.expand_path("../templates", __FILE__))

def create_redux_directories
dirs = %w(actions constants reducers store)
dirs = %w(actions constants containers reducers store)
dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
end

def copy_base_redux_files
base_path = "redux/base/"
%w(client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx
client/app/bundles/HelloWorld/components/HelloWorld.jsx
client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx
client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx
client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
client/app/bundles/HelloWorld/store/helloWorldStore.jsx).each do |file|
client/app/bundles/HelloWorld/store/helloWorldStore.jsx
client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx
client/app/bundles/HelloWorld/startup/registration.jsx).each do |file|
copy_file(base_path + file, file)
end
end

def template_appropriate_version_of_hello_world_app
filename = "HelloWorldApp.jsx"
location = "client/app/bundles/HelloWorld/startup"
template("redux/base/#{location}/HelloWorldApp.jsx.tt", "#{location}/#{filename}")
end
end
end
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint comma-dangle: ["error",
{"functions": "never", "arrays": "only-multiline", "objects":
"only-multiline"} ] */

const webpack = require('webpack');
const path = require('path');

Expand All @@ -9,7 +13,7 @@ const config = {
'es5-shim/es5-shim',
'es5-shim/es5-sham',
'babel-polyfill',
'./app/bundles/HelloWorld/startup/HelloWorldApp',
'./app/bundles/HelloWorld/startup/registration',
],

output: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { PropTypes } from 'react';

export default class HelloWorldApp extends React.Component {
static propTypes = {
name: PropTypes.string.isRequired, // this is passed from the Rails view
};

/**
* @param props - Comes from your rails view.
* @param _railsContext - Comes from React on Rails
*/
constructor(props, _railsContext) {
super(props);

// How to set initial state in ES6 class syntax
// https://facebook.github.io/react/docs/reusable-components.html#es6-classes
this.state = { name: this.props.name };
}

updateName = (name) => {
this.setState({ name });
};

render() {
return (
<div>
<h3>
Hello, {this.state.name}!
</h3>
<hr />
<form >
<label htmlFor="name">
Say hello to:
</label>
<input
id="name"
type="text"
value={this.state.name}
onChange={(e) => this.updateName(e.target.value)}
/>
</form>
</div>
);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ReactOnRails from 'react-on-rails';

import HelloWorldApp from '../components/HelloWorldApp';

// This is how react_on_rails can see the HelloWorld in the browser.
ReactOnRails.register({
HelloWorldApp,
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fs.watchFile(bundlePath + bundleFileName, (curr) => {
return;
}

// eslint-disable-next-line global-require
// eslint-disable-next-line global-require, import/no-dynamic-require
require(bundlePath + bundleFileName);
console.log(`Loaded server bundle: ${bundlePath + bundleFileName}`);
handler.initialize();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { PropTypes } from 'react';

export default class HelloWorld extends React.Component {
static propTypes = {
name: PropTypes.string.isRequired, // this is passed from the Rails view
};

/**
* @param props - Comes from your rails view.
* @param _railsContext - Comes from React on Rails
*/
constructor(props, _railsContext) {
super(props);

// How to set initial state in ES6 class syntax
// https://facebook.github.io/react/docs/reusable-components.html#es6-classes
this.state = { name: this.props.name };
}

updateName = (name) => {
this.setState({ name });
};

render() {
return (
<div>
<h3>
Hello, {this.state.name}!
</h3>
<hr />
<form >
<label htmlFor="name">
Say hello to:
</label>
<input
id="name"
type="text"
value={this.state.name}
onChange={(e) => this.updateName(e.target.value)}
/>
</form>
</div>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ const HelloWorldApp = (props, _railsContext) => (
</Provider>
);

// This is how react_on_rails can see the HelloWorldApp in the browser.
ReactOnRails.register({ HelloWorldApp });
export default HelloWorldApp;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import ReactOnRails from 'react-on-rails';

import HelloWorldApp from './HelloWorldApp';

// This is how react_on_rails can see the HelloWorldApp in the browser.
ReactOnRails.register({ HelloWorldApp });
8 changes: 0 additions & 8 deletions node_package/scripts/lint-fix

This file was deleted.

4 changes: 3 additions & 1 deletion node_package/src/ReactOnRails.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ ctx.ReactOnRails = {
setOptions(newOptions) {
if ('traceTurbolinks' in newOptions) {
this.options.traceTurbolinks = newOptions.traceTurbolinks;

// eslint-disable-next-line no-param-reassign
delete newOptions.traceTurbolinks;
}

if (Object.keys(newOptions).length > 0) {
throw new Error(
'Invalid options passed to ReactOnRails.options: ', JSON.stringify(newOptions)
'Invalid options passed to ReactOnRails.options: ', JSON.stringify(newOptions),
);
}
},
Expand Down
8 changes: 4 additions & 4 deletions node_package/src/clientStartup.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function turbolinksInstalled() {

function forEach(fn, className, railsContext) {
const els = document.getElementsByClassName(className);
for (let i = 0; i < els.length; i++) {
for (let i = 0; i < els.length; i += 1) {
fn(els[i], railsContext);
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ export function clientStartup(context) {
return;
}

// eslint-disable-next-line no-underscore-dangle
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
context.__REACT_ON_RAILS_EVENT_HANDLERS_RAN_ONCE__ = true;

debugTurbolinks('Adding DOMContentLoaded event to install event listeners.');
Expand All @@ -153,13 +153,13 @@ export function clientStartup(context) {

if (!turbolinksInstalled()) {
debugTurbolinks(
'NOT USING TURBOLINKS: DOMContentLoaded event, calling reactOnRailsPageLoaded'
'NOT USING TURBOLINKS: DOMContentLoaded event, calling reactOnRailsPageLoaded',
);
reactOnRailsPageLoaded();
} else if (turbolinksVersion5()) {
debugTurbolinks(
'USING TURBOLINKS 5: document added event listeners turbolinks:before-cache and ' +
'turbolinks:load.'
'turbolinks:load.',
);
document.addEventListener('turbolinks:before-cache', reactOnRailsPageUnloaded);
document.addEventListener('turbolinks:load', reactOnRailsPageLoaded);
Expand Down
4 changes: 2 additions & 2 deletions node_package/src/serverRenderReactComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export default function serverRenderReactComponent(options) {
hasErrors = !!reactElementOrRouterResult.routeError;
if (hasErrors) {
console.error(
`React Router ERROR: ${JSON.stringify(reactElementOrRouterResult.routeError)}`
`React Router ERROR: ${JSON.stringify(reactElementOrRouterResult.routeError)}`,
);
} else if (trace) {
const redirectLocation = reactElementOrRouterResult.redirectLocation;
const redirectPath = redirectLocation.pathname + redirectLocation.search;
console.log(`\
ROUTER REDIRECT: ${name} to dom node with id: ${domNodeId}, redirect to ${redirectPath}`
ROUTER REDIRECT: ${name} to dom node with id: ${domNodeId}, redirect to ${redirectPath}`,
);
}
} else {
Expand Down

0 comments on commit 2e42088

Please sign in to comment.