Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CommentList

A list of comments. Offers the ability to query and update the comments in this list. The list’s count, the number of comments known by the server to belong into this list, can be queried independently.

A list contains only comments that either are published or are deleted but still have replies.

Hierarchy

  • CommentList

Implements

Indexable

[index: number]: Comment

Array like index signature. Keeps the comments in the order set through #sortBys or #sortBy. If no order was set yet, the list is ordered by the comments’ creation date.

A list contains only comments that either are published or are deleted but still have replies.

Index

Constructors

constructor

  • Creates a comment list.

    Parameters

    • parent: Page | Comment

      The object this list is collecting comments of. Either a page if this list is collecting its comments, or a comment if this list is collecting its replies.

    Returns CommentList

Properties

_count

_count: number = 0

The (flat) count of comments belonging into this list.

onCountChange

onCountChange: AsyncEvent<number> = new AsyncEvent<number>()

Fired when this list’s #count changed.

onDeepCountChange

onDeepCountChange: AsyncEvent<number> = new AsyncEvent<number>()

Fired when this list’s #deepCount changed.

onLengthChange

onLengthChange: AsyncEvent<number> = new AsyncEvent<number>()

Fired when this list’s #length changed.

onNew

onNew: AsyncEvent<Comment> = new AsyncEvent<Comment>()

Fired when a new comment arrives in this index.

Accessors

count

  • get count(): number
  • The number of comments known to belong in this list. May differ from this list’s #length.

    Returns number

deepCount

  • get deepCount(): number
  • The number of comments known to belong in this list, recursively including replies.

    Returns number

length

  • get length(): number

Methods

byId

  • Queries the comment with the provided id.

    Parameters

    • id: number

      Id of a comment in this list.

    Returns Comment

    The comment with the provided id, or undefined if there is no such comment in this list.

fetch

  • Updates the comments in this list from the server.

    Returns Promise<CommentList>

    A promise that will be resolved with this list when the update succeeded.

fetchCount

  • fetchCount(): Promise<number>
  • Updates the count (number of comments excluding replies) of this list. Calling this method will not change this list’s content.

    Returns Promise<number>

    A promise that will be resolved with the deep count when its retrieval succeeded.

fetchDeepCount

  • fetchDeepCount(): Promise<number>
  • Updates the deep count (number of comments including replies) of this list. Calling this method will not change this list’s content.

    Returns Promise<number>

    A promise that will be resolved with the deep count when its retrieval succeeded.

flatMap

  • flatMap<ResultType>(transformer: function): Array<ResultType>
  • Transforms this comment list together with the comments’ replies into an array using the provided transformer.

    Type parameters

    • ResultType

    Parameters

    • transformer: function
          A function mapping each comment to the desired value.
        • Parameters

          Returns ResultType

    Returns Array<ResultType>

    The array containing the result of transforming each comment in this list. The returned array will have the transformed values in the same order as the source comments were in this list. Replies come directly after their parent.

map

  • map<ResultType>(transformer: function): Array<ResultType>
  • Transforms this comment list into an array using the provided transformer.

    Type parameters

    • ResultType

    Parameters

    • transformer: function

      A function mapping each comment in this list to the desired value.

        • Parameters

          Returns ResultType

    Returns Array<ResultType>

    The array containing the result of transforming each comment in this list. The returned array will have the transformed values in the same order as the source comment were in this list.

sortBy

  • Sort this list using the provided criterion in the provided mode. The list will be kept sorted during any updates until the next call to this method or #sortBys. If the provided criterion decides for two comments to be equal, their creation date will be used in ascending order to sort them.

    Parameters

    • criterion: SortCriterion

      The criterion to sort this list by.

    • Default value mode: SortMode = SortMode.ASCENDING

      The sort direction to use.

    Returns void

sortBys

  • sortBys(...sortMethods: Array<object>): void
  • Sort this list using multiple criteria, potentially in different modes. The list will be kept sorted during any updates until the next call to this method or (#sortBy)[#sortby]. For a pair of comments, the first provided sort method will be used to decide their order. Only if that method decides the comments to be equal, the next method will be used. If all of the provided criteria decide the comments to be equal, their creation date will be used in ascending order to sort them.

    Parameters

    • Rest ...sortMethods: Array<object>

      The sort methods to use, in order of their presedence.

    Returns void

Generated using TypeDoc