Skip to content

Instantly share code, notes, and snippets.

@aprilrd
Last active May 8, 2018 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aprilrd/e51da6286e7e91e1615b053f7a0922b1 to your computer and use it in GitHub Desktop.
Save aprilrd/e51da6286e7e91e1615b053f7a0922b1 to your computer and use it in GitHub Desktop.
Redux + Immutable.Map
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