Chromium Code Reviews| 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 library observe.src.compound_path_observer; | 5 library observe.src.compound_path_observer; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'package:observe/observe.dart'; | 8 import 'package:observe/observe.dart'; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 // TODO(rafaelw): Consider having a seperate ChangeSummary for | 78 // TODO(rafaelw): Consider having a seperate ChangeSummary for |
| 79 // CompoundBindings so to excess dirtyChecks. | 79 // CompoundBindings so to excess dirtyChecks. |
| 80 void _scheduleResolve(_) { | 80 void _scheduleResolve(_) { |
| 81 if (_scheduled) return; | 81 if (_scheduled) return; |
| 82 _scheduled = true; | 82 _scheduled = true; |
| 83 scheduleMicrotask(_resolve); | 83 scheduleMicrotask(_resolve); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void _resolve() { | 86 void _resolve() { |
| 87 _scheduled = false; | 87 _scheduled = false; |
| 88 if (_observers.isEmpty) return; | |
|
Siggi Cherem (dart-lang)
2013/11/08 18:37:00
turns out that the schedule happens when there wer
| |
| 88 var newValue = _observers.map((o) => o.value).toList(); | 89 var newValue = _observers.map((o) => o.value).toList(); |
| 89 if (_computeValue != null) newValue = _computeValue(newValue); | 90 if (_computeValue != null) newValue = _computeValue(newValue); |
| 90 _value = notifyPropertyChange(#value, _value, newValue); | 91 _value = notifyPropertyChange(#value, _value, newValue); |
| 91 } | 92 } |
| 92 | 93 |
| 93 /** | 94 /** |
| 94 * Closes the observer. | 95 * Closes the observer. |
| 95 * | 96 * |
| 96 * This happens automatically if the [value] property is no longer observed, | 97 * This happens automatically if the [value] property is no longer observed, |
| 97 * but this can also be called explicitly. | 98 * but this can also be called explicitly. |
| 98 */ | 99 */ |
| 99 void close() { | 100 void close() { |
| 100 if (_observers.isEmpty) return; | 101 if (_observers.isEmpty) return; |
| 101 | 102 |
| 102 if (_started) { | 103 if (_started) { |
| 103 for (StreamSubscription sub in _subs) { | 104 for (StreamSubscription sub in _subs) { |
| 104 sub.cancel(); | 105 sub.cancel(); |
| 105 } | 106 } |
| 106 } | 107 } |
| 107 _observers.clear(); | 108 _observers.clear(); |
| 108 _subs.clear(); | 109 _subs.clear(); |
| 109 _value = null; | 110 _value = null; |
| 110 } | 111 } |
| 111 | 112 |
| 112 observed() => start(); | 113 observed() => start(); |
| 113 unobserved() => close(); | 114 unobserved() => close(); |
| 114 } | 115 } |
| OLD | NEW |