Created
October 12, 2018 10:37
-
-
Save anandof28/275e3d73c8962cc9b01332ceb44e187d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //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