| 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 /** |
| 6 * *Warning*: this library is experimental, and APIs are subject to change. |
| 7 * |
| 8 * This library is used to observe changes to [Observable] types. It also |
| 9 * has helpers to implement [Observable] objects. |
| 10 * |
| 11 * For example: |
| 12 * |
| 13 * class Monster extends Object with ObservableMixin { |
| 14 * static const _HEALTH = const Symbol('health'); |
| 15 * |
| 16 * int _health = 100; |
| 17 * get health => _health; |
| 18 * set health(value) { |
| 19 * _health = notifyChange(_HEALTH, _health, value); |
| 20 * } |
| 21 * |
| 22 * void damage(int amount) { |
| 23 * print('$this takes $amount damage!'); |
| 24 * health -= amount; |
| 25 * } |
| 26 * |
| 27 * toString() => 'Monster with $health hit points'; |
| 28 * |
| 29 * // These methods are temporary until dart2js supports mirrors. |
| 30 * getValueWorkaround(key) { |
| 31 * if (key == _HEALTH) return health; |
| 32 * return null; |
| 33 * } |
| 34 * setValueWorkaround(key, val) { |
| 35 * if (key == _HEALTH) health = val; |
| 36 * } |
| 37 * } |
| 38 * |
| 39 * main() { |
| 40 * var obj = new Monster(); |
| 41 * obj.changes.listen((records) { |
| 42 * print('Changes to $obj were: $records'); |
| 43 * }); |
| 44 * // Schedules asynchronous delivery of these changes |
| 45 * obj.damage(10); |
| 46 * obj.damage(20); |
| 47 * print('done!'); |
| 48 * } |
| 49 */ |
| 50 library observe; |
| 51 |
| 52 // Import the observe implementation library. It contains the types that are |
| 53 // required to implement Model-Driven-Views in dart:html. Use package:observe |
| 54 // (this package) if you need this functionality |
| 55 // DO NOT import observe_impl in your code; it may break unpredictably. |
| 56 import 'dart:observe_impl'; |
| 57 |
| 58 // Re-export the observe implementation |
| 59 export 'dart:observe_impl'; |
| 60 |
| 61 part 'src/observable_box.dart'; |
| 62 part 'src/observable_list.dart'; |
| 63 part 'src/observable_map.dart'; |
| OLD | NEW |