| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 part of observe; |
| 6 |
| 7 /** |
| 8 * Forwards an observable property from one object to another. For example: |
| 9 * |
| 10 * class MyModel extends ObservableBase { |
| 11 * StreamSubscription _sub; |
| 12 * MyOtherModel _otherModel; |
| 13 * |
| 14 * MyModel() { |
| 15 * ... |
| 16 * _sub = bindProperty(_otherModel, const Symbol('value'), |
| 17 * () => notifyProperty(this, const Symbol('prop')); |
| 18 * } |
| 19 * |
| 20 * String get prop => _otherModel.value; |
| 21 * set prop(String value) { _otherModel.value = value; } |
| 22 * } |
| 23 * |
| 24 * See also [notifyProperty]. |
| 25 */ |
| 26 StreamSubscription bindProperty(Observable source, Symbol sourceName, |
| 27 void callback()) { |
| 28 return source.changes.listen((records) { |
| 29 for (var record in records) { |
| 30 if (record.changes(sourceName)) { |
| 31 callback(); |
| 32 } |
| 33 } |
| 34 }); |
| 35 } |
| OLD | NEW |