Last active
January 18, 2016 23:44
-
-
Save markmcdermid/d6b55497e49864c2cf7a 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
const initialState = { | |
friends: [ | |
{ | |
id: 1, | |
name: 'Some Guy', | |
starred: false | |
}, { | |
id: 2, | |
name: 'Barack Obama', | |
starred: false | |
}, { | |
id: 3, | |
name: 'David Cameron', | |
starred: false | |
} | |
], | |
visibilityFilter: 'starred' | |
} |
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
export default handleActions({ | |
[ADD_FRIEND]: (state, { payload }) => { | |
const { friends } = state | |
return { | |
//eg visibilityFilter: 'STARRED', | |
...state, | |
friends: [ | |
...state.friends, | |
{ | |
id: friends.reduce((maxId, f) => Math.max(f.id, maxId), -1) + 1, | |
name: payload, | |
starred: false | |
} | |
] | |
} | |
} | |
}, initialState) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment