Last active
January 29, 2018 03:32
-
-
Save dt665m/9680da3c80974369ce041b0493b92af8 to your computer and use it in GitHub Desktop.
Redux Bare Minimum
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
var redux = require('redux') | |
var initialState = { | |
name: 'original', | |
count: 0 | |
} | |
var IncrementAction = { | |
type: 'INCREMENT' | |
} | |
var ChangeAction = { | |
type: 'CHANGE_NAME', | |
payload: "newName", | |
paypoop: "poop", | |
complicated: { | |
com1: "hello", | |
com2: "world" | |
} | |
} | |
function stateReducer(state = initialState, action) { | |
console.log(state); | |
state.marker = "MARKED"; | |
switch (action.type) { | |
case 'INCREMENT': | |
console.log("INCREMENTED!!!") | |
state.count++; | |
return state; | |
case 'CHANGE_NAME': | |
console.log("CHANGE ACTION: ", action) | |
state.name = action.payload; | |
return state | |
default: | |
return state; | |
} | |
} | |
store = redux.createStore(stateReducer) | |
store.dispatch(IncrementAction); | |
store.dispatch(ChangeAction); | |
store.dispatch({type: 'CHANGE_NAME', payload: "NEW"}) | |
store.dispatch({type: 'CHANGE_NAME', payload: "NEW1"}) | |
store.dispatch({type: 'CHANGE_NAME', payload: "NEW2"}) | |
store.dispatch({type: 'CHANGE_NAME', payload: "NEW3"}) | |
store.dispatch({type: 'CHANGE_NAME', payload: "NEW4"}) | |
console.log("FINAL STATE: ", store.getState()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment