Reference Source
import ItemList from 'flarum/utils/ItemList.js'
public class | source

ItemList

The ItemList class collects items and then arranges them into an array by priority.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

The items in the list.

Method Summary

Public Methods
public

add(key: String, content: *, priority: Integer)

Add an item to the list.

public

get(key: String): *

Get the content of an item.

public

has(key: *): boolean

Check whether an item is present in the list.

public

merge(items: ItemList)

Merge another list's items into this one.

public

remove(key: String)

Remove an item from the list.

public

replace(key: String, content: *, priority: Integer)

Replace an item in the list, only if it is already present.

public

Convert the list into an array of item content arranged by priority.

Public Constructors

public constructor() source

Public Members

public items: Object source

The items in the list.

Public Methods

public add(key: String, content: *, priority: Integer) source

Add an item to the list.

Params:

NameTypeAttributeDescription
key String

A unique key for the item.

content *

The item's content.

priority Integer
  • optional

The priority of the item. Items with a higher priority will be positioned before items with a lower priority.

public get(key: String): * source

Get the content of an item.

Params:

NameTypeAttributeDescription
key String

Return:

*

public has(key: *): boolean source

Check whether an item is present in the list.

Params:

NameTypeAttributeDescription
key *

Return:

boolean

public merge(items: ItemList) source

Merge another list's items into this one.

Params:

NameTypeAttributeDescription
items ItemList

public remove(key: String) source

Remove an item from the list.

Params:

NameTypeAttributeDescription
key String

public replace(key: String, content: *, priority: Integer) source

Replace an item in the list, only if it is already present.

Params:

NameTypeAttributeDescription
key String
content *
  • optional
priority Integer
  • optional

public toArray(): Array source

Convert the list into an array of item content arranged by priority. Each item's content will be assigned an itemName property equal to the item's unique key.

Return:

Array