Flarum (v2.0.0-beta.1)
    Preparing search index...

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

    Type Parameters

    • T
    Index

    Constructors

    Properties

    _items: Record<string, Item<T>> = {}

    The items in the list.

    Methods

    • Add an item to the list.

      Parameters

      • key: string

        A unique key for the item.

      • content: T

        The item's content.

      • priority: number = 0

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

      Returns this

    • Replaces an item's content, if the provided item key exists.

      If the provided key is not present, an error will be thrown.

      Parameters

      • key: string

        The key of the item in the list

      • content: T

        The item's new content

      Returns this

      items.setContent('myItem', <p>My new value.</p>);
      
               items
      .setContent('myItem', <p>My new value.</p>)
      .setPriority('myItem', 10);

      If the provided key is not present in the ItemList.

    • Replaces an item's priority, if the provided item key exists.

      If the provided key is not present, an error will be thrown.

      Parameters

      • key: string

        The key of the item in the list

      • priority: number

        The item's new priority

      Returns this

      items.setPriority('myItem', 10);
      
               items
      .setPriority('myItem', 10)
      .setContent('myItem', <p>My new value.</p>);

      If the provided key is not present in the ItemList.

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

      This does not preserve the original types of primitives and proxies all content values to make itemName accessible on them.

      NOTE: If your ItemList holds primitive types (such as numbers, booleans or strings), these will be converted to their object counterparts if you do not provide true to this function.

      NOTE: Modifying any objects in the final array may also update the content of the original ItemList.

      Parameters

      • OptionalkeepPrimitives: false

        Converts item content to objects and sets the itemName property on them.

      Returns (T & { itemName: string })[]

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

      Content values that are already objects will be proxied and have itemName accessible on them. Primitive values will not have the itemName property accessible.

      NOTE: Modifying any objects in the final array may also update the content of the original ItemList.

      Parameters

      • keepPrimitives: true

        Converts item content to objects and sets the itemName property on them.

      Returns (T extends object ? T & Readonly<{ itemName: string }> : T)[]