mirror of
https://github.com/flarum/framework.git
synced 2024-12-03 07:33:36 +08:00
Merge pull request #1594 from datitisev/item-list
Allow ItemList method chaining (add, merge, remove, replace)
This commit is contained in:
commit
ccf1110faf
|
@ -64,10 +64,13 @@ export default class ItemList {
|
||||||
* @param {*} content The item's content.
|
* @param {*} content The item's content.
|
||||||
* @param {Integer} [priority] The priority of the item. Items with a higher
|
* @param {Integer} [priority] The priority of the item. Items with a higher
|
||||||
* priority will be positioned before items with a lower priority.
|
* priority will be positioned before items with a lower priority.
|
||||||
|
* @return {ItemList}
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
add(key, content, priority = 0) {
|
add(key, content, priority = 0) {
|
||||||
this.items[key] = new Item(content, priority);
|
this.items[key] = new Item(content, priority);
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,6 +79,7 @@ export default class ItemList {
|
||||||
* @param {String} key
|
* @param {String} key
|
||||||
* @param {*} [content]
|
* @param {*} [content]
|
||||||
* @param {Integer} [priority]
|
* @param {Integer} [priority]
|
||||||
|
* @return {ItemList}
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
replace(key, content = null, priority = null) {
|
replace(key, content = null, priority = null) {
|
||||||
|
@ -88,22 +92,28 @@ export default class ItemList {
|
||||||
this.items[key].priority = priority;
|
this.items[key].priority = priority;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an item from the list.
|
* Remove an item from the list.
|
||||||
*
|
*
|
||||||
* @param {String} key
|
* @param {String} key
|
||||||
|
* @return {ItemList}
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
remove(key) {
|
remove(key) {
|
||||||
delete this.items[key];
|
delete this.items[key];
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge another list's items into this one.
|
* Merge another list's items into this one.
|
||||||
*
|
*
|
||||||
* @param {ItemList} items
|
* @param {ItemList} items
|
||||||
|
* @return {ItemList}
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
merge(items) {
|
merge(items) {
|
||||||
|
@ -112,6 +122,8 @@ export default class ItemList {
|
||||||
this.items[i] = items.items[i];
|
this.items[i] = items.items[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user