Skip to content

Instantly share code, notes, and snippets.

@markmcdermid
Last active January 18, 2016 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markmcdermid/d6b55497e49864c2cf7a to your computer and use it in GitHub Desktop.
Save markmcdermid/d6b55497e49864c2cf7a to your computer and use it in GitHub Desktop.
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'
}
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