-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor List diffing/change records, add diffing interface (#5)
* Refactor our a differ/list differ. * Fix bugs in mergeSplice * More fixes to the list differ. * Some debugging. * More fixes. * Fix remaining edge case missed. * Slight cleanups before PR * Update README * Add license headers.
- Loading branch information
1 parent
eaafa82
commit 010bcd7
Showing
19 changed files
with
767 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
## 0.15.0 | ||
|
||
* Added the `Differ` interface, as well as `EqualityDiffer` | ||
* Refactored list diffing into a `ListDiffer` | ||
* Added concept of `ChangeRecord.ANY` and `ChangeRecord.NONE` | ||
* Low-GC ways to expression "something/nothing" changed | ||
* Refactored `ListChangeRecord` | ||
* Added named constructors for common use cases | ||
* Added equality and hashCode checks | ||
* Added `ListChangeRecord.apply` to apply a change record | ||
* Added missing `@override` annotations to satisfy `annotate_overrides` | ||
|
||
## 0.14.0+1 | ||
|
||
* Add a missing dependency on `pkg/meta`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
Support for marking objects as observable, and getting notifications when those | ||
objects are mutated. | ||
Support for detecting and being notified when an object is mutated. | ||
|
||
This library is used to observe changes to observable types. It also | ||
has helpers to make implementing and using observable objects easy. | ||
There are two general ways to detect changes: | ||
|
||
* Listen to `Observable.changes` and be notified when an object changes | ||
* Use `Differ.diff` to determine changes between two objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2016, 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. | ||
|
||
library observable.src.differs; | ||
|
||
import 'dart:math' as math; | ||
|
||
import 'package:collection/collection.dart'; | ||
|
||
import 'records.dart'; | ||
|
||
part 'differs/list_differ.dart'; | ||
|
||
/// Generic comparisons between two comparable objects. | ||
abstract class Differ<E> { | ||
/// Returns a list of change records between [e1] and [e2]. | ||
/// | ||
/// A return value of an empty [ChangeRecord.NONE] means no changes found. | ||
List<ChangeRecord> diff(E e1, E e2); | ||
} | ||
|
||
/// Uses [Equality] to determine a simple [ChangeRecord.ANY] response. | ||
class EqualityDiffer<E> implements Differ<E> { | ||
final Equality<E> _equality; | ||
|
||
const EqualityDiffer([this._equality = const DefaultEquality()]); | ||
|
||
const EqualityDiffer.identity() : this._equality = const IdentityEquality(); | ||
|
||
@override | ||
List<ChangeRecord> diff(E e1, E e2) { | ||
return _equality.equals(e1, e2) ? ChangeRecord.NONE : ChangeRecord.ANY; | ||
} | ||
} |
Oops, something went wrong.