Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Unified Diff: pkg/observe/lib/src/change_notifier.dart

Issue 20631002: [pkg:observe] Add support for explicit change notification, even on dirty-checked objects (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: revert pubspec Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/observe/lib/src/observable.dart » ('j') | pkg/observe/lib/src/observable.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/observe/lib/src/change_notifier.dart
diff --git a/pkg/observe/lib/src/change_notifier.dart b/pkg/observe/lib/src/change_notifier.dart
index 9e54f60811c5c6e2e956a27f038cdbfacfabde26..8102ab0c7110b3ca5f2f4bdafb197e7360e32c0d 100644
--- a/pkg/observe/lib/src/change_notifier.dart
+++ b/pkg/observe/lib/src/change_notifier.dart
@@ -5,22 +5,8 @@
part of observe;
/**
- * Interface representing an [Observable] object that performs its own change
+ * Base class implementing [Observable] object that performs its own change
* notifications, and does not need to be considered by [Observable.dirtyCheck].
- */
-abstract class ChangeNotifier extends Observable {
- /**
- * Notify observers of a change.
- *
- * For most objects [ChangeNotifierMixin.notifyPropertyChange] is more
- * convenient, but collections sometimes deliver other types of changes such
- * as a [ListChangeRecord].
- */
- void notifyChange(ChangeRecord record);
-}
-
-/**
- * Base class implementing [ChangeNotifier].
*
* When a field, property, or indexable item is changed, a derived class should
* call [notifyPropertyChange]. See that method for an example.
@@ -28,12 +14,13 @@ abstract class ChangeNotifier extends Observable {
typedef ChangeNotifierBase = Object with ChangeNotifierMixin;
/**
- * Mixin for implementing [ChangeNotifier] objects.
+ * Mixin implementing [Observable] object that performs its own change
+ * notifications, and does not need to be considered by [Observable.dirtyCheck].
*
* When a field, property, or indexable item is changed, a derived class should
* call [notifyPropertyChange]. See that method for an example.
*/
-abstract class ChangeNotifierMixin implements ChangeNotifier {
+abstract class ChangeNotifierMixin implements Observable {
StreamController _changes;
List<ChangeRecord> _records;
@@ -62,8 +49,7 @@ abstract class ChangeNotifierMixin implements ChangeNotifier {
var records = _records;
_records = null;
if (hasObservers && records != null) {
- // TODO(jmesserly): make "records" immutable
- _changes.add(records);
+ _changes.add(new UnmodifiableListView<ChangeRecord>(records));
return true;
}
return false;
@@ -91,14 +77,8 @@ abstract class ChangeNotifierMixin implements ChangeNotifier {
* const Symbol('myField'), _myField, value);
* }
*/
- // TODO(jmesserly): should this be == instead of identical, to prevent
- // spurious loops?
- notifyPropertyChange(Symbol field, Object oldValue, Object newValue) {
- if (hasObservers && !identical(oldValue, newValue)) {
- notifyChange(new PropertyChangeRecord(field));
- }
- return newValue;
- }
+ notifyPropertyChange(Symbol field, Object oldValue, Object newValue)
+ => _notifyPropertyChange(this, field, oldValue, newValue);
void notifyChange(ChangeRecord record) {
if (!hasObservers) return;
« no previous file with comments | « no previous file | pkg/observe/lib/src/observable.dart » ('j') | pkg/observe/lib/src/observable.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698