Skip to content

Commit

Permalink
Fix merge()
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Aug 22, 2021
1 parent 06b9e44 commit 2af54b1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions js/src/common/utils/ItemList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ class Item<T> {
content: T;
priority: number;

// TODO: Flarum 2.0 - Stop setting `key` on Items
/**
* The index of this item in the latest generated array.
*
* Set when calling `.toArray()`.
*
* **NOTE:** If you modify the item list after `.toArray()` is called,
* this value may not be correct.
*
* @deprecated This will be removed in Flarum 2.0.
*/
key?: number;

Expand Down Expand Up @@ -178,11 +181,13 @@ export default class ItemList<T> {
* with the same key.
*/
merge<K>(otherList: ItemList<K>): ItemList<T | K> {
Object.keys(otherList._items).forEach((key) => {
const val = otherList._items[key];
const otherItems = otherList.toObject();

Object.keys(otherItems).forEach((key) => {
const val = otherItems[key];

if (val instanceof Item) {
(this as ItemList<T | K>)._items[key] = otherList._items[key];
(this as ItemList<T | K>)._items[key] = val;
}
});

Expand Down

0 comments on commit 2af54b1

Please sign in to comment.