revert(list-selection): Using clientIds had unintended consequences

This commit is contained in:
Ben Gotow 2016-02-05 10:17:41 -08:00
parent c4749f592e
commit 54054bef7b

View file

@ -45,7 +45,7 @@ class ListSelection
return unless item return unless item
throw new Error("toggle must be called with a Model") unless item instanceof Model 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 if without.length < @_items.length
@_items = without @_items = without
else else
@ -56,7 +56,7 @@ class ListSelection
return unless item return unless item
throw new Error("add must be called with a Model") unless item instanceof Model 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) updated.push(item)
if updated.length isnt @_items.length if updated.length isnt @_items.length
@_items = updated @_items = updated
@ -73,7 +73,7 @@ class ListSelection
itemIds = _.pluck(items, 'id') 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 if without.length < @_items.length
@_items = without @_items = without
@trigger(@) @trigger(@)
@ -97,12 +97,12 @@ class ListSelection
# items are in the _items array in the order they were selected. # items are in the _items array in the order they were selected.
# (important for walking) # (important for walking)
relativeTo = @_items[@_items.length - 1] relativeTo = @_items[@_items.length - 1]
startIdx = @_view.indexOfId(relativeTo.clientId) startIdx = @_view.indexOfId(relativeTo.id)
endIdx = @_view.indexOfId(item.clientId) endIdx = @_view.indexOfId(item.id)
return if startIdx is -1 or endIdx is -1 return if startIdx is -1 or endIdx is -1
for idx in [startIdx..endIdx] for idx in [startIdx..endIdx]
item = @_view.get(idx) 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) @_items.push(item)
@trigger() @trigger()
@ -116,7 +116,7 @@ class ListSelection
ids = @ids() ids = @ids()
noSelection = @_items.length is 0 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 if noSelection or neitherSelected
@_items.push(current) if current @_items.push(current) if current
@ -124,15 +124,15 @@ class ListSelection
else else
selectionPostPopHeadId = null selectionPostPopHeadId = null
if @_items.length > 1 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() @_items.pop()
else else
# Important: As you walk over this item, remove it and re-push it on the selected # 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 # 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. # 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) @_items.push(next)
@trigger() @trigger()
@ -147,7 +147,7 @@ class ListSelection
touched = 0 touched = 0
for newer in change.objects for newer in change.objects
for existing, idx in @_items for existing, idx in @_items
if existing.clientId is newer.clientId if existing.id is newer.id
@_items[idx] = newer @_items[idx] = newer
touched += 1 touched += 1
break break