-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
Hello world revision #584
Merged
Merged
Hello world revision #584
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<h1 class="alert alert-info this-works">Hello World</h1> | ||
<h1>Hello World</h1> | ||
<%%= react_component("HelloWorldApp", props: @hello_world_props, prerender: false) %> | ||
|
29 changes: 29 additions & 0 deletions
29
...t_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorld.jsx.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
// Simple example of a React "dumb" component | ||
const HelloWorld = ({ name, updateName }) => ( | ||
<div className="container"> | ||
<h3> | ||
Hello, {name}! | ||
</h3> | ||
<hr /> | ||
<form className="form-horizontal"> | ||
<label htmlFor="name"> | ||
Say hello to: | ||
</label> | ||
<input | ||
type="text" value={name} id="name" | ||
onChange={(e) => updateName(e.target.value)} | ||
/> | ||
</form> | ||
</div> | ||
); | ||
|
||
HelloWorld.propTypes = { | ||
// If you have lots of data or action properties, you should consider grouping them by | ||
// passing two properties: "data" and "actions". | ||
updateName: PropTypes.func.isRequired, | ||
name: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default HelloWorld; |
42 changes: 0 additions & 42 deletions
42
...ails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
lib/generators/react_on_rails/templates/base/base/package.json.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
..._rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
...s/templates/redux/base/client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import actionTypes from '../constants/helloWorldConstants'; | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
export function updateName(name) { | ||
return { | ||
type: actionTypes.HELLO_WORLD_NAME_UPDATE, | ||
name, | ||
}; | ||
} | ||
import { HELLO_WORLD_NAME_UPDATE } from '../constants/helloWorldConstants'; | ||
|
||
export const updateName = (text) => ({ | ||
type: HELLO_WORLD_NAME_UPDATE, | ||
text, | ||
}); |
14 changes: 2 additions & 12 deletions
14
...ails/templates/redux/base/client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
// See https://www.npmjs.com/package/mirror-creator | ||
// Allows us to set up constants in a slightly more concise syntax. See: | ||
// client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx | ||
import mirrorCreator from 'mirror-creator'; | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
const actionTypes = mirrorCreator([ | ||
'HELLO_WORLD_NAME_UPDATE', | ||
]); | ||
|
||
// actionTypes = {HELLO_WORLD_NAME_UPDATE: "HELLO_WORLD_NAME_UPDATE"} | ||
// Notice how we don't have to duplicate HELLO_WORLD_NAME_UPDATE twice | ||
// thanks to mirror-creator. | ||
export default actionTypes; | ||
export const HELLO_WORLD_NAME_UPDATE = 'HELLO_WORLD_NAME_UPDATE'; |
42 changes: 0 additions & 42 deletions
42
...act_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...ils/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Simple example of a React "smart" component | ||
|
||
import { connect } from 'react-redux'; | ||
import HelloWorld from '../components/HelloWorld'; | ||
import * as actions from '../actions/helloWorldActionCreators'; | ||
|
||
// Which part of the Redux global state does our component want to receive as props? | ||
const mapStateToProps = (state) => ({ name: state.name }); | ||
|
||
// 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/reactjs/react-redux/blob/master/docs/api.md#examples | ||
export default connect(mapStateToProps, actions)(HelloWorld); |
28 changes: 12 additions & 16 deletions
28
...n_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import Immutable from 'immutable'; | ||
|
||
import actionTypes from '../constants/helloWorldConstants'; | ||
|
||
export const $$initialState = Immutable.fromJS({ | ||
name: '', // this is the default state that would be used if one were not passed into the store | ||
}); | ||
|
||
export default function helloWorldReducer($$state = $$initialState, action) { | ||
const { type, name } = action; | ||
|
||
switch (type) { | ||
case actionTypes.HELLO_WORLD_NAME_UPDATE: | ||
return $$state.set('name', name); | ||
import { combineReducers } from 'redux'; | ||
import { HELLO_WORLD_NAME_UPDATE } from '../constants/helloWorldConstants'; | ||
|
||
const name = (state = '', action) => { | ||
switch (action.type) { | ||
case HELLO_WORLD_NAME_UPDATE: | ||
return action.text; | ||
default: | ||
return $$state; | ||
return state; | ||
} | ||
} | ||
}; | ||
|
||
const helloWorldReducer = combineReducers({ name }); | ||
|
||
export default helloWorldReducer; |
13 changes: 0 additions & 13 deletions
13
...tors/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 6 additions & 30 deletions
36
...act_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,8 @@ | ||
import { compose, createStore, applyMiddleware, combineReducers } from 'redux'; | ||
import { createStore } from 'redux'; | ||
import helloWorldReducer from '../reducers/helloWorldReducer'; | ||
|
||
// See | ||
// https://github.com/gaearon/redux-thunk and http://redux.js.org/docs/advanced/AsyncActions.html | ||
// This is not actually used for this simple example, but you'd probably want to use this | ||
// once your app has asynchronous actions. | ||
import thunkMiddleware from 'redux-thunk'; | ||
const configureStore = (railsProps) => ( | ||
createStore(helloWorldReducer, railsProps) | ||
); | ||
|
||
import reducers from '../reducers'; | ||
import { initialStates } from '../reducers'; | ||
|
||
export default props => { | ||
// This is how we get initial props Rails into redux. | ||
const { name } = props; | ||
const { $$helloWorldState } = initialStates; | ||
|
||
// Redux expects to initialize the store using an Object, not an Immutable.Map | ||
const initialState = { | ||
$$helloWorldStore: $$helloWorldState.merge({ | ||
name, | ||
}), | ||
}; | ||
|
||
const reducer = combineReducers(reducers); | ||
const composedStore = compose( | ||
applyMiddleware(thunkMiddleware) | ||
); | ||
const storeCreator = composedStore(createStore); | ||
const store = storeCreator(reducer, initialState); | ||
|
||
return store; | ||
}; | ||
export default configureStore; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that there will be a few small changes related to file and component name in no-redux example as HelloWorldWidget.jsx is shared.
Also, there's a lint violation here. And I simplified it a little bit with the arrow function.