Chromium Code Reviews| Index: sdk/lib/observe/observe.dart |
| diff --git a/sdk/lib/observe/observe.dart b/sdk/lib/observe/observe.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3a21d64213f3f4527b399ff874d33c91bd2c544c |
| --- /dev/null |
| +++ b/sdk/lib/observe/observe.dart |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +/** |
| + * *Warning*: this library is experimental, and APIs are subject to change. |
| + * |
| + * This library is used to observe changes to [Observable] types. It also |
|
Lasse Reichstein Nielsen
2013/05/06 10:58:58
I think the Observable name is too generic.
This i
Jennifer Messerly
2013/05/07 05:43:38
It's intended for all observable objects. List and
|
| + * has helpers to implement [Observable] objects. |
| + * |
| + * For example: |
| + * |
| + * class Monster extends ObservableMixin { |
|
floitsch
2013/05/06 17:37:46
As written in the other file: I don't like to exte
Jennifer Messerly
2013/05/07 05:43:38
Done.
|
| + * int _health = 100; |
| + * static const _HEALTH = 'health'; |
| + * get health => _health; |
| + * set health(value) { |
| + * _health = notifyChange(_HEALTH, _health, value); |
| + * } |
| + * void damage(int amount) { |
| + * print('$this takes $amount damage!'); |
| + * health -= amount; |
| + * } |
| + * toString() => 'Monster'; |
| + * |
| + * // These methods are temporary until dart2js supports mirrors. |
| + * getValue(key) { |
| + * if (key == _HEALTH) return health; |
| + * return null; |
| + * } |
| + * setValue(key, val) { |
| + * if (key == _HEALTH) health = val; |
| + * } |
| + * } |
| + * |
| + * main() { |
| + * var obj = new Monster(); |
| + * obj.changes.listen((records) { |
| + * print('Changes to $obj were: $records'); |
| + * }); |
| + * // Asynchronously schedules delivery of these changes |
|
Lasse Reichstein Nielsen
2013/05/06 10:58:58
"Schedules asynchronous ..."?
(Nitpick - the sche
Jennifer Messerly
2013/05/07 05:43:38
Done.
|
| + * obj.damage(10); |
| + * obj.damage(20); |
| + * print('done!'); |
| + * } |
| + */ |
| +library dart.observe; |
| + |
| +import 'dart:async'; |
| +import 'dart:collection'; |
| +import 'dart:math' as math; |
| + |
| +part 'list_diff.dart'; |
| +part 'observe_path.dart'; |
| +part 'observable.dart'; |
| +part 'observable_box.dart'; |
| +part 'observable_list.dart'; |
| +part 'observable_map.dart'; |