-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] - simplify data fetching, organize structure
- Loading branch information
1 parent
1918a4b
commit 8ee228b
Showing
24 changed files
with
285 additions
and
146 deletions.
There are no files selected for viewing
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
src/redux/action_creators/repo_detail/repo_detail_page_action_creators.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// import { canUseDOM } from 'exenv'; | ||
|
||
export function repoDetailPageLoading(state = {}) { | ||
return { | ||
type: 'REPO_DETAIL_PAGE_LOADING', | ||
isLoading: true, | ||
state | ||
}; | ||
} | ||
|
||
export function repoDetailPageLoaded(state = {}) { | ||
return { | ||
type: 'REPO_DETAIL_PAGE_LOADED', | ||
isLoading: false, | ||
state | ||
}; | ||
} | ||
|
||
export function repoDetailPageLoadError(state = {}, error) { | ||
return { | ||
type: 'REPO_DETAIL_PAGE_ERROR', | ||
isLoading: false, | ||
state, | ||
error | ||
}; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/redux/action_creators/search/search_action_creators.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// https://api.github.com/searchs/michaelbenin | ||
// import { canUseDOM } from 'exenv'; | ||
|
||
export function searchLoading(search = {}, state) { | ||
return { | ||
type: 'SEARCH_LOADING', | ||
isLoading: true, | ||
search, | ||
state | ||
}; | ||
} | ||
|
||
export function searchLoaded(search, state) { | ||
return { | ||
type: 'SEARCH_LOADED', | ||
isLoading: false, | ||
search, | ||
state | ||
}; | ||
} | ||
|
||
export function searchError(error, state) { | ||
return { | ||
type: 'SEARCH_ERROR', | ||
isLoading: false, | ||
error, | ||
state | ||
}; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/redux/action_creators/search/search_page_action_creators.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// https://api.github.com/searchs/michaelbenin | ||
// import { canUseDOM } from 'exenv'; | ||
|
||
export function searchPageLoading(state = {}) { | ||
return { | ||
type: 'SEARCH_PAGE_LOADING', | ||
isLoading: true, | ||
state | ||
}; | ||
} | ||
|
||
export function searchPageLoaded(state = {}) { | ||
return { | ||
type: 'SEARCH_PAGE_LOADED', | ||
isLoading: false, | ||
state | ||
}; | ||
} | ||
|
||
export function searchPageError(error, state = {}) { | ||
return { | ||
type: 'SEARCH_PAGE_ERROR', | ||
isLoading: false, | ||
state, | ||
error | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/redux/actions/repo_detail/async_repo_detail_actions.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as repoDetailActions from '../../action_creators/repo_detail/repo_detail_action_creators'; | ||
import RepoDetailModel from '../../../models/repo_detail'; | ||
import notFoundActionCreator from '../../action_creators/not_found_status_action_creator'; | ||
import log from '../../../services/logger_service'; | ||
|
||
export default function fetchRepoDetail(params, dispatch, state) { | ||
dispatch(repoDetailActions.repoDetailLoading()); | ||
return RepoDetailModel.fetch(params, state) | ||
.then(function handleRepoDetailData(repoData) { | ||
dispatch(repoDetailActions.repoDetailLoaded(repoData.data, state)); | ||
}) | ||
.catch(function handleUserError(err) { | ||
log.error(err, 'Error in fetching repo.'); | ||
dispatch(notFoundActionCreator(500, 'ERROR_STATUS')); | ||
dispatch(repoDetailActions.repoDetailLoadError(err, state)); | ||
}); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/redux/actions/repo_detail/async_repo_detail_page_actions.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import P from 'bluebird'; | ||
import * as repoDetailPageActions from '../../action_creators/repo_detail/repo_detail_page_action_creators'; | ||
import notFoundActionCreator from '../../action_creators/not_found_status_action_creator'; | ||
import log from '../../../services/logger_service'; | ||
|
||
import repoDetailAsyncAction from './async_repo_detail_actions'; | ||
|
||
export default function fetchRepoDetail(params, dispatch, state) { | ||
dispatch(repoDetailPageActions.repoDetailPageLoading()); | ||
return P.all([repoDetailAsyncAction(params, dispatch, state)]) | ||
.then(function handleRepoDetailData() { | ||
dispatch(repoDetailPageActions.repoDetailPageLoaded()); | ||
}) | ||
.catch(function handleUserError(err) { | ||
log.error(err, 'Error in fetching repo detail page.'); | ||
dispatch(notFoundActionCreator(500, 'ERROR_STATUS')); | ||
dispatch(repoDetailPageActions.repoDetailPageLoadError(err, state)); | ||
}); | ||
} |
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,19 @@ | ||
// https://api.github.com/searchs/michaelbenin | ||
// import { canUseDOM } from 'exenv'; | ||
import * as searchActions from '../../action_creators/search/search_action_creators'; | ||
import notFoundActionCreator from '../../action_creators/not_found_status_action_creator'; | ||
import SearchModel from '../../../models/search'; | ||
import log from '../../../services/logger_service'; | ||
|
||
export default function fetchSearchAction(query, dispatch, state) { | ||
dispatch(searchActions.searchLoading()); | ||
return SearchModel.fetch(query, state) | ||
.then(function handleSearchModelData(searchData) { | ||
dispatch(searchActions.searchLoaded(searchData.data, state)); | ||
}) | ||
.catch(function handleSearchError(err) { | ||
log.error(err, 'Error in fetching repo.'); | ||
dispatch(notFoundActionCreator(500, 'ERROR_STATUS')); | ||
dispatch(searchActions.searchError(err, state)); | ||
}); | ||
} |
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,20 @@ | ||
// https://api.github.com/searchs/michaelbenin | ||
// import { canUseDOM } from 'exenv'; | ||
import P from 'bluebird'; | ||
import * as searchPageActions from '../../action_creators/search/search_page_action_creators'; | ||
import notFoundActionCreator from '../../action_creators/not_found_status_action_creator'; | ||
import log from '../../../services/logger_service'; | ||
import searchAsyncAction from './async_search_actions'; | ||
|
||
export default function fetchRepoDetail(params, dispatch, state) { | ||
dispatch(searchPageActions.searchPageLoading()); | ||
return P.all([searchAsyncAction(params, dispatch, state)]) | ||
.then(function handleRepoDetailData() { | ||
dispatch(searchPageActions.searchPageLoaded()); | ||
}) | ||
.catch(function handleUserError(err) { | ||
log.error(err, 'Error in search page.'); | ||
dispatch(notFoundActionCreator(500, 'ERROR_STATUS')); | ||
dispatch(searchPageActions.searchPageLoadError(err, state)); | ||
}); | ||
} |
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,17 +1,26 @@ | ||
import { combineReducers } from 'redux'; | ||
import { routerReducer } from 'react-router-redux'; | ||
import { routerReducer as routing } from 'react-router-redux'; | ||
|
||
import configReducer from './config_reducer'; | ||
import metaReducer from './meta_reducer'; | ||
import statusReducer from './status_reducer'; | ||
import repoDetailReducer from './repo_detail_reducer'; | ||
import searchResultsReducer from './search_results_reducer'; | ||
import config from './config_reducer'; | ||
import meta from './meta_reducer'; | ||
import status from './status_reducer'; | ||
|
||
import repoDetail from './repo_detail/repo_detail_reducer'; | ||
import repoDetailPage from './repo_detail/repo_detail_page_reducer'; | ||
|
||
import searchPage from './search/search_page_reducer'; | ||
import search from './search/search_results_reducer'; | ||
|
||
export default combineReducers({ | ||
routing: routerReducer, | ||
config: configReducer, | ||
meta: metaReducer, | ||
status: statusReducer, | ||
repoDetail: repoDetailReducer, | ||
search: searchResultsReducer | ||
routing, | ||
|
||
config, | ||
meta, | ||
status, | ||
|
||
repoDetailPage, | ||
repoDetail, | ||
|
||
searchPage, | ||
search | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/redux/reducers/repo_detail/repo_detail_page_reducer.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// https://github.com/reactjs/redux/issues/99 | ||
// import { canUseDOM } from 'exenv'; | ||
|
||
export default function(state = {}, action) { | ||
const typeMap = { | ||
REPO_DETAIL_PAGE_LOADING() { | ||
return { | ||
isLoading: true | ||
}; | ||
}, | ||
REPO_DETAIL_PAGE_LOADED() { | ||
return { | ||
isLoading: false | ||
}; | ||
}, | ||
REPO_DETAIL_PAGE_ERROR() { | ||
return { | ||
isLoading: false, | ||
error: action.error | ||
}; | ||
} | ||
}; | ||
|
||
if (typeMap[action.type]) { | ||
return typeMap[action.type](); | ||
} | ||
|
||
return state; | ||
} |
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,29 @@ | ||
// https://github.com/reactjs/redux/issues/99 | ||
// import { canUseDOM } from 'exenv'; | ||
|
||
export default function(state = {}, action) { | ||
const typeMap = { | ||
SEARCH_LOADING() { | ||
return { | ||
isLoading: true | ||
}; | ||
}, | ||
SEARCH_LOADED() { | ||
return { | ||
isLoading: false | ||
}; | ||
}, | ||
SEARCH_ERROR() { | ||
return { | ||
isLoading: false, | ||
error: action.error | ||
}; | ||
} | ||
}; | ||
|
||
if (typeMap[action.type]) { | ||
return typeMap[action.type](); | ||
} | ||
|
||
return state; | ||
} |
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
Oops, something went wrong.