| 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 /** |
| (...skipping 24 matching lines...) Expand all Loading... |
| 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 |
| 41 * call [resolve] manually, avoiding the need for scheduling an asynchronous | 41 * call [resolve] manually, avoiding the need for scheduling an asynchronous |
| 42 * resolve. | 42 * resolve. |
| 43 */ | 43 */ |
| 44 // TODO(jmesserly): I don't like having this public, is the optimization | 44 // TODO(jmesserly): I don't like having this public, is the optimization |
| 45 // really needed? "runAsync" in Dart should be pretty cheap. | 45 // really needed? "scheduleMicrotask" in Dart should be pretty cheap. |
| 46 bool scheduled = false; | 46 bool scheduled = false; |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Creates a new CompoundBinding, optionally proving the [combinator] function | 49 * Creates a new CompoundBinding, optionally proving the [combinator] function |
| 50 * for computing the value. You can also set [schedule] to true if you plan | 50 * for computing the value. You can also set [schedule] to true if you plan |
| 51 * to invoke [resolve] manually after initial construction of the binding. | 51 * to invoke [resolve] manually after initial construction of the binding. |
| 52 */ | 52 */ |
| 53 CompoundBinding([CompoundBindingCombinator combinator]) { | 53 CompoundBinding([CompoundBindingCombinator combinator]) { |
| 54 // TODO(jmesserly): this is a tweak to the original code, it seemed to me | 54 // TODO(jmesserly): this is a tweak to the original code, it seemed to me |
| 55 // that passing the combinator to the constructor should be equivalent to | 55 // that passing the combinator to the constructor should be equivalent to |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 _values.remove(name); | 94 _values.remove(name); |
| 95 if (!suppressResolve) _scheduleResolve(); | 95 if (!suppressResolve) _scheduleResolve(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // TODO(rafaelw): Is this the right processing model? | 98 // TODO(rafaelw): Is this the right processing model? |
| 99 // TODO(rafaelw): Consider having a seperate ChangeSummary for | 99 // TODO(rafaelw): Consider having a seperate ChangeSummary for |
| 100 // CompoundBindings so to excess dirtyChecks. | 100 // CompoundBindings so to excess dirtyChecks. |
| 101 void _scheduleResolve() { | 101 void _scheduleResolve() { |
| 102 if (scheduled) return; | 102 if (scheduled) return; |
| 103 scheduled = true; | 103 scheduled = true; |
| 104 runAsync(resolve); | 104 scheduleMicrotask(resolve); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void resolve() { | 107 void resolve() { |
| 108 if (_observers.isEmpty) return; | 108 if (_observers.isEmpty) return; |
| 109 scheduled = false; | 109 scheduled = false; |
| 110 | 110 |
| 111 if (_combinator == null) { | 111 if (_combinator == null) { |
| 112 throw new StateError( | 112 throw new StateError( |
| 113 'CompoundBinding attempted to resolve without a combinator'); | 113 'CompoundBinding attempted to resolve without a combinator'); |
| 114 } | 114 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 126 for (var binding in _observers.values) { | 126 for (var binding in _observers.values) { |
| 127 binding.cancel(); | 127 binding.cancel(); |
| 128 } | 128 } |
| 129 _observers.clear(); | 129 _observers.clear(); |
| 130 _values.clear(); | 130 _values.clear(); |
| 131 value = null; | 131 value = null; |
| 132 } | 132 } |
| 133 | 133 |
| 134 _unobserved() => close(); | 134 _unobserved() => close(); |
| 135 } | 135 } |
| OLD | NEW |