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

addItem Refactor #37

Merged
merged 4 commits into from
Jun 3, 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
27 changes: 9 additions & 18 deletions src/components/list/listview.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,12 @@ module.exports = class KDListView extends KDView

{lastToFirst} = @getOptions()


unless index

index = 0

unless index?
if lastToFirst
then @items.unshift itemInstance
else @items.push itemInstance

index = if lastToFirst then 0 else @items.length - 1
else

@items.splice index, 0, itemInstance
Expand All @@ -120,13 +117,14 @@ module.exports = class KDListView extends KDView
{boxed, lastToFirst} = @getOptions()

if index <= 0
index = if boxed and lastToFirst then undefined else 0

if boxed
then @packageItem itemInstance
else @addSubView itemInstance, null, lastToFirst

else if index > 0
if index >= @items.length - 1
index = if boxed and not lastToFirst then undefined else @items.length - 1

if boxed and not index?
@packageItem itemInstance
else
shouldBeLastItem = index >= @items.length - 1
item = itemInstance.getElement()

Expand All @@ -135,14 +133,7 @@ module.exports = class KDListView extends KDView
neighborItem.parentNode.insertBefore item, neighborItem
itemInstance.emit 'viewAppended' if @parentIsInDom
else
@addSubView itemInstance, null, !lastToFirst







@addSubView itemInstance, null

@scrollDown() if @doIHaveToScroll()

Expand Down
26 changes: 3 additions & 23 deletions src/components/list/listviewcontroller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ module.exports = class KDListViewController extends KDViewController
options.noItemFoundWidget or= null
options.noMoreItemFoundWidget or= null

@itemsOrdered = [] unless @itemsOrdered
# CtF: this must be fixed: duplicate itemsOrdered and KDListView.items
# Object.defineProperty this, "itemsOrdered", get : => @getListView().items
Object.defineProperty this, "itemsOrdered", get : =>
warn "KDListViewController::itemsOrdered is deprecated."
@getListView().items

@itemsIndexed = {}
@selectedItems = []
Expand Down Expand Up @@ -157,28 +157,8 @@ module.exports = class KDListViewController extends KDViewController

registerItem: (itemInstance, index) ->

{lastToFirst} = @getOptions()

# this is a copy/paste
# we should remove itemsOrdered altogether
# and it will be fixed with that refactor
# see CtF's comment above
unless index

index = 0

if lastToFirst
then @itemsOrdered.unshift itemInstance
else @itemsOrdered.push itemInstance

else

@itemsOrdered.splice index, 0, itemInstance


@itemsIndexed[id] = itemInstance if id = itemInstance.getItemDataId()?


{selection, keyNav, multipleSelection} = @getOptions()

if selection
Expand Down