Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: packages/observe/lib/src/observer_transform.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/observe/lib/src/observable_map.dart ('k') | packages/observe/lib/src/path_observer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/observe/lib/src/observer_transform.dart
diff --git a/packages/observe/lib/src/observer_transform.dart b/packages/observe/lib/src/observer_transform.dart
deleted file mode 100644
index 7fab5551cd577991f394ef129ccd4a69656422a9..0000000000000000000000000000000000000000
--- a/packages/observe/lib/src/observer_transform.dart
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library observe.src.observer_transform;
-
-import 'package:observe/observe.dart';
-
-/// 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
-///
-class ObserverTransform extends Bindable {
- Bindable _bindable;
- Function _getTransformer, _setTransformer;
- Function _notifyCallback;
- var _value;
-
- ObserverTransform(Bindable bindable, computeValue(value), {setValue(value)})
- : _bindable = bindable,
- _getTransformer = computeValue,
- _setTransformer = setValue;
-
- open(callback) {
- _notifyCallback = callback;
- _value = _getTransformer(_bindable.open(_observedCallback));
- return _value;
- }
-
- _observedCallback(newValue) {
- final value = _getTransformer(newValue);
- if (value == _value) return null;
- _value = value;
- return _notifyCallback(value);
- }
-
- void close() {
- if (_bindable != null) _bindable.close();
- _bindable = null;
- _getTransformer = null;
- _setTransformer = null;
- _notifyCallback = null;
- _value = null;
- }
-
- get value => _value = _getTransformer(_bindable.value);
-
- set value(newValue) {
- if (_setTransformer != null) {
- newValue = _setTransformer(newValue);
- }
- _bindable.value = newValue;
- }
-
- deliver() => _bindable.deliver();
-}
« no previous file with comments | « packages/observe/lib/src/observable_map.dart ('k') | packages/observe/lib/src/path_observer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698