From eb5b849a032dfae0872b274359ea8bc782382c0e Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Fri, 5 Feb 2016 10:17:41 -0800 Subject: [PATCH] revert(list-selection): Using clientIds had unintended consequences --- src/components/list-selection.coffee | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/list-selection.coffee b/src/components/list-selection.coffee index b61e1148f..811242ff1 100644 --- a/src/components/list-selection.coffee +++ b/src/components/list-selection.coffee @@ -45,7 +45,7 @@ class ListSelection return unless item throw new Error("toggle must be called with a Model") unless item instanceof Model - without = _.reject @_items, (t) -> t.clientId is item.clientId + without = _.reject @_items, (t) -> t.id is item.id if without.length < @_items.length @_items = without else @@ -56,7 +56,7 @@ class ListSelection return unless item throw new Error("add must be called with a Model") unless item instanceof Model - updated = _.reject @_items, (t) -> t.clientId is item.clientId + updated = _.reject @_items, (t) -> t.id is item.id updated.push(item) if updated.length isnt @_items.length @_items = updated @@ -73,7 +73,7 @@ class ListSelection itemIds = _.pluck(items, 'id') - without = _.reject @_items, (t) -> t.clientId in itemIds + without = _.reject @_items, (t) -> t.id in itemIds if without.length < @_items.length @_items = without @trigger(@) @@ -97,12 +97,12 @@ class ListSelection # items are in the _items array in the order they were selected. # (important for walking) relativeTo = @_items[@_items.length - 1] - startIdx = @_view.indexOfId(relativeTo.clientId) - endIdx = @_view.indexOfId(item.clientId) + startIdx = @_view.indexOfId(relativeTo.id) + endIdx = @_view.indexOfId(item.id) return if startIdx is -1 or endIdx is -1 for idx in [startIdx..endIdx] item = @_view.get(idx) - @_items = _.reject @_items, (t) -> t.clientId is item.clientId + @_items = _.reject @_items, (t) -> t.id is item.id @_items.push(item) @trigger() @@ -116,7 +116,7 @@ class ListSelection ids = @ids() noSelection = @_items.length is 0 - neitherSelected = (not current or ids.indexOf(current.clientId) is -1) and (not next or ids.indexOf(next.clientId) is -1) + neitherSelected = (not current or ids.indexOf(current.id) is -1) and (not next or ids.indexOf(next.id) is -1) if noSelection or neitherSelected @_items.push(current) if current @@ -124,15 +124,15 @@ class ListSelection else selectionPostPopHeadId = null if @_items.length > 1 - selectionPostPopHeadId = @_items[@_items.length - 2].clientId + selectionPostPopHeadId = @_items[@_items.length - 2].id - if next.clientId is selectionPostPopHeadId + if next.id is selectionPostPopHeadId @_items.pop() else # Important: As you walk over this item, remove it and re-push it on the selected # array even if it's already there. That way, the items in _items are always # in the order you walked over them, and you can walk back to deselect them. - @_items = _.reject @_items, (t) -> t.clientId is next.clientId + @_items = _.reject @_items, (t) -> t.id is next.id @_items.push(next) @trigger() @@ -147,7 +147,7 @@ class ListSelection touched = 0 for newer in change.objects for existing, idx in @_items - if existing.clientId is newer.clientId + if existing.id is newer.id @_items[idx] = newer touched += 1 break