| 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 /** | 7 /** |
| 8 * Use `@observable` to make a field automatically observable. | 8 * Use `@observable` to make a field automatically observable. |
| 9 */ | 9 */ |
| 10 const Object observable = const _ObservableAnnotation(); | 10 const Object observable = const _ObservableAnnotation(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 * will not schedule [deliverChanges]; use [Observable.dirtyCheck] instead. | 185 * will not schedule [deliverChanges]; use [Observable.dirtyCheck] instead. |
| 186 */ | 186 */ |
| 187 void notifyChange(ChangeRecord record) { | 187 void notifyChange(ChangeRecord record) { |
| 188 if (!hasObservers) return; | 188 if (!hasObservers) return; |
| 189 | 189 |
| 190 if (_records == null) _records = []; | 190 if (_records == null) _records = []; |
| 191 _records.add(record); | 191 _records.add(record); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 /** |
| 196 * Notify the property change. Shorthand for: |
| 197 * |
| 198 * target.notifyChange(new PropertyChangeRecord(targetName)); |
| 199 */ |
| 200 void notifyProperty(Observable target, Symbol targetName) { |
| 201 target.notifyChange(new PropertyChangeRecord(targetName)); |
| 202 } |
| 203 |
| 195 // TODO(jmesserly): remove the instance method and make this top-level method | 204 // TODO(jmesserly): remove the instance method and make this top-level method |
| 196 // public instead? | 205 // public instead? |
| 197 _notifyPropertyChange(Observable obj, Symbol field, Object oldValue, | 206 _notifyPropertyChange(Observable obj, Symbol field, Object oldValue, |
| 198 Object newValue) { | 207 Object newValue) { |
| 199 | 208 |
| 200 // TODO(jmesserly): should this be == instead of identical, to prevent | 209 // TODO(jmesserly): should this be == instead of identical, to prevent |
| 201 // spurious loops? | 210 // spurious loops? |
| 202 if (obj.hasObservers && !identical(oldValue, newValue)) { | 211 if (obj.hasObservers && !identical(oldValue, newValue)) { |
| 203 obj.notifyChange(new PropertyChangeRecord(field)); | 212 obj.notifyChange(new PropertyChangeRecord(field)); |
| 204 } | 213 } |
| 205 return newValue; | 214 return newValue; |
| 206 } | 215 } |
| 207 | 216 |
| 208 | 217 |
| 209 /** | 218 /** |
| 210 * The type of the `@observable` annotation. | 219 * The type of the `@observable` annotation. |
| 211 * | 220 * |
| 212 * Library private because you should be able to use the [observable] field | 221 * Library private because you should be able to use the [observable] field |
| 213 * to get the one and only instance. We could make it public though, if anyone | 222 * to get the one and only instance. We could make it public though, if anyone |
| 214 * needs it for some reason. | 223 * needs it for some reason. |
| 215 */ | 224 */ |
| 216 class _ObservableAnnotation { | 225 class _ObservableAnnotation { |
| 217 const _ObservableAnnotation(); | 226 const _ObservableAnnotation(); |
| 218 } | 227 } |
| OLD | NEW |