Skip to content

Instantly share code, notes, and snippets.

@kristoferjoseph
Created June 22, 2017 16:59
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 kristoferjoseph/533f2ee6c0a3fb17ae10b58e6d4806ca to your computer and use it in GitHub Desktop.
Save kristoferjoseph/533f2ee6c0a3fb17ae10b58e6d4806ca to your computer and use it in GitHub Desktop.
Flux pattern: How to update an item in an Array in an immutable way
function update (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) {
active[i] = data
break
}
}
return {
active: active
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment