Created
February 5, 2015 10:50
-
-
Save prewk/fb97fec7d9b9842b920c to your computer and use it in GitHub Desktop.
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
var menuItems = Immutable.List.of( | |
{ parent_id: 0, id: 1 }, | |
{ parent_id: 1, id: 2 }, | |
{ parent_id: 1, id: 2 } | |
); | |
var results1 = menuItems | |
.filter(function(menuItem) { return menuItem.parent_id === 1; }) // Filter out items with parent_id = 1 | |
.sort(function(childA, childB) { return childA.sort_order - childB.sort_order; }); // Sort them by sort_order | |
var results2 = menuItems.withMutations(function(list) { | |
list | |
.filter(function(menuItem) { return menuItem.parent_id === 1; }) // Filter out items with parent_id = 1 | |
.sort(function(childA, childB) { return childA.sort_order - childB.sort_order; }); // Sort them by sort_order | |
}); | |
console.log(results1.size); // 2 | |
console.log(results2.size); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment