Created
June 22, 2017 17:01
-
-
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
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 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