Skip to content

Instantly share code, notes, and snippets.

@kristoferjoseph
Created June 22, 2017 17:01
Show Gist options
  • Save kristoferjoseph/58be71fec3fb30428f2447d9cb304ab8 to your computer and use it in GitHub Desktop.
Save kristoferjoseph/58be71fec3fb30428f2447d9cb304ab8 to your computer and use it in GitHub Desktop.
Flux pattern: How to remove an item in an Array in an immutable way
function remove (state, data) {
var active = state.active.concat()
var i = 0
var l = active.length
var item
for (i; i<l; i++) {
item = active[i]
if (item.id === data.id) {
break
}
}
active.splice(i, 1)
return {
active: active
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment