Skip to content

Instantly share code, notes, and snippets.

@anandof28
Created October 12, 2018 10:37
Show Gist options
  • Select an option

  • Save anandof28/275e3d73c8962cc9b01332ceb44e187d to your computer and use it in GitHub Desktop.

Select an option

Save anandof28/275e3d73c8962cc9b01332ceb44e187d to your computer and use it in GitHub Desktop.
//Input and Reducer
import { createStore } from "redux";
import { Object } from "core-js";
//constant
const UPDATEPROFILE = "UPDATEPROFILE";
const initalState = {
id: 1,
name: "defaultName"
};
const ProfileReducer = (state = initalState, action) => {
switch (action.type) {
case UPDATEPROFILE:
return Object.assign({}, state, { name: action.name });
default:
return state;
}
};
const appStore = createStore(ProfileReducer);
/* const action = {
type: UPDATEPROFILE,
name: "Ram"
};
*/
/* function ProfileActionCreator(name) {
return {
type: UPDATEPROFILE,
name: name
};
} */
const ProfileActionCreator = name => ({ type: UPDATEPROFILE, name });
appStore.subscribe(function() {
console.log(appStore.getState());
});
//appStore.dispatch(action);
appStore.dispatch(ProfileActionCreator("Robert"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment