-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working version with Redux with a few isssues:
Squash merge of #60 from @alexfedoseev (thanks!) 1. What should we name the reducer? Seems confusing in terms of how the reducer name gets put as part of the state. 2. Functional issue in that we don't clear out the last name/commment after ajax is successful. Seems that we would need to have the component state inside of the main store. 3. Ajax counter to show busy indicator of async in progress might not be working. 4. We should show a simple validation on the server and the display of a simple error message on the form.
- Loading branch information
Showing
12 changed files
with
93 additions
and
71 deletions.
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
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 |
44 changes: 22 additions & 22 deletions
44
client/assets/javascripts/actions/CommentActionCreators.js
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,66 +1,66 @@ | ||
import CommentsManager from '../utils/CommentsManager'; | ||
import * as types from '../constants/ActionTypes'; | ||
import * as actionTypes from '../constants/ActionTypes'; | ||
|
||
export function incrementAjaxCounter() { | ||
return { | ||
type: types.INCREMENT_AJAX_COUNTER | ||
} | ||
type: actionTypes.INCREMENT_AJAX_COUNTER, | ||
}; | ||
} | ||
|
||
export function decrementAjaxCounter() { | ||
return { | ||
type: types.DECREMENT_AJAX_COUNTER | ||
} | ||
type: actionTypes.DECREMENT_AJAX_COUNTER, | ||
}; | ||
} | ||
|
||
export function fetchCommentsSuccess(comments) { | ||
return { | ||
type: types.FETCH_COMMENTS_SUCCESS, | ||
comments | ||
type: actionTypes.FETCH_COMMENTS_SUCCESS, | ||
comments, | ||
}; | ||
} | ||
|
||
export function fetchCommentsFailure(error) { | ||
return { | ||
type: types.FETCH_COMMENTS_FAILURE, | ||
error | ||
type: actionTypes.FETCH_COMMENTS_FAILURE, | ||
error, | ||
}; | ||
} | ||
|
||
export function submitCommentSuccess(comment) { | ||
return { | ||
type: types.SUBMIT_COMMENT_SUCCESS, | ||
comment | ||
type: actionTypes.SUBMIT_COMMENT_SUCCESS, | ||
comment, | ||
}; | ||
} | ||
|
||
export function submitCommentFailure(error) { | ||
return { | ||
type: types.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)) | ||
comments => dispatch(fetchCommentsSuccess(comments)), | ||
error => dispatch(fetchCommentsFailure(error)) | ||
); | ||
} | ||
}; | ||
} | ||
|
||
function dispatchDecrementAjaxCounter() { | ||
function dispatchDecrementAjaxCounter(dispatch) { | ||
return dispatch(decrementAjaxCounter()); | ||
} | ||
|
||
export function submitComment(comment) { | ||
return function(dispatch) { | ||
return dispatch => { | ||
dispatch(incrementAjaxCounter()); | ||
return CommentsManager.submitComment(comment).then( | ||
comment => dispatch(submitCommentSuccess(comment)), | ||
error => dispatch(submitCommentFailure(error))).then( | ||
dispatchDecrementAjaxCounter, | ||
dispatchDecrementAjaxCounter); | ||
dispatchDecrementAjaxCounter(dispatch), | ||
dispatchDecrementAjaxCounter(dispatch)); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import commentsData from './commentReducer'; | ||
|
||
export default { commentsData }; |
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,10 @@ | ||
import { createStore, applyMiddleware } from 'redux'; | ||
import { createStore, applyMiddleware, combineReducers } from 'redux'; | ||
import thunk from 'redux-thunk'; | ||
import commentReducer from '../reducers/commentReducer'; | ||
import loggerMiddleware from '../middleware/loggerMiddleware'; | ||
import reducers from '../reducers'; | ||
|
||
// Smth wrong with this one, off for now | ||
// import loggerMiddleware from '../middleware/loggerMiddleware'; | ||
|
||
// 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)); |
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