Options
All
  • Public
  • Public/Protected
  • All
Menu

A variant of Observable that has a function which can be called to obtain the value, if no value is currently stored. That function is the delegate.

If cacheDelegateResults is true and the value is not undefined or null, that value will be stored. It will be returned on every get() until clear() is called.

If cacheDelegateNull is true even null or undefined values from the delegateGetter will be taken as the true value.

Type parameters

  • T

Hierarchy

Index

Constructors

constructor

  • new LazyObservable(value?: T, delegateGetter?: function, cacheDelegateResults?: boolean): LazyObservable
  • Parameters

    • Optional value: T
    • Optional delegateGetter: function
        • (): T
        • Returns T

    • Optional cacheDelegateResults: boolean

    Returns LazyObservable

Properties

Private bindingEvent

bindingEvent: GeocortexEvent

cacheDelegateNull

cacheDelegateNull: boolean

When true the value returned from the delegateGetter will be used even if it is undefined or null.

cacheDelegateResults

cacheDelegateResults: boolean

When true indicates that a value from delegateGetter should be stored.

delegateGetter

delegateGetter: function

Delegate function that can be called to return the value when the stored value is null.

Type declaration

    • (): T
    • Returns T

Methods

bind

  • bind(scope: any, handler: function): string
  • Binds an event handler to the binding event of this Observable. The event handler will be executed when the value of the Observable changes via a call to set(). A string token is returned that can be used to unbind the handler from the event.

    var property = new Observable();
    property.bind(this, function(value) {
        alert(value);
    });
    
    // Alerts "hello world"
    property.set("hello world");

    Parameters

    • scope: any

      The value of 'this' to bind the handler to.

    • handler: function

      The handler function to execute when the value changes.

        • (value: T): void
        • Parameters

          • value: T

          Returns void

    Returns string

clear

  • clear(): void
  • Clear the stored result. The delegate function will not be called until the next get().

    Returns void

equals

  • Compares the value of this Observable to the value of another object. If the other object is an Observable, its value will be used in the comparison.

    var a = new Observable("hello");
    var b = new Observable("hello");
    
    // Alerts "true"
    alert(a.equals(b));

    Parameters

    • other: T | Observable<T>

      The other raw value or Observable to compare.

    Returns boolean

get

  • get(): T

once

  • once(scope: any, handler: Function): string
  • Binds a one-time event handler to the Observable, unbinding it the next time the Observable fires.

    var property = new Observable();
    var token = property.once(this, function(value) {
        alert(value);
    });
    
    // Alerts "hello world"
    property.set("hello world");
    
    // Does not alert anything
    property.set("hello?");

    Parameters

    • scope: any

      The value of 'this' inside of the handler.

    • handler: Function

      The one-time handler to execute.

    Returns string

pulse

  • pulse(): void
  • Sets the Observable to its current value and fires the binding event.

    var property1 = new Observable("hello");
    property1.bind(this, function (value) {
        alert(value);
    });
    
    // Alerts "hello".
    property1.pulse();

    Returns void

removeSync

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

    Returns void

set

  • set(value: T): void
  • Sets the value of the Observable, raising the binding event and notifying any subscribers of the new value. Set() should always be used to modify Observable values.

    var property = new Observable("hello");
    
    // Updates the value and fires the binding event.
    property.set("hello world");
    
    // Alerts "hello world"
    alert(property.get());

    Parameters

    • value: T

      The new value to set the Observable to.

    Returns void

sync

  • Synchronizes this Observable to another Observable. When the other Observable changes, this Observable will be set to the same value, and the binding event raised. The value of this Observable will be set to the value of the other Observable upon synchronization.

    var property1 = new Observable("hello");
    var property2 = new Observable();
    
    property2.sync(property1);
    
    // Alerts "hello"
    alert(property2.get());
    
    property1.set("bye");
    
    // Alerts "bye"
    alert(property2.get());

    Parameters

    Returns void

syncTransform

  • syncTransform<U>(source: Observable<U>, transformation: function): void
  • Works the same as sync, but calls a transformation function every time the other Observable changes.

    var property1 = new Observable("hello");
    var property2 = new Observable();
    
    property2.syncTransform(property1, function (value) {
         return value.toUpperCase());
    });
    
    // Alerts "HELLO"
    alert(property2.get());
    
    property1.set("bye");
    
    // Alerts "BYE"
    alert(property2.get());

    Type parameters

    • U

    Parameters

    • source: Observable<U>

      The Observable to sync to.

    • transformation: function

      The function that performs the desired transformation.

        • (value: U): T
        • Parameters

          • value: U

          Returns T

    Returns void

unbind

  • unbind(token: string): boolean
  • Removes an event handler previously attached via bind(), given the token that bind() returned.

    var property = new Observable();
    var token = property.bind(this, function(value) {
        alert(value);
    });
    
    // Alerts "hello world"
    property.set("hello world");
    property.unbind(token);
    
    // Does not alert anything
    property.set("hello?");

    Parameters

    • token: string

      The token previously returned from a call to bind().

    Returns boolean

Static Private makeBindableProxy

  • makeBindableProxy(obj: any): any