-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hot reload + api / production on 3000 to match CRA
- Loading branch information
Showing
13 changed files
with
224 additions
and
45 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
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 |
---|---|---|
|
@@ -10,5 +10,14 @@ router.get('/', function(req, res, next) { | |
res.json({}) | ||
}) | ||
|
||
const users = { | ||
1: { email: '[email protected]' } | ||
} | ||
router.get('/users/:id', function(req, res, next) { | ||
if(Object.keys(users).indexOf(req.params.id) > -1) { | ||
res.json(users[req.params.id]) | ||
} else { | ||
res.status(404).json({}) | ||
} | ||
}) | ||
module.exports = router | ||
|
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,11 @@ | ||
import { fork } from 'redux-saga/effects' | ||
import userSaga from './user' | ||
import API from '../api' | ||
|
||
const api = API.create() | ||
|
||
export default function * rootSaga() { | ||
yield [ | ||
fork(userSaga(api)) | ||
] | ||
} |
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 @@ | ||
import * as userActions from '../actions/user' | ||
import * as userTypes from '../types/user' | ||
import { call, put, takeLatest } from 'redux-saga/effects' | ||
|
||
function * getUser(api, {id}) { | ||
if(!id) { | ||
yield put(userActions.reset()) | ||
} else { | ||
const response = yield call(api.getUser, id) | ||
|
||
if(response.ok) { | ||
yield put(userActions.set(response.data)) | ||
} else { | ||
yield put(userActions.reset()) | ||
} | ||
} | ||
} | ||
|
||
const userSaga = (api) => { | ||
return function * () { | ||
yield [ | ||
takeLatest(userTypes.REQUEST, getUser, api) | ||
] | ||
} | ||
} | ||
|
||
export default userSaga |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const prefix = 'USER/' | ||
|
||
export const REQUEST = prefix + 'REQUEST' | ||
export const SET = prefix + 'SET' | ||
export const RESET = prefix + 'RESET' | ||
|
Oops, something went wrong.