Last active
November 16, 2016 13:09
-
-
Save sAbakumoff/55ffb611eef5d198b0326372ee6be7e8 to your computer and use it in GitHub Desktop.
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
function addTodo(state, action){ | |
var new_state; | |
if(action.type !== "ADD_TODO") | |
return state; | |
if(!state) | |
new_state=[]; | |
else | |
new_state=state.slice(); | |
new_state.push(action.item); | |
return new_state; | |
} | |
var state0 = addTodo(null, {type:"ADD_TODO", item : "abc"}); | |
console.log(state0); //["abc"] | |
var state1 = addTodo(state0, {type:"ADD_TODO", item : "xyz"}); | |
console.log(state1); //["abc", "xyz"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment