class ObserverTransform


ObserverTransform is used to dynamically transform observed value(s).

var obj = new ObservableBox(10); var observer = new PathObserver(obj, 'value'); var transform = new ObserverTransform(observer,

   (x) => x * 2, setValue: (x) => x ~/ 2);

// Open returns the current value of 20. transform.open((newValue) => print('new: $newValue'));

obj.value = 20; // prints 'new: 40' async new Future(() {

 transform.value = 4; // obj.value will be 2

});

ObserverTransform can also be used to reduce a set of observed values to a single value:

var obj = new ObservableMap.from({'a': 1, 'b': 2, 'c': 3}); var observer = new CompoundObserver()

 ..addPath(obj, 'a')
 ..addPath(obj, 'b')
 ..addPath(obj, 'c');

var transform = new ObserverTransform(observer,

   (values) => values.fold(0, (x, y) => x + y));

// Open returns the current value of 6. transform.open((newValue) => print('new: $newValue'));

obj'a' = 2; obj'c' = 10; // will print 'new 14' asynchronously

Inheritance

Constructors

ObserverTransform(Bindable bindable, dynamic computeValue(value), {dynamic setValue(value)})

Properties

hashCode → int

Get a hash code for this object.

read-only, inherited
runtimeType → Type

A representation of the runtime type of the object.

read-only, inherited
value → dynamic

read / write

Operators

operator ==(other) → bool

The equality operator.

inherited

Methods

close() → void

Stops future notifications and frees the reference to the callback passed to open, so its memory can be collected even if this Bindable is alive.

deliver() → dynamic

Deliver changes. Typically this will perform dirty-checking, if any is needed.

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
open(callback) → dynamic

Initiates observation and returns the initial value. The callback will be called with the updated value.

toString() → String

Returns a string representation of this object.

inherited