Last active
May 8, 2018 07:01
-
-
Save aprilrd/e51da6286e7e91e1615b053f7a0922b1 to your computer and use it in GitHub Desktop.
Redux + Immutable.Map
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
import { Map } from "immutable"; | |
// reducers | |
const INITIAL_STATE = Map({ post: null, isLoading: false }); | |
function postReducer(state = INITIAL_STATE, action) { | |
switch (action.type) { | |
case "FETCHED": { | |
return state.withMutations(currentState => | |
currentState.set("post", action.payload.post).set("isLoading", false), | |
); | |
} | |
default: { | |
return state; | |
} | |
} | |
} | |
// action creators | |
function fetchedPost(post) { | |
return { | |
type: "FETCHED", | |
payload: { | |
post, | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment