Last active
May 27, 2019 02:19
-
-
Save toruticas/04d02de8acea42167175c420900de2ba to your computer and use it in GitHub Desktop.
Redux Architecture Example (reducer)
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
import { List, Map } from 'immutable'; | |
export const scaffold = Map({ | |
currentIndex: 1, | |
inputValue: '', | |
items: List(), | |
}); | |
export default (state = scaffold, action) => { | |
switch (action.type) { | |
case 'CHANGE_INPUT_VALUE': | |
return state | |
.set('inputValue', action.value); | |
case 'ADD_ITEM': | |
return state | |
.update('items', item => item.push(action.item)) | |
.update('currentIndex', value => value + 1); | |
case 'REMOVE_ITEM': | |
return state | |
.update('items', | |
value => value.filter(item => item.get('id') !== action.id) | |
); | |
default: | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment