pub repository
mirror.p-hatan.irobservable
0.20.2Support for marking objects as observable
This package is discontinued upstream.
Readme
Support for detecting and being notified when an object is mutated.
An observable is a way to be notified of a continuous stream of events over time.
Some suggested uses for this library:
- Observe objects for changes, and log when a change occurs
- Optimize for observable collections in your own APIs and libraries instead of diffing
- Implement simple data-binding by listening to streams
You may want to look at the former TC39 proposal Observe.observe, which was deprecated.
Usage
There are two general ways to detect changes:
- Listen to
Observable.changesand be notified when an object changes - Use
Differ.diffto determine changes between two objects
Examples
Operations on Lists:
import 'package:observable/observable.dart';
void main() {
var changes;
ObservableList<String> list = new ObservableList<String>.from(['a', 'b', 'c']);
StreamSubscription sub = list.listChanges.listen((c) => changes = c);
ListChangeRecord _delta(
int index, {
List removed: const [],
int addedCount: 0,
}) {
return new ListChangeRecord(
list,
index,
removed: removed,
addedCount: addedCount,
);
}
list.insertAll(1, ['y', 'z']); // changes == [_delta(1, addedCount: 2)]
}
Diffing two maps:
import 'package:observable/observable.dart';
void main() {
final map1 = {
'key-a': 'value-a',
'key-b': 'value-b-old',
};
final map2 = {
'key-a': 'value-a',
'key-b': 'value-b-new',
};
var diffResult = diff(map1,
map2); // [ new MapChangeRecord('key-b', 'value-b-old', 'value-b-new')]
}
Diffing two sets:
import 'package:observable/observable.dart';
void main() {
diff(
new Set<String>.from(['a', 'b']),
new Set<String>.from(['a']),
); // [ new SetChangeRecord.remove('b') ]
}
Changelog
0.20.3
- Bug fix: Avoid emitting an empty list via
ObservableList.listChanges
0.20.2
- Bug fix: Avoid emitting a no-op
MapChangeRecord - Bug fix: Restore
ObservableList.discardListChangesfunctionality
0.20.1
- Add
Observable<List|Set|Map>.unmodifiablefor immutable collections - Add
Observable<List|Set|Map>.EMPTYfor empty immutable collections- This can be used as an optimization for libraries that always need to return an observable collection, but don't want to allocate a new instance to represent an empty immutable.
0.20.0
- Add
ObservableSet,SetChangeRecord, andSetDiffer
0.19.0
- Refactor and deprecate
ObservableMap-specific APIObservableMapno longer emits#keysand#valueschange recordsObservableMap.spyis deprecated, becomes.delegateinstead
- Potentially breaking:
ObservableMapmay no longer be extended
It is also considered deprecated to be notified of length changes.
0.18.1
- Bug fix: Do not throw when
Observable<T>.notifyChangeis used
0.18.0
- Refactor and deprecate
ObservableList-specific APIObservableList.applyChangeRecordsObservableList.calculateChangeRecordsObservableList.withLengthObservableList.deliverListChangesObservableList.discardListChangesObservableList.hasListChangesObservableList.listChangesObservableList.notifyListChange
- Potentially breaking:
ObservableListmay no longer be extended
It is also considered deprecated to be notified of length, isEmpty
and isNotEmpty PropertyChangeRecords on ObservableList - in a
future release ObservableList.changes will be
Stream<List<ListChangeRecord>>.
0.17.0+1
- Revert
PropertyChangeMixin, which does not work in dart2js
0.17.0
This is a larger change with a goal of no runtime changes for current
customers, but in the future Observable will become a very
lightweight interface, i.e.:
abstract class Observable<C extends ChangeRecord> {
Stream<List<C>> get changes;
}
- Started deprecating the wide
ObservableinterfaceChangeNotifiershould be used as a base class for these methods:Observable.observedObservable.unobservedObservable.hasObserversObservable.deliverChangesObservable.notifyChange
PropertyChangeNotifiershould be used for these methods:Observable.notifyPropertyChange
- Temporarily,
ObservableusesChangeNotifier- Existing users of anything but
implements Observableshould move to implementing or extendingChangeNotifier. In a future releaseObservablewill reduce API surface down to an abstractStream<List<C>> get changes.
- Existing users of anything but
- Added the
ChangeNotifierandPropertyChangeNotifierclasses- Can be used to implement
Observablein a generic manner
- Can be used to implement
- Observable is now
Observable<C extends ChangeRecord>- When passing a generic type
C,notifyPropertyChangeis illegal
- When passing a generic type
0.16.0
- Refactored
MapChangeRecord- Added equality and hashCode checks
- Added
MapChangeRecord.applyto apply a change record
- Added
MapDiffer, which implementsDifferfor aMap
0.15.0+2
- Fix a bug in
ListDifferthat caused aRangeError
0.15.0+1
- Fix analysis errors caused via missing
/*<E>*/syntax in0.15.0
0.15.0
- Added the
Differinterface, as well asEqualityDiffer - Refactored list diffing into a
ListDiffer - Added concept of
ChangeRecord.ANYandChangeRecord.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.applyto apply a change record
- Added missing
@overrideannotations to satisfyannotate_overrides
0.14.0+1
- Add a missing dependency on
pkg/meta.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add observablepubspec.yaml
name: observable
version: 0.20.2
author: Dart Team <misc@dartlang.org>
description: Support for marking objects as observable
homepage: https://github.com/dart-lang/observable
environment:
sdk: '>=1.21.0 <2.0.0'
dependencies:
collection: '^1.11.0'
meta: '^1.0.4'
quiver: '^0.24.0'
dev_dependencies:
dart_style: '^0.2.0'
test: '^0.12.17'
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.1.0 | 2014-06-06T16:41:32.001090Z | Download | d6fdf1e65de6103941a7377d4d268d4147c47850536b70850be8686a4bb8282f |
| 0.1.1 | 2014-06-06T17:10:06.910100Z | Download | 8aa5feb72be0bfdb8d344ddd2da3dd13a2630da5e71dc40c8e30ba020fbeb59b |
| 0.1.2 | 2014-06-06T18:12:36.721340Z | Download | 79d8074f5f771078c368508b836584dbce4a2d5b74cb80800d4cb03cc14950c2 |
| 0.1.3 | 2014-06-08T15:07:06.198290Z | Download | 142ddf0b61a4b653bda1a28a22ed2a57bfa21620f21daacee603a7087e875ba5 |
| 0.1.4 | 2014-06-08T15:08:37.263640Z | Download | ac8da8a48ed40a2c169ed49135b277897a5c710f101bf88884f6477f0f144080 |
| 0.1.5 | 2014-06-11T12:09:08.919140Z | Download | aed2d42592befd39e1ca321631118d99538dff6bbfcc8fab70bcb3fac6df37d2 |
| 0.1.6 | 2014-06-11T13:46:07.823640Z | Download | 98674349a58d899c16c21927b0b625c7299e9b35872150a92f8727a74a0200c7 |
| 0.14.0 | 2016-09-23T20:48:35.289Z | Download | c5fc18c79e862c880c604568ac949e427d82214098f250d890ec824461940996 |
| 0.14.0+1 | 2016-09-26T17:05:37.029Z | Download | 549d63f721775224e229510760304766448b02c62c48f248192ea3a3c36aed9b |
| 0.15.0+1 | 2016-11-17T01:37:36.985Z | Download | d8427a2b87da22a818d2b4e1b37c7f45775e26e0ccfbd63884c1d85a4a945111 |
| 0.16.0 | 2016-11-17T18:32:04.548Z | Download | b8abdac0b1ac8b296a961f6ae24247ec15a30755b734b68f67d1bf8394e87ff7 |
| 0.17.0 | 2016-11-17T23:17:29.180Z | Download | 01328f5b4c877837d64440daf0e8c343a122948689d195708953d4dad0cf013b |
| 0.17.0+1 | 2016-11-21T18:59:50.788Z | Download | 8a6c6e21e1a5fc032fc49cfc28c5c3574962dbed3252d8570a5b1e4174c73025 |
| 0.18.0 | 2016-11-22T04:50:21.072Z | Download | be648ac636727693806487e7e07a640665336fd2dff97582c5fcbd9e7ed70876 |
| 0.18.1 | 2016-11-22T20:16:21.692Z | Download | 44e76715dee5848404d4c1d6b0a39333f6f791d8c7c48e2bb4abc2204995dfbd |
| 0.19.0 | 2016-11-23T01:31:07.467Z | Download | 371d4356dc92f71a004c71301fecb5237f43dff5e1f789ff79edc844078c0cde |
| 0.20.1 | 2016-11-29T03:07:45.483Z | Download | ba572ba1f5f11072e7109490ce416cb1338528c54a8561cadf154fe2d630397e |
| 0.20.2 | 2016-12-20T07:22:32.443Z | Download | b9b4f7107089afb58f73346ddf9da4e64e56a02e62b729694c0129e484cc9d06 |
| 0.20.4 | 2017-02-25T04:21:45.913Z | Download | d6308bf35fc8803fed7e026fc991cf2ad4e02be63055a15eac9a2c51b3761d63 |
| 0.20.4+1 | 2017-04-04T20:02:29.019802Z | Download | 5382b3f529e69b44888baaa595eca60127290b4d26c223fd996a2d6561b71933 |
| 0.20.4+2 | 2017-12-27T18:49:28.130687Z | Download | 375870ad899a83138014f715c4031785445bcc0860b010ab08523e3ceb37b61e |
| 0.20.4+3 | 2018-01-09T01:26:36.225295Z | Download | 898df861aa2c37614f81e00d5da4e6e50496a925f16a81a7e49b1ed5967df464 |
| 0.21.0 | 2018-02-12T18:09:51.151116Z | Download | ebb9ff4bd8b957ef2bc102e1e604b04cab48b2ca9fcf5873854feae1c87d8a99 |
| 0.21.1 | 2018-03-01T02:04:09.492545Z | Download | 60c73ae870a0f001a23ce12678d815f3b932032763413d1bb15bd514af169301 |
| 0.21.2 | 2018-03-07T23:28:47.382783Z | Download | ad3b0443325a0f10ca328555bd68d287f27d06d1a81b1abb065ccf413353957e |
| 0.21.3 | 2018-03-13T16:59:28.153540Z | Download | f4e963b40cd0b460122a958ff77ccf97597a85e39cfab0b7303d9437a5c8f6b0 |
| 0.22.0 | 2018-03-19T17:07:57.288351Z | Download | a7722c1d562039d433cb6b8cd257d6bc784d26ce044725409065d16136dc124a |
| 0.22.1 | 2018-03-23T23:29:35.934828Z | Download | 2a88d6c6182bb1cc3d95841ff40a6f2bd54e527f76b21693d32680ea127f5f9f |
| 0.22.1+1 | 2018-05-03T16:19:13.923304Z | Download | 631b89955023d9dd0a456cd21de780259bc759bbe98277fe7a1ebc6b6bb41e6f |
| 0.22.1+2 | 2018-05-18T22:13:21.263251Z | Download | cb24c2888248a842710be263b9a981eba24563c6fd8351c08cc3b52b5ac765a7 |
| 0.22.1+3 | 2018-05-25T17:11:35.455328Z | Download | dda14d0c17ef7846f748aca2c8cdf388f326cc1b66bd963779d0f20cce267692 |
| 0.22.1+4 | 2018-07-23T18:41:54.734062Z | Download | e45aeef60f47c2696b36718b383aad7cef9a7b252dcb6d16df6261906e96b957 |
| 0.22.1+5 | 2018-12-10T22:17:15.043501Z | Download | a99d958c8483e369da3ab6832148364dc73fc22f6ee6c9792cbc8ecae7964e27 |
| 0.22.2 | 2019-02-05T22:26:59.772301Z | Download | bb74db48ca45dc26ae0e3f15334e2bd844ceacc23a31e9c18045df311833129f |
| 0.23.0 | 2021-03-23T17:30:12.296140Z | Download | 72aeca9b76959826ca380bfe2517bc21a6a25d56f41ab620f1421728ffa5e564 |
| 0.24.0 | 2021-12-01T23:27:45.159724Z | Download | 6be2c1236cd4130a0e752895b0d3dee6d438d4c0b6775b8fe5808cf981aa9a70 |
Dependencies
collection "^1.11.0"
meta "^1.0.4"
quiver "^0.24.0"