Revert from a while ago: always append if reference item not found

API still needs some work though
This commit is contained in:
Toby Zerner 2015-06-23 11:12:37 +09:30
parent 35cd1f3b51
commit 951db23ffd

View File

@ -44,13 +44,19 @@ export default class ItemList {
items.forEach(item => {
var key = item.position.before || item.position.after;
var type = item.position.before ? 'before' : 'after';
// TODO: Allow both before and after to be specified, and multiple keys to
// be specified for each.
// e.g. {before: ['foo', 'bar'], after: ['qux', 'qaz']}
// This way extensions can make sure they are positioned where
// they want to be relative to other extensions.
if (key) {
var index = array.indexOf(this[key]);
if (index === -1) {
index = type === 'before' ? 0 : array.length;
}
array.push(item);
} else {
array.splice(index + (type === 'after' ? 1 : 0), 0, item);
}
}
});
return array.map((item) => item.content);