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

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

Issue 27618002: package:observe fix various api issues (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | « pkg/observe/lib/src/change_notifier.dart ('k') | pkg/observe/lib/src/compound_binding.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/observe/lib/src/change_record.dart
diff --git a/pkg/observe/lib/src/change_record.dart b/pkg/observe/lib/src/change_record.dart
index 99e806ddb373b56d528f884d74be91dd7413badc..bb584e8f427aa2e35f0e9dc612a774094e0c21c8 100644
--- a/pkg/observe/lib/src/change_record.dart
+++ b/pkg/observe/lib/src/change_record.dart
@@ -5,22 +5,41 @@
part of observe;
/** Records a change to an [Observable]. */
-abstract class ChangeRecord {
- // TODO(jmesserly): rename this--it's confusing. Perhaps "matches"?
- /** True if the change affected the given item, otherwise false. */
- bool changes(key);
-}
+// TODO(jmesserly): remove this type
+abstract class ChangeRecord {}
/** A change record to a field of an observable object. */
-class PropertyChangeRecord extends ChangeRecord {
- /** The field that was changed. */
- final Symbol field;
+class PropertyChangeRecord<T> extends ChangeRecord {
+ /**
+ * *Deprecated* use [name] instead.
+ * The field that was changed.
+ */
+ @deprecated
+ Symbol get field => name;
+
+ /** The object that changed. */
+ final object;
+
+ /** The name of the property that changed. */
+ final Symbol name;
- PropertyChangeRecord(this.field);
+ /** The previous value of the property. */
+ final T oldValue;
- bool changes(key) => key is Symbol && field == key;
+ /** The new value of the property. */
+ final T newValue;
- String toString() => '#<PropertyChangeRecord $field>';
+ PropertyChangeRecord(this.object, this.name, this.oldValue, this.newValue);
+
+ /*
+ * *Deprecated* instead of `record.changes(key)` simply do
+ * `key == record.name`.
+ */
+ @deprecated
+ bool changes(key) => key is Symbol && name == key;
+
+ String toString() =>
+ '#<PropertyChangeRecord $name from: $oldValue to: $newValue>';
}
/** A change record for an observable list. */
@@ -41,16 +60,23 @@ class ListChangeRecord extends ChangeRecord {
}
}
+ /**
+ * *Deprecated* use [indexChanged] instead.
+ * Returns true if the provided index was changed by this operation.
+ */
+ @deprecated
+ bool changes(value) => indexChanged(value);
+
/** Returns true if the provided index was changed by this operation. */
- bool changes(key) {
+ bool indexChanged(otherIndex) {
// If key isn't an int, or before the index, then it wasn't changed.
- if (key is! int || key < index) return false;
+ if (otherIndex is! int || otherIndex < index) return false;
// If this was a shift operation, anything after index is changed.
if (addedCount != removedCount) return true;
// Otherwise, anything in the update range was changed.
- return key < index + addedCount;
+ return otherIndex < index + addedCount;
}
String toString() => '#<ListChangeRecord index: $index, '
« no previous file with comments | « pkg/observe/lib/src/change_notifier.dart ('k') | pkg/observe/lib/src/compound_binding.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698