From f667313cc228af07bab58ec191c37009151eb5d3 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Thu, 11 Jun 2015 18:41:13 +0930 Subject: [PATCH] Improve ordering of list items when specified key doesn't exist --- framework/core/js/lib/utils/item-list.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/framework/core/js/lib/utils/item-list.js b/framework/core/js/lib/utils/item-list.js index 8d7f8c511..0b5bfb9fb 100644 --- a/framework/core/js/lib/utils/item-list.js +++ b/framework/core/js/lib/utils/item-list.js @@ -41,21 +41,17 @@ export default class ItemList { addItems('push', false); addItems('push', 'last'); - items = items.filter(function(item) { + items.forEach(item => { var key = item.position.before || item.position.after; var type = item.position.before ? 'before' : 'after'; if (key) { var index = array.indexOf(this[key]); if (index === -1) { - console.log("Can't find item with key '"+key+"' to insert "+type+", inserting at end instead"); - return true; - } else { - array.splice(array.indexOf(this[key]) + (type === 'after' ? 1 : 0), 0, item); + index = type === 'before' ? 0 : array.length; } + array.splice(index + (type === 'after' ? 1 : 0), 0, item); } - }.bind(this)); - - array = array.concat(items); + }); return array.map((item) => item.content); }