Skip to content

ReadOnlyObservableCollection

Andrei Fangli edited this page Sep 3, 2023 · 3 revisions
API / ReadOnlyObservableCollection<TItem> class

Represents a read-only observable collection which can be used as a base class for custom observable collections as well.

Extends: ViewModel, implements IReadOnlyObservableCollection<TItem>.

class ReadOnlyObservableCollection<TItem> extends ViewModel implements IReadOnlyObservableCollection<TItem>

Template Parameters

  • TItem: the type of items the collection contains.

Constructors

Properties

  • itemAdded: an event that is raised when an item is added to the collection.
  • itemRemoved: an event that is raised when an item is removed from the collection.
  • collectionChanged: an event that is raised when the collection changed.
  • length: gets the number of items in the collection.
  • @unscopables: Returns an object specifying how properties are handled inside a with statement.

Methods

  • at: gets the item at the provided index.
  • concat: merges the current collection with the given Array(s) and returns a new JavaScript Array.
  • join: aggregates the contained items into a String placing the provided separator between them.
  • slice: returns a new JavaScript Array containing the elements starting at the provided start index up to, but not including, the provided end index.
  • indexOf: returns the first index of an item, or -1 if none can be found.
  • lastIndexOf: returns the last index of an item, or -1 if none can be found.
  • every: checks whether all elements in the collection fulfil a given condition.
  • some: checks whether some elements in the collection fulfil a given condition.
  • forEach: executes the given callback for each item in the collection.
  • map: creates a new JavaScript Array constructed by mapping each item in the collection using a callback.
  • filter: creates a new JavaScript Array containing only the items for which the provided predicate evaluates to true.
  • reduce: aggregates the collection to a single value.
  • reduceRight: aggregates the collection to a single value by iterating the collection from end to start.
  • find: returns the first item for which the provided predicate evaluated to true, if no item can be found then undefined is returned.
  • findLast: returns the last item for which the provided predicate evaluated to true, if no item can be found then undefined is returned.
  • findIndex: returns the index of the first item for which the provided predicate evaluated to true, if no item can be found then -1 is returned.
  • findLastIndex: returns the index of the last item for which the provided predicate evaluated to true, if no item can be found then -1 is returned.
  • entries: returns an Array iterator containing all the index/item pairs in the collection.
  • keys: returns an Array iterator containing all the indexes in the collection.
  • values: returns an Array iterator containing all the items in the collection.
  • includes: checks whether the provided item is contained by the collection.
  • flatMap: returns a new JavaScript Array by mapping all items in the collection and the flattening the result by one level.
  • flat: returns a new JavaScript Array containing the flattened sub-arrays by recursively concatenating them.
  • toReversed: Returns a JavaScript Array containing the items of the collection in reverse order.
  • toSorted: Returns a JavaScript Array containing the items of the collection in ascending order.
  • toSpliced: Returns a JavaScript Array containing the spliced items of the collection.
  • with: Returns a JavaScript Array containing the elements from the collection and having the one at the provided index replaced with the provided value.
  • @iterator: returns an Array iterator containing all the items in the collection.
  • toArray: Converts the observable collection to a native JavaScript Array.

  • push: appends new elements to the end of the collection, and returns the new length of the collection.
  • pop: removes the last element from the collection and returns it. If the collection is empty, undefined is returned.
  • unshift: inserts new elements at the start of the collection, and returns the new length of the collection.
  • shift: removes the first element from the collection and returns it. If the collection is empty, undefined is returned.
  • get: gets the item at the provided index.
  • set: sets the provided item at the provided index.
  • splice: removes and/or adds elements to the collection and returns the deleted elements.
  • clear: Clears the contents of the collection and returns the removed items, similar to calling collection.splice(0).
  • reset: resets the contents of the collection by clearing it and setting the provided items. Returns the new length of the collection. Similar to calling collection.splice(0, collection.length, ...items).
Clone this wiki locally