Class Observer

Adds update and management functionality to target objects such as arrays, DOM elements, and objects. The Sys.Observer class is based on the Observer pattern. The Sys.Observer class maintains a list of interested dependents (observers) in a separate object (the subject). All methods that are contained in the Sys.Observer class are static. In order to be used with the Sys.Observer class, an object must be an object, array, or DOM element.

see

{@link http://msdn.microsoft.com/en-us/library/dd393710(v=vs.100).aspx}

Index

Methods

Methods

public static add(target: Array<any>, item: any)

Adds an item to the collection in an observable manner.

Parameters

  • target: Array<any>
          The array to which an item will be added.
    
  • item: any
          The item to add.
    

public static addCollectionChanged(target: any, handler: Function)

Adds an event handler to the target.

Parameters

  • target: any

    The array to which an event handler will be added.

  • handler: Function

    The event handler.

public static addEventHandler(target: any, eventName: string, handler: Function)

Adds an observable event handler to the target.

Parameters

  • target: any
  • eventName: string

    A string that contains the event name.

  • handler: Function

    The added function.

public static addPropertyChanged(target: any, handler: Function)

Adds a propertyChanged event handler to the target.

Parameters

  • target: any

    The object to observe.

  • handler: Function

    The function handler to add.

public static addRange(target: Array<any>, items: Array<any>)

Adds items to the collection in an observable manner.

Parameters

  • target: Array<any>

    The array to which items will be added.

  • items: Array<any>

    The array of items to add.

public static beginUpdate(target: any)

Begins the process of updating the target object.

Parameters

  • target: any

    The object to update.

public static clear(target: any)

Clears the array of its elements in an observable manner.

Parameters

  • target: any

    The array to clear.

public static endUpdate(target: any)

Ends the process of updating the target object.

Parameters

  • target: any

    The object being updated.

public static insert(target: any, index: number, item: any)

Inserts an item at the specified index in an observable manner.

Parameters

  • target: any

    The array to which the item is inserted.

  • index: number

    A number that represents the index where the item will be inserted.

  • item: any

    The item to insert.

public static isUpdating(target: any): boolean

Indicates that the target is being updated.

Parameters

  • target: any

    The target object to update.

Returns

boolean

true if given target argument is currently updating; otherwise false.

public static makeObservable(target: any): any

Makes an object directly observable by adding observable methods to it.

see

{@link http://msdn.microsoft.com/en-us/library/dd393633(v=vs.100).aspx}

Parameters

  • target: any

    The object, array, or DOM element to make observable.

Returns

any

The observable object.

public static raiseCollectionChanged(target: Array<any>, changes: CollectionChange)

Raises the collectionChanged event.

Parameters

  • target: Array<any>

    The collection to which an event is raised.

  • changes: CollectionChange

    A Sys.CollectionChange object that contains the list of changes that were performed on the collection since the last event.

public static raiseEvent(target: any, eventName: string, eventArgs: EventArgs)

Raises an observable event on the target.

Parameters

  • target: any

    The target object.

  • eventName: string

    A string that contains the event name.

  • eventArgs: EventArgs

    A Sys.EventArgs object used to pass event argument information.

public static raisePropertyChanged(target: any, propertyName: string)

Raises a propertyChanged notification event.

Parameters

  • target: any

    The object to which an event is raised.

  • propertyName: string

    The name of the property that changed.

public static remove(target: Array<any>, item: any): boolean

Removes the first occurrence of an item from the array in an observable manner.

Parameters

  • target: Array<any>

    The array to which the item will be removed.

  • item: any

    The item to remove.

Returns

boolean

true if the item is found in the array. Otherwise false.

public static removeAt(target: Array<any>, index: number)

Removes the item at the specified index from the array in an observable manner.

Parameters

  • target: Array<any>

    The array to which an item is removed.

  • index: number

    A number that represents the index of the item to remove.

public static removeCollectionChanged(target: any, handler: Function)

Removes the collectionChanged event handler from the target.

Parameters

  • target: any

    The array from which the collectionChanged event handler is removed.

  • handler: Function

    The function to remove.

public static removeEventHandler(target: any, handler: Function)

Removes a propertyChanged event handler from the target.

Parameters

  • target: any

    The object to observe.

  • handler: Function

    The event handler to remove.

public static setValue(target: any, propertyName: string, value: any)

Sets a property or field on the target in an observable manner. The raisePropertyChanged method is called after the setValue method set the value of the target object property.

Parameters

  • target: any

    The object to which the property is set.

  • propertyName: string

    A string that contains the name of the property or field to set.

  • value: any

    The value to set.