Options
All
  • Public
  • Public/Protected
  • All
Menu

ObservableCollection provides Observable semantics around collections. Modifications to an ObservableCollection are broadcast via a binding event that describes the change to the collection via a {@link geocortex.framework.events.CollectionChangedArgs}.

See Observable for more details about semantics and usage of Observables.

docs-hide-from-nav

Type parameters

  • T

Hierarchy

Index

Constructors

constructor

  • Creates a new ObservableCollection, optionally wrapping an existing array.

    var collection = new ObservableCollection(["hello"]);
    collection.addItem("world");
    
    // Returns ["hello", "world"]
    var array = collection.get();

    Parameters

    • Optional items: T[]

      An array of items to initialize the collection to.

    Returns ObservableCollection

Properties

bindingEvent

bindingEvent: GeocortexEvent

The {@link geocortex.framework.events.Event} that is fired when this collection is modified.

throttleDelay

throttleDelay: number

An optional throttleDelay parameter that defines the delay between throttling operations (in milliseconds).

throttledOperations

throttledOperations: ThrottledOperation[]

An array containing all the throttled binding operations currently active on this collection, if throttling is enabled.

useThrottling

useThrottling: boolean

Whether or not to perform throttled binding on this collection. If set to true, data-binding operations across this collection will be performed asynchronously to avoid blocking the UI thread.

Methods

addItem

  • addItem(item: T): void
  • Adds an item to the collection and triggers the binding event.

    Parameters

    • item: T

      The item to add to the collection.

    Returns void

addItems

  • addItems(items: T[]): void
  • Adds items to the collection and triggers the binding event.

    Parameters

    • items: T[]

      The items to add to the collection.

    Returns void

bind

  • bind(scope: any, handler: function): string
  • Binds a handler to the binding event. This handler will be executed whenever the value of the collection is modified Through an ObservableCollection call. This method returns a subscription token that can be used to unsubscribe the handler.

    Parameters

    • scope: any

      The scope to execute the handler in. This will the meaning of 'this' inside of the handler when it is called.

    • handler: function

      The handler to execute when the Observable changes.

    Returns string

clear

  • clear(): void
  • Clears the collection and triggers the binding event.

    Returns void

contains

  • contains(item: T): boolean
  • Checks whether this collection contains a specific item.

    Parameters

    • item: T

      The item to check for.

    Returns boolean

equals

get

  • get(): T[]
  • Gets the raw underlying collection.

    Returns T[]

getAt

  • getAt(index: number): T
  • Tries to get an item from the underlying collection at a given index.

    Parameters

    • index: number

    Returns T

getItems

  • getItems(): T[]
  • Gets the raw underlying collection.

    Returns T[]

getLength

  • getLength(): number
  • Gets the length of the collection.

    Returns number

getRange

  • getRange(begin: number, end?: number): T[]
  • Returns items, given a specific range. Works like Array.slice, except end is inclusive.

    Parameters

    • begin: number

      The beginning of the range to fetch.

    • Optional end: number

      The end of the rang to fetch (inclusive).

    Returns T[]

indexOf

  • indexOf(item: T): number
  • Determines the index of the specified item in the collection.

    Parameters

    • item: T

      The item to get the index of.

    Returns number

insertItem

  • insertItem(index: number, item: T): void
  • Inserts an item into the collection at a given position and triggers the binding event.

    Parameters

    • index: number

      The location to insert the items.

    • item: T

    Returns void

insertItems

  • insertItems(index: number, items: T[]): void
  • Inserts items into the collection at a given position and triggers the binding event.

    Parameters

    • index: number

      The location to insert the items.

    • items: T[]

      The items to insert.

    Returns void

isEmpty

  • isEmpty(): boolean
  • Checks whether this collection contains any items

    Returns boolean

length

  • length(): number
  • Returns the length of this collection.

    Returns number

once

  • once(scope: any, handler: Function): string
  • Binds a handler the the binding event only once. The handler will only be executed the next time the ObservableCollection is updated. This method returns a subscription token that can be used to unsubscribe the handler.

    Parameters

    • scope: any

      The scope to execute the handler in.

    • handler: Function

      The handler to execute when the Observable changes.

    Returns string

pulse

  • pulse(): void
  • Fires the binding event twice, simulating a clear and and append of the entire collection back to its original state. See Observable.

    Returns void

removeAt

  • removeAt(index: number): void
  • Removes the item at the specified index and triggers the binding event. If the index is not valid for this collection, then nothing happens.

    Parameters

    • index: number

      The index of the item to remove.

    Returns void

removeItem

  • removeItem(obj: T): void
  • Removes an object from the collection and triggers the binding event.

    Parameters

    • obj: T

      The object instance to remove.

    Returns void

removeRange

  • removeRange(from: number, to?: number): void
  • Removes a range of items from the collection and fires the binding event accordingly.

    Parameters

    • from: number

      The index to remove from.

    • Optional to: number

      The index to remove to. This is inclusive.

    Returns void

removeSync

  • removeSync(): void
  • Removes the event subscriptions that were created when sync() was called. This effectively unbinds the synchronization that exists between this ObservableCollection and another ObservableCollection.

    Returns void

removeWhere

  • removeWhere(callback: function): void
  • Removes all items from this ObservableCollection where the supplied callback function returns a truthy value.

    Parameters

    • callback: function
        • (item: T): boolean
        • Parameters

          • item: T

          Returns boolean

    Returns void

set

  • set(newCollection: T[]): void
  • Copies an existing raw collection.

    Parameters

    • newCollection: T[]

      The raw collection to copy.

    Returns void

sync

  • Synchronizes one observable collection with another. Henceforth, whenever the source changes, the synchronized collection will also be updated.

    Parameters

    • source: ObservableCollection<T>

      The source ObservableCollection that this ObservableCollection will now mirror.

    Returns void

unbind

  • unbind(token: string): boolean
  • Unbinds a binding subscription, given a valid subscription token received from a call to bind().

    Parameters

    • token: string

      The token representing the previously added subscription handler.

    Returns boolean