Skip to content

Instantly share code, notes, and snippets.

@tonis2
Created February 25, 2016 10:45
Show Gist options
  • Save tonis2/e39a16d198b689d80a8c to your computer and use it in GitHub Desktop.
Save tonis2/e39a16d198b689d80a8c to your computer and use it in GitHub Desktop.
Pulling feed
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