When true the value returned from the delegateGetter will be used even if it is undefined or null.
When true indicates that a value from delegateGetter should be stored.
Delegate function that can be called to return the value when the stored value is null.
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");
The value of 'this' to bind the handler to.
The handler function to execute when the value changes.
Clear the stored result. The delegate function will not be called until the next get().
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));
The other raw value or Observable to compare.
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?");
The value of 'this' inside of the handler.
The one-time handler to execute.
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();
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.
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());
The new value to set the Observable to.
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());
The Observable to synchronize this one with.
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());
The Observable to sync to.
The function that performs the desired transformation.
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?");
The token previously returned from a call to bind().
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.