-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redux integration & faker + json server
- Loading branch information
Praneet Prakash Rohida
authored and
Praneet Prakash Rohida
committed
Aug 31, 2017
1 parent
938e1fe
commit 49a66eb
Showing
13 changed files
with
149 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function setUsername(username) { | ||
return function(dispatch) { | ||
console.log("In set username reducer"); | ||
dispatch({ type: "SET_USERNAME", payload: { username: username } }); | ||
}; | ||
} |
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 @@ | ||
import axios from "axios"; | ||
import { connect } from "react-redux"; | ||
|
||
export function fetchTweets() { | ||
return function(dispatch) { | ||
dispatch({ type: "FETCH_TWEETS" }); | ||
axios | ||
// .get("https://jsonplaceholder.typicode.com/posts") | ||
.get("http://10.0.1.75:3000/tweets") | ||
.then(response => { | ||
dispatch({ | ||
type: "FETCH_TWEETS_FULFILLED", | ||
payload: response.data | ||
}); | ||
}) | ||
.catch(err => { | ||
dispatch({ type: "FETCH_TWEETS_REJECTED", payload: err }); | ||
}); | ||
}; | ||
} |
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,9 @@ | ||
import { combineReducers } from "redux"; | ||
|
||
import tweets from "./tweetsReducer"; | ||
import login from "./loginReducer"; | ||
|
||
export default combineReducers({ | ||
tweets, | ||
login | ||
}); |
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 @@ | ||
export default function reducer( | ||
state = { | ||
username: "" | ||
}, | ||
action | ||
) { | ||
switch (action.type) { | ||
case "SET_USERNAME": { | ||
console.log("In set username reducer"); | ||
return { ...state, username: action.payload.username }; | ||
break; | ||
} | ||
default: { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export default function reducer( | ||
state = { | ||
tweets: [], | ||
fetching: false, | ||
fetched: false, | ||
error: null | ||
}, | ||
action | ||
) { | ||
switch (action.type) { | ||
case "FETCH_TWEETS": { | ||
return { ...state, fetching: true }; | ||
break; | ||
} | ||
case "FETCH_TWEETS_REJECTED": { | ||
return { ...state, fetching: false, error: action.payload }; | ||
break; | ||
} | ||
case "FETCH_TWEETS_FULFILLED": { | ||
return { | ||
...state, | ||
fetched: true, | ||
fetching: false, | ||
tweets: action.payload, | ||
error: null | ||
}; | ||
break; | ||
} | ||
default: { | ||
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
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 { applyMiddleware, createStore } from "redux"; | ||
|
||
import logger from "redux-logger"; | ||
import thunk from "redux-thunk"; | ||
import promise from "redux-promise-middleware"; | ||
|
||
import reducer from "./reducers"; | ||
|
||
const middleware = applyMiddleware(promise(), thunk, logger); | ||
|
||
export default createStore(reducer, middleware); |