Created
February 25, 2016 10:45
-
-
Save tonis2/e39a16d198b689d80a8c to your computer and use it in GitHub Desktop.
Pulling feed
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
const PULL_DATA= 'PULL_DATA' | |
import agent from 'superagent' | |
const initialState = { | |
apiFeed:[], | |
loaded:false | |
}; | |
export default function Data(state = initialState, action) { | |
switch (action.type) { | |
case PULL_DATA: | |
return { | |
...state, | |
apiFeed: action.payload, | |
loaded: true | |
} | |
default: | |
return state | |
} | |
} | |
function data_pull(text) { | |
return { | |
type: PULL_DATA, | |
payload: text | |
} | |
} | |
export function getData() { | |
return dispatch => { | |
agent.get('http://localhost:8080/').end((err, res) => { | |
if (!err) { | |
dispatch(data_pull(res.body)) | |
} else { | |
dispatch(data_pull(err)); | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment