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

ListView: Prevent unregisterItem method to delete item from listView #62

Merged
merged 3 commits into from
Aug 16, 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
2 changes: 0 additions & 2 deletions src/components/list/listviewcontroller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ module.exports = class KDListViewController extends KDViewController
unregisterItem: (itemInstance, index) ->

@emit 'UnregisteringItem', itemInstance, index
actualIndex = @getIndex index

@getListItems().splice actualIndex, 1
if itemInstance.getData()?
delete @itemsIndexed[itemInstance.getItemDataId()]
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove the actualIndex variable as well. Other than tat, LGTM.


Expand Down
41 changes: 3 additions & 38 deletions test/components/list/listviewcontroller.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -282,47 +282,12 @@ describe 'KDListViewController', ->
itemView = new KDListItemView {}, {id: 1}
viewController = new KDListViewController { multipleSelection: on }

viewController.registerItem itemView

sinon.spy viewController, 'emit'
viewController.unregisterItem itemView, 0

assert.isDefined viewController._e['UnregisteringItem']


context 'when it is lastToFirst', ->

it 'removes item from view list', ->

viewController = new KDListViewController
itemClass : KDListItemView
lastToFirst : yes

for i in [0...5]
viewController.addItem {title: Date.now(), id: i}, i

item = viewController.getListItems()[1]
viewController.unregisterItem item, 1
assert.ok viewController.emit.calledWith 'UnregisteringItem'

itemViews = viewController.getListItems().map (item) -> item.data.id
assert.ok _.isEqual itemViews, [0, 1, 2, 4]

context 'when it is not lastToFirst', ->

it 'removes item from view list', ->

viewController = new KDListViewController
itemClass : KDListItemView
lastToFirst : no

for i in [0...5]
viewController.addItem {title: Date.now(), id: i}, i

item = viewController.getListItems()[1]
viewController.unregisterItem item, 1

itemViews = viewController.getListItems().map (item) -> item.data.id

assert.deepEqual itemViews, [0, 2, 3, 4]
assert.isDefined viewController._e['UnregisteringItem']

context 'if there is data on the instance', ->

Expand Down