| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of observe; | 5 part of observe; |
| 6 | 6 |
| 7 /** The callback used in the [CompoundBinding.combinator] field. */ | 7 /** The callback used in the [CompoundBinding.combinator] field. */ |
| 8 typedef Object CompoundBindingCombinator(Map objects); | 8 typedef Object CompoundBindingCombinator(Map objects); |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * CompoundBinding is an object which knows how to listen to multiple path | 11 * CompoundBinding is an object which knows how to listen to multiple path |
| 12 * values (registered via [bind]) and invoke its [combinator] when one or more | 12 * values (registered via [bind]) and invoke its [combinator] when one or more |
| 13 * of the values have changed and set its [value] property to the return value | 13 * of the values have changed and set its [value] property to the return value |
| 14 * of the function. When any value has changed, all current values are provided | 14 * of the function. When any value has changed, all current values are provided |
| 15 * to the [combinator] in the single `values` argument. | 15 * to the [combinator] in the single `values` argument. |
| 16 * | 16 * |
| 17 * For example: | 17 * For example: |
| 18 * | 18 * |
| 19 * var binding = new CompoundBinding((values) { | 19 * var binding = new CompoundBinding((values) { |
| 20 * var combinedValue; | 20 * var combinedValue; |
| 21 * // compute combinedValue based on the current values which are provided | 21 * // compute combinedValue based on the current values which are provided |
| 22 * return combinedValue; | 22 * return combinedValue; |
| 23 * }); | 23 * }); |
| 24 * binding.bind('name1', obj1, path1); | 24 * binding.bind('name1', obj1, path1); |
| 25 * binding.bind('name2', obj2, path2); | 25 * binding.bind('name2', obj2, path2); |
| 26 * //... | 26 * //... |
| 27 * binding.bind('nameN', objN, pathN); | 27 * binding.bind('nameN', objN, pathN); |
| 28 */ | 28 */ |
| 29 // TODO(jmesserly): rename to something that indicates it's a computed value? | 29 // TODO(jmesserly): rename to something that indicates it's a computed value? |
| 30 class CompoundBinding extends ChangeNotifierBase { | 30 class CompoundBinding extends ChangeNotifier { |
| 31 CompoundBindingCombinator _combinator; | 31 CompoundBindingCombinator _combinator; |
| 32 | 32 |
| 33 // TODO(jmesserly): ideally these would be String keys, but sometimes we | 33 // TODO(jmesserly): ideally these would be String keys, but sometimes we |
| 34 // use integers. | 34 // use integers. |
| 35 Map<dynamic, StreamSubscription> _observers = new Map(); | 35 Map<dynamic, StreamSubscription> _observers = new Map(); |
| 36 Map _values = new Map(); | 36 Map _values = new Map(); |
| 37 Object _value; | 37 Object _value; |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * True if [resolve] is scheduled. You can set this to true if you plan to | 40 * True if [resolve] is scheduled. You can set this to true if you plan to |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 for (var binding in _observers.values) { | 124 for (var binding in _observers.values) { |
| 125 binding.cancel(); | 125 binding.cancel(); |
| 126 } | 126 } |
| 127 _observers.clear(); | 127 _observers.clear(); |
| 128 _values.clear(); | 128 _values.clear(); |
| 129 value = null; | 129 value = null; |
| 130 } | 130 } |
| 131 | 131 |
| 132 _unobserved() => close(); | 132 _unobserved() => close(); |
| 133 } | 133 } |
| OLD | NEW |