0
是否可以在不使用聚合物库的情况下观察Dart中的变量和/或集合?我可以在没有聚合物的飞镖中观察变量吗?
是否可以在不使用聚合物库的情况下观察Dart中的变量和/或集合?我可以在没有聚合物的飞镖中观察变量吗?
是的,你可以使用观察包装:http://pub.dartlang.org/packages/observe
我建了一个前一阵子,似乎一个例子仍然工作
import 'package:observe/observe.dart';
class Notifiable extends Object with ChangeNotifier {
String _input = '';
@reflectable
get input => _input;
@reflectable
set input(val) {
_input = notifyPropertyChange(#input, _input, val + " new");
}
Notifiable() {
this.changes.listen((List<ChangeRecord> record) => record.forEach(print));
}
}
class MyObservable extends Observable {
@observable
String counter = '';
MyObservable() {
this.changes.listen((List<ChangeRecord> record) => record.forEach(print));
}
}
void main() {
var x = new MyObservable();
x.counter = "hallo";
Observable.dirtyCheck();
Notifiable notifiable = new Notifiable();
notifiable.input = 'xxx';
notifiable.input = 'yyy';
}