-
Notifications
You must be signed in to change notification settings - Fork 382
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
First do it #60
First do it #60
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,6 @@ npm-debug.log | |
|
||
# Ignore bundle dependencies | ||
vendor/ruby | ||
|
||
# RVM gemset | ||
.ruby-gemset | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,61 @@ | ||
import CommentsManager from '../utils/CommentsManager'; | ||
import * from '../constants/ActionTypes'; | ||
import * as actionTypes from '../constants/ActionTypes'; | ||
|
||
export function incrementAjaxCounter() { | ||
return { | ||
type: INCREMENT_AJAX_COUNTER | ||
} | ||
type: actionTypes.INCREMENT_AJAX_COUNTER, | ||
}; | ||
} | ||
|
||
export function decrementAjaxCounter() { | ||
return { | ||
type: DECREMENT_AJAX_COUNTER | ||
} | ||
type: actionTypes.DECREMENT_AJAX_COUNTER, | ||
}; | ||
} | ||
|
||
export function fetchCommentsSuccess(comments) { | ||
return { | ||
type: FETCH_COMMENTS_SUCCESS, | ||
comments | ||
type: actionTypes.FETCH_COMMENTS_SUCCESS, | ||
comments, | ||
}; | ||
} | ||
|
||
export function fetchCommentsFailure(error) { | ||
return { | ||
type: FETCH_COMMENTS_FAILURE, | ||
error | ||
type: actionTypes.FETCH_COMMENTS_FAILURE, | ||
error, | ||
}; | ||
} | ||
|
||
export function submitCommentSuccess(comment) { | ||
return { | ||
type: SUBMIT_COMMENT_SUCCESS, | ||
comment | ||
type: actionTypes.SUBMIT_COMMENT_SUCCESS, | ||
comment, | ||
}; | ||
} | ||
|
||
export function submitCommentFailure(error) { | ||
return { | ||
type: SUBMIT_COMMENT_FAILURE, | ||
error | ||
} | ||
type: actionTypes.SUBMIT_COMMENT_FAILURE, | ||
error, | ||
}; | ||
} | ||
|
||
export function fetchComments() { | ||
return function(dispatch) { | ||
return dispatch => { | ||
return CommentsManager.fetchComments().then( | ||
comments => dispatch(fetchCommentsSuccess(comments)), | ||
error => dispatch(fetchCommentsFailure(error)) | ||
); | ||
} | ||
}; | ||
} | ||
|
||
export function submitComment(comment) { | ||
return function(dispatch) { | ||
return dispatch => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
dispatch(incrementAjaxCounter()); | ||
return CommentsManager.submitComment(comment).then( | ||
comment => dispatch(submitCommentSuccess(comment), | ||
commentFromServer => dispatch(submitCommentSuccess(commentFromServer)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
error => dispatch(submitCommentFailure(error)) | ||
).then(() => dispatch(decrementAjaxCounter())); | ||
} | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,12 @@ const CommentList = React.createClass({ | |
|
||
render() { | ||
const reversedData = this.props.comments.slice(0).reverse(); | ||
const commentNodes = reversedData.map((comment, index) => { | ||
const commentNodes = this.props.comments.get('comments').map((comment, index) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to sort out the reversed data. The reducer is putting the new one at that the top. I'm not sure if we should have the store in reverse order, and not reverse for display or vice versa. |
||
// `key` is a React-specific concept and is not mandatory for the | ||
// purpose of this tutorial. if you're curious, see more here: | ||
// http://facebook.github.io/react/docs/multiple-components.html#dynamic-children | ||
return ( | ||
<Comment author={comment.author} key={index} text={comment.text}/> | ||
<Comment author={comment.get('author')} key={index} text={comment.get('text')}/> | ||
); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import * from '../constants/ActionTypes'; | ||
import * as actionTypes from '../constants/ActionTypes'; | ||
|
||
import Immutable from 'immutable'; | ||
import { Map } from 'immutable'; | ||
|
||
const initialState = Immutable.Map({ | ||
const initialState = Map({ | ||
comments: [], | ||
ajaxCounter: 0, | ||
fetchCommentError: '', | ||
submitCommentError: '', | ||
}); | ||
|
||
export default function commentReducer(state = initialState, action) { | ||
export default function comments(state = initialState, action) { | ||
switch (action.type) { | ||
case FETCH_COMMENTS_SUCCESS: | ||
return state.merge({ comments: action.comments, fetchCommentError: '' }); | ||
case FETCH_COMMENTS_FAILURE: | ||
return state.merge({ fetchCommentError: action.error }); | ||
case SUBMIT_COMMENT_SUCCESS: | ||
return state.withMutatations(mState => { | ||
mState.updateIn(['comments'], comments => comments.unshift(action.comment)). | ||
merge({ submitCommentError: '' }); | ||
}); | ||
case SUBMIT_COMMENT_FAILURE: | ||
return state.merge({ submitCommentError: action.error }); | ||
case INCREMENT_AJAX_COUNTER: | ||
return state.merge({ ajaxCounter: state.get('ajaxCounter') + 1 }); | ||
case DECREMENT_AJAX_COUNTER: | ||
return state.merge({ ajaxCounter: state.get('ajaxCounter') - 1 }); | ||
default: | ||
return state; | ||
case actionTypes.FETCH_COMMENTS_SUCCESS: | ||
return state.merge({ comments: action.comments, fetchCommentError: '' }); | ||
case actionTypes.FETCH_COMMENTS_FAILURE: | ||
return state.merge({ fetchCommentError: action.error }); | ||
case actionTypes.SUBMIT_COMMENT_SUCCESS: | ||
return state.withMutatations(mState => { | ||
mState.updateIn(['comments'], comments => comments.unshift(action.comment)). // Seems to me this is a mutation, for `comments` we should use List type instead | ||
merge({ submitCommentError: '' }); | ||
}); | ||
case actionTypes.SUBMIT_COMMENT_FAILURE: | ||
return state.merge({ submitCommentError: action.error }); | ||
case actionTypes.INCREMENT_AJAX_COUNTER: | ||
return state.merge({ ajaxCounter: state.get('ajaxCounter') + 1 }); | ||
case actionTypes.DECREMENT_AJAX_COUNTER: | ||
return state.merge({ ajaxCounter: state.get('ajaxCounter') - 1 }); | ||
default: | ||
return state; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import comments from './commentReducer'; | ||
|
||
export default { comments }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { createStore, applyMiddleware } from 'redux'; | ||
import commentReducer from '../reducers/commentReducer'; | ||
import { createStore, applyMiddleware, combineReducers } from 'redux'; | ||
import thunk from 'redux-thunk'; | ||
import reducers from '../reducers'; | ||
|
||
// Smth wrong with this one, off for now | ||
import loggerMiddleware from '../middleware/loggerMiddleware'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes -- let's see if we can get this one working afterwards, maybe a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will take a look into this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
||
// applyMiddleware supercharges createStore with middleware: | ||
const createStoreWithMiddleware = applyMiddleware(thunk, loggerMiddleware)(createStore); | ||
export default createStoreWithMiddleware(commentReducer); | ||
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore); | ||
export default createStoreWithMiddleware(combineReducers(reducers)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,10 @@ module.exports = { | |
// jquery: 'var jQuery' | ||
// }, | ||
resolve: { | ||
root: [path.join(__dirname, 'scripts'), | ||
path.join(__dirname, 'assets/javascripts'),], | ||
root: [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, best to put white space changes in separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
path.join(__dirname, 'scripts'), | ||
path.join(__dirname, 'assets/javascripts'), | ||
], | ||
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', '.scss', '.css', 'config.js'], | ||
}, | ||
module: { | ||
|
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.
Curious if this should be project specific.
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.
I keep all gems in isolated gemsets for two reasons:
yo
generator, so I scaffold a lot for testing purposes. It's easier for me to delete scaffolded test gems by deleting gemset.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.
Should .ruby-gemset be in developer's global gitignore?
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.
If everybody is using gemset-per-app strategy, then no. Otherwise — yes.