Skip to content

Commit

Permalink
Add .map to list facet as its needed frequently enough
Browse files Browse the repository at this point in the history
  • Loading branch information
danielzurawski committed Jul 6, 2015
1 parent 07bad75 commit 2db9861
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/components/c_facets/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ _.extendProto(List, {
removeItem: List$removeItem,
extractItem: List$extractItem,
each: List$each,
map: List$map,
_setItem: List$_setItem,
_removeItem: List$_removeItem,
_addItem: List$_addItem,
Expand Down Expand Up @@ -103,8 +104,8 @@ function onChildrenBound() {
item.item.setIndex(index);
});
}
// Component must have one child with an Item facet

// Component must have one child with an Item facet
if (! foundItem) throw new Error('No child component has Item facet');

this.list.itemSample = foundItem;
Expand All @@ -125,7 +126,7 @@ function onChildrenBound() {

function List$_createCacheTemplate() {
if (!this.itemSample) return false;

var itemSample = this.itemSample;

// create item template to insert many items at once
Expand All @@ -136,7 +137,7 @@ function List$_createCacheTemplate() {
attr.el = itemElCopy;
attr.decorate();

var itemsTemplateStr =
var itemsTemplateStr =
'{{ var i = it.count; while(i--) { }}'
+ itemElCopy.outerHTML
+ '{{ } }}';
Expand Down Expand Up @@ -247,7 +248,7 @@ function _updateItemsIndexes(fromIndex, toIndex) {

function List$addItems(count, index) { // ,... items data
var itemsData = _.slice(arguments, 2);
if (itemsData.length < count)
if (itemsData.length < count)
itemsData.concat(_.repeat(count - itemsData.length, {}));
var spliceArgs = [index, 0].concat(itemsData);
var dataFacet = this.owner.data;
Expand Down Expand Up @@ -348,7 +349,7 @@ function List$extractItem(index) {
/**
* List facet instance method
* Removes item, returns the removed item that is destroyed by default.
*
*
* @param {Number} index item index
* @param {Boolean} doDestroyItem optional false to prevent item destruction, true by default
* @return {Component}
Expand Down Expand Up @@ -420,6 +421,14 @@ function List$each(callback, thisArg) {
}


function List$map(callback, thisArg) {
return this._listItems.map(function(item, index) {
if (item) return callback.apply(this, arguments); // passes item, index to callback
else logger.warn('List$map: item', index, 'is undefined');
}, thisArg || this);
}


/**
* Facet instance method
* Destroys the list
Expand Down

0 comments on commit 2db9861

Please sign in to comment.