Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Removelistitemfix #46

Merged
merged 4 commits into from
Jul 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions src/components/list/listview.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,24 @@ module.exports = class KDListView extends KDView


removeItem: (itemInstance, itemData, index) ->

if index?
@emit 'ItemWasRemoved', @items[index], index
[item] = @items.splice index, 1
destroy = (item, i) =>
@emit 'ItemWasRemoved', item, i
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be the race condition we were seing maybe? index in params list i in function block.

item.destroy()
return yes
else
{dataPath} = @getOptions()

destroy = (item, index) =>
@emit 'ItemWasRemoved', item, i
@items.splice i, 1
item.destroy()
return yes

for item, i in @items
if itemInstance
if itemInstance.getId() is item.getId()
destroy item, i
break
else if itemData
if itemData?[dataPath] is item.getData()?[dataPath]
destroy item, i
break

if index
return no unless @items[index]
return destroy @items[index], index

{dataPath} = @getOptions()

for item, i in @items
if itemInstance
if itemInstance.getId() is @items[i].getId()
return destroy @items[i], i
else if itemData
if itemData[dataPath] and @items[i].getData()[dataPath] and itemData[dataPath] is @items[i].getData()[dataPath]
return destroy @items[i], i


removeItemByData: (itemData) -> @removeItem null, itemData
Expand Down
3 changes: 2 additions & 1 deletion src/components/list/listviewcontroller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = class KDListViewController extends KDViewController
# rename these options
options.noItemFoundWidget or= null
options.noMoreItemFoundWidget or= null
options.lastToFirst ?= no

Object.defineProperty this, "itemsOrdered", get : =>
warn "KDListViewController::itemsOrdered is deprecated."
Expand Down Expand Up @@ -155,7 +156,6 @@ module.exports = class KDListViewController extends KDViewController


removeItem: (itemInstance, itemData, index) ->

return unless itemInstance or itemData or index?

@getListView().removeItem itemInstance, itemData, index
Expand All @@ -180,6 +180,7 @@ module.exports = class KDListViewController extends KDViewController

@emit 'UnregisteringItem', itemInstance, index
actualIndex = if @getOptions().lastToFirst then @getItemCount() - index - 1 else index
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set default lastToFirst value, which needs an updated actualIndex assignment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this needs index ?= @getItemCount()


@getListItems().splice actualIndex, 1
if itemInstance.getData()?
delete @itemsIndexed[itemInstance.getItemDataId()]
Expand Down