| Index: pkg/observe/lib/observe.dart
|
| diff --git a/pkg/observe/lib/observe.dart b/pkg/observe/lib/observe.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3ee6dc70b8d669860d69be71ba7668394b26c59e
|
| --- /dev/null
|
| +++ b/pkg/observe/lib/observe.dart
|
| @@ -0,0 +1,63 @@
|
| +// 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
|
| + * has helpers to implement [Observable] objects.
|
| + *
|
| + * For example:
|
| + *
|
| + * class Monster extends Object with ObservableMixin {
|
| + * static const _HEALTH = const Symbol('health');
|
| + *
|
| + * int _health = 100;
|
| + * get health => _health;
|
| + * set health(value) {
|
| + * _health = notifyChange(_HEALTH, _health, value);
|
| + * }
|
| + *
|
| + * void damage(int amount) {
|
| + * print('$this takes $amount damage!');
|
| + * health -= amount;
|
| + * }
|
| + *
|
| + * toString() => 'Monster with $health hit points';
|
| + *
|
| + * // These methods are temporary until dart2js supports mirrors.
|
| + * getValueWorkaround(key) {
|
| + * if (key == _HEALTH) return health;
|
| + * return null;
|
| + * }
|
| + * setValueWorkaround(key, val) {
|
| + * if (key == _HEALTH) health = val;
|
| + * }
|
| + * }
|
| + *
|
| + * main() {
|
| + * var obj = new Monster();
|
| + * obj.changes.listen((records) {
|
| + * print('Changes to $obj were: $records');
|
| + * });
|
| + * // Schedules asynchronous delivery of these changes
|
| + * obj.damage(10);
|
| + * obj.damage(20);
|
| + * print('done!');
|
| + * }
|
| + */
|
| +library observe;
|
| +
|
| +// Import the observe implementation library. It contains the types that are
|
| +// required to implement Model-Driven-Views in dart:html. Use package:observe
|
| +// (this package) if you need this functionality
|
| +// DO NOT import observe_impl in your code; it may break unpredictably.
|
| +import 'dart:observe_impl';
|
| +
|
| +// Re-export the observe implementation
|
| +export 'dart:observe_impl';
|
| +
|
| +part 'src/observable_box.dart';
|
| +part 'src/observable_list.dart';
|
| +part 'src/observable_map.dart';
|
|
|