Created
June 22, 2017 16:59
-
-
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
This file contains hidden or 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
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