Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ObservableList<T>

A concrete implementation of IObservableList.

Type parameters

  • T

Hierarchy

  • ObservableList

Implements

Index

Constructors

constructor

  • Construct a new observable list.

    Parameters

    • Optional items: T[]

      The initial items for the list.

    Returns ObservableList

Properties

Protected internal

internal: T[]

The protected internal array of items for the list.

Notes

Subclasses may access this array directly as needed.

Static changedSignal

changedSignal: Signal<ObservableList<any>, IListChangedArgs<any>>

A signal emitted when the list has changed.

See also: changed

Accessors

changed

length

  • get length(): number
  • The number of items in the list.

    Notes

    This is a read-only property.

    Returns number

Methods

Private _check

  • _check(i: number): boolean
  • Check whether a normalized index is in range.

    Parameters

    • i: number

    Returns boolean

Private _clamp

  • _clamp(i: number): number
  • Normalize and clamp an index to the list bounds.

    Parameters

    • i: number

    Returns number

Private _limit

  • _limit(c: number): number
  • Normalize and limit a count to the length of the list.

    Parameters

    • c: number

    Returns number

Private _norm

  • _norm(i: number): number
  • Normalize an index and offset negative values from the list end.

    Parameters

    • i: number

    Returns number

add

  • add(item: T): number
  • Add an item to the end of the list.

    Parameters

    • item: T

      The item to add to the list.

    Returns number

    The index at which the item was added.

Protected addItem

  • addItem(index: number, item: T): number
  • Add an item to the list at the specified index.

    Parameters

    • index: number

      The index at which to add the item. This must be an integer in the range [0, internal.length].

    • item: T

      The item to add at the specified index.

    Returns number

    The index at which the item was added.

    Notes

    This may be reimplemented by subclasses to customize the behavior.

assign

  • assign(items: T[]): T[]
  • Replace the contents of the list with the specified items.

    Parameters

    • items: T[]

      The items to assign to the list.

    Returns T[]

    An array of the previous list items.

    Notes

    This is equivalent to list.replace(0, list.length, items).

clear

  • clear(): T[]
  • Remove all items from the list.

    Returns T[]

    An array of the items removed from the list.

    Notes

    This is equivalent to list.replace(0, list.length, []).

contains

  • contains(item: T): boolean
  • Test whether the list contains a specific item.

    Parameters

    • item: T

      The item of interest.

    Returns boolean

    true if the list contains the item, false otherwise.

get

  • get(index: number): T
  • Get the item at a specific index in the list.

    Parameters

    • index: number

      The index of the item of interest. If this is negative, it is offset from the end of the list.

    Returns T

    The item at the specified index, or undefined if the index is out of range.

indexOf

  • indexOf(item: T): number
  • Get the index of the first occurence of an item in the list.

    Parameters

    • item: T

      The item of interest.

    Returns number

    The index of the specified item or -1 if the item is not contained in the list.

insert

  • insert(index: number, item: T): number
  • Insert an item into the list at a specific index.

    Parameters

    • index: number

      The index at which to insert the item. If this is negative, it is offset from the end of the list. In all cases, it is clamped to the bounds of the list.

    • item: T

      The item to insert into the list.

    Returns number

    The index at which the item was inserted.

move

  • move(fromIndex: number, toIndex: number): boolean
  • Move an item from one index to another.

    Parameters

    • fromIndex: number

      The index of the item of interest. If this is negative, it is offset from the end of the list.

    • toIndex: number

      The desired index for the item. If this is negative, it is offset from the end of the list.

    Returns boolean

    true if the item was moved, false otherwise.

Protected moveItem

  • moveItem(fromIndex: number, toIndex: number): boolean
  • Move an item in the list from one index to another.

    Parameters

    • fromIndex: number

      The initial index of the item. This must be an integer in the range [0, internal.length).

    • toIndex: number

      The desired index for the item. This must be an integer in the range [0, internal.length).

    Returns boolean

    true if the item was moved, false otherwise.

    Notes

    This may be reimplemented by subclasses to customize the behavior.

remove

  • remove(item: T): number
  • Remove the first occurrence of a specific item from the list.

    Parameters

    • item: T

      The item to remove from the list.

    Returns number

    The index occupied by the item, or -1 if the item is not contained in the list.

removeAt

  • removeAt(index: number): T
  • Remove the item at a specific index.

    Parameters

    • index: number

      The index of the item of interest. If this is negative, it is offset from the end of the list.

    Returns T

    The item at the specified index, or undefined if the index is out of range.

Protected removeItem

  • removeItem(index: number): T
  • Remove the item from the list at the specified index.

    Parameters

    • index: number

      The index of the item to remove. This must be an integer in the range [0, internal.length).

    Returns T

    The item removed from the list.

    Notes

    This may be reimplemented by subclasses to customize the behavior.

replace

  • replace(index: number, count: number, items: T[]): T[]
  • Replace items at a specific location in the list.

    Parameters

    • index: number

      The index at which to modify the list. If this is negative, it is offset from the end of the list. In all cases, it is clamped to the bounds of the list.

    • count: number

      The number of items to remove at the given index. This is clamped to the length of the list.

    • items: T[]

      The items to insert at the specified index.

    Returns T[]

    An array of the items removed from the list.

Protected replaceItems

  • replaceItems(index: number, count: number, items: T[]): T[]
  • Replace items at a specific location in the list.

    Parameters

    • index: number

      The index at which to modify the list. This must be an integer in the range [0, internal.length].

    • count: number

      The number of items to remove from the list. This must be an integer in the range [0, internal.length].

    • items: T[]

      The items to insert at the specified index.

    Returns T[]

    An array of the items removed from the list.

    Notes

    This may be reimplemented by subclasses to customize the behavior.

set

  • set(index: number, item: T): T
  • Set the item at a specific index.

    Parameters

    • index: number

      The index of interest. If this is negative, it is offset from the end of the list.

    • item: T

      The item to set at the index.

    Returns T

    The item which occupied the index, or undefined if the index is out of range.

Protected setItem

  • setItem(index: number, item: T): T
  • Set the item at a specific index in the list.

    Parameters

    • index: number

      The index of interest. This must be an integer in the range [0, internal.length).

    • item: T

      The item to set at the index.

    Returns T

    The item which previously occupied the specified index.

    Notes

    This may be reimplemented by subclasses to customize the behavior.

slice

  • slice(start?: number, end?: number): T[]
  • Get a shallow copy of a portion of the list.

    Parameters

    • Optional start: number

      The start index of the slice, inclusive. If this is negative, it is offset from the end of the list. If this is not provided, it defaults to 0. In all cases, it is clamped to the bounds of the list.

    • Optional end: number

      The end index of the slice, exclusive. If this is negative, it is offset from the end of the list. If this is not provided, it defaults to length. In all cases, it is clamped to the bounds of the list.

    Returns T[]

    A new array containing the specified range of items.

Generated using TypeDoc