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
Get a hash code for this object.…
A representation of the runtime type of the object.
The equality operator.…
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 changes. Typically this will perform dirty-checking, if any is needed.
Invoked when a non-existent method or property is accessed.…
Initiates observation and returns the initial value.
The callback will be called with the updated value
.…
Returns a string representation of this object.