observable 0.22.1+5

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 84

Build Status

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.changes and be notified when an object changes
  • Use Differ.diff to determine changes between two objects

0.22.1+5

Fix generic type error that occurs when using ChangeNotifier with a subclass of ChangeRecord. Previously, calling notifyChanges() on class Foo with ChangeNotifier<CustomChangeRecord> {} would throw a type error. Now, the changes stream emits a custom ChangeRecords class that implements the List interface. This change is backwards compatible.

0.22.1+4

  • Support Dart 2 stable.

  • Bump and widen dev dependencies on build packages.

0.22.1+3

Update implementations of the cast() and the deprecated retype() methods.

  • The retype() method on List and Map is deprecated and will be removed.
  • The cast() method should do what the retype() method did.

0.22.1+2

  • Widen dependency on quiver to include v0.29.

0.22.1+1

  • Fixes for Dart2 runtime type errors.

0.22.1

  • Added ObservableList.castFrom, similar to List.castFrom.

  • Changed ObservableList's cast and retype function to create a forwarding instance of ObservableList instead of an instance of List.

0.22.0

  • Added ObservableMap.castFrom, similar to Map.castFrom.

  • Fixed a bug where ObservableMap's cast and retype function would create a new empty instance instead of a forwarding instance.

0.21.3

  • Support Dart 2 collection methods where previously threw UnimplementedError.

0.21.2

  • Fix toObservable(deep: false) to be shallow again.
  • Remove use of Maps, for better compatibility with Dart 2.

0.21.1

  • Updated one test to comply with Dart 2 voidness semantics.
  • Fix Dart 2 runtime cast failure in toObservable().
  • Loosen ObservableList.from() to take Iterable, not Iterable<T>. This matches List.from() and avoids some unnecessary cast failures.

0.21.0

Breaking Changes

Version 0.21.0 reverts to version 0.17.0+1 with fixes to support Dart 2. Versions 0.18, 0.19, and 0.20 were not used by the package authors and effectively unsupported. This resolves the fork that happened at version 0.18 and development can now be supported by the authors.

Reverted Changes

(From 0.20.1)

  • Revert add Observable<List|Set|Map>.unmodifiable for immutable collections
  • Revert add Observable<List|Set|Map>.EMPTY for 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.

(From 0.20.0)

  • Revert add ObservableSet, SetChangeRecord, and SetDiffer

(From 0.19.0)

  • Revert refactor and deprecate ObservableMap-specific API
    • ObservableMap no longer emits #keys and #values change records
    • ObservableMap.spy is deprecated, becomes .delegate instead
  • Revert Potentially breaking: ObservableMap may no longer be extended

Revert considered deprecated to be notified of length changes.

(From 0.18.0)

  • Revert refactor and deprecate ObservableList-specific API
    • ObservableList.applyChangeRecords
    • ObservableList.calculateChangeRecords
    • ObservableList.withLength
    • ObservableList.deliverListChanges
    • ObservableList.discardListChanges
    • ObservableList.hasListChanges
    • ObservableList.listChanges
    • ObservableList.notifyListChange
  • Revert potentially breaking: ObservableList may no longer be extended

Revert considered deprecated to be notified of length, isEmpty and isNotEmpty PropertyChangeRecords on ObservableList

Changes Applied on top of version 0.17.0+1

(With internal change numbers)

  • Flip deliverChanges from @protected to @visibleForTesting. cl/147029982
  • Fix a typing bug in observable when running with DDC: ChangeRecord.NONE creates a List<ChangeRecord>, while the call sites expect a List<ListChangeRecord> or List<MapChangeRecord>, respectively. cl/155201160
  • Fix Observable._isNotGeneric check. cl/162282107
  • Fix issue with type in deliverChanges. cl/162493576
  • Stop using the comment syntax for generics. cl/163224019
  • Fix ListChangeRecord's added getter. Add checks for the added and removed getters in listChangeTests. cl/169261086.
  • Migrate observable to real generic method syntax. cl/170239122
  • Fix only USES_DYNAMIC_AS_BOTTOM error in observable. cl/179946618
  • Cherry pick https://github.com/dart-lang/observable/pull/46.
  • Stub out Dart 2 core lib changes in ObservableMap.
  • Removed Observable{List|Map}.NONE (not Dart2 compatible).
  • Fix issue with type in ObservableList._notifyListChange. cl/182284033

0.20.4+3

  • Support the latest release of pkg/quiver (0.27).

0.20.4+2

  • Support the latest release of pkg/quiver (0.26).
  • Bug fix: Some minor type fixes for strict runtimes (and Dart 2.0), namely:
    • PropertyChangeNotifier merely extends ChangeNotifier rather than extends ChangeNotifier<PropertyChangeRecord>.
    • Introduce new ListChangeRecord.NONE and MapChangeRecord.NONE.

0.20.4+1

  • Support the latest release of pkg/quiver (0.25).

0.20.4

  • Bug fix: Additional fix around ObservableList.listChanges

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.discardListChanges functionality

0.20.1

  • Add Observable<List|Set|Map>.unmodifiable for immutable collections
  • Add Observable<List|Set|Map>.EMPTY for 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, and SetDiffer

0.19.0

  • Refactor and deprecate ObservableMap-specific API
    • ObservableMap no longer emits #keys and #values change records
    • ObservableMap.spy is deprecated, becomes .delegate instead
  • Potentially breaking: ObservableMap may 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>.notifyChange is used

0.18.0

  • Refactor and deprecate ObservableList-specific API
    • ObservableList.applyChangeRecords
    • ObservableList.calculateChangeRecords
    • ObservableList.withLength
    • ObservableList.deliverListChanges
    • ObservableList.discardListChanges
    • ObservableList.hasListChanges
    • ObservableList.listChanges
    • ObservableList.notifyListChange
  • Potentially breaking: ObservableList may 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 Observable interface
    • ChangeNotifier should be used as a base class for these methods:
      • Observable.observed
      • Observable.unobserved
      • Observable.hasObservers
      • Observable.deliverChanges
      • Observable.notifyChange
    • PropertyChangeNotifier should be used for these methods:
      • Observable.notifyPropertyChange
    • Temporarily, Observable uses ChangeNotifier
      • Existing users of anything but implements Observable should move to implementing or extending ChangeNotifier. In a future release Observable will reduce API surface down to an abstract Stream<List<C>> get changes.
  • Added the ChangeNotifier and PropertyChangeNotifier classes
    • Can be used to implement Observable in a generic manner
  • Observable is now Observable<C extends ChangeRecord>
    • When passing a generic type C, notifyPropertyChange is illegal

0.16.0

  • Refactored MapChangeRecord
    • Added equality and hashCode checks
    • Added MapChangeRecord.apply to apply a change record
  • Added MapDiffer, which implements Differ for a Map

0.15.0+2

  • Fix a bug in ListDiffer that caused a RangeError

0.15.0+1

  • Fix analysis errors caused via missing /*<E>*/ syntax in 0.15.0

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.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  observable: ^0.22.1+5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:observable/observable.dart';
  
Version Uploaded Documentation Archive
0.22.1+5 Dec 10, 2018 Go to the documentation of observable 0.22.1+5 Download observable 0.22.1+5 archive
0.22.1+4 Jul 23, 2018 Go to the documentation of observable 0.22.1+4 Download observable 0.22.1+4 archive
0.22.1+3 May 25, 2018 Go to the documentation of observable 0.22.1+3 Download observable 0.22.1+3 archive
0.22.1+2 May 18, 2018 Go to the documentation of observable 0.22.1+2 Download observable 0.22.1+2 archive
0.22.1+1 May 3, 2018 Go to the documentation of observable 0.22.1+1 Download observable 0.22.1+1 archive
0.22.1 Mar 23, 2018 Go to the documentation of observable 0.22.1 Download observable 0.22.1 archive
0.22.0 Mar 19, 2018 Go to the documentation of observable 0.22.0 Download observable 0.22.0 archive
0.21.3 Mar 13, 2018 Go to the documentation of observable 0.21.3 Download observable 0.21.3 archive
0.21.2 Mar 7, 2018 Go to the documentation of observable 0.21.2 Download observable 0.21.2 archive
0.21.1 Mar 1, 2018 Go to the documentation of observable 0.21.1 Download observable 0.21.1 archive

All 33 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
91
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on Dec 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:observable/observable.dart.

Health suggestions

Fix lib/src/observable_map.dart. (-7.24 points)

Analysis of lib/src/observable_map.dart reported 15 hints, including:

line 105 col 10: 'hasObservers' is deprecated and shouldn't be used.

line 116 col 7: 'notifyPropertyChange' is deprecated and shouldn't be used.

line 117 col 7: 'notifyChange' is deprecated and shouldn't be used.

line 120 col 7: 'notifyChange' is deprecated and shouldn't be used.

line 136 col 9: 'hasObservers' is deprecated and shouldn't be used.

Fix lib/src/observable_list.dart. (-1.99 points)

Analysis of lib/src/observable_list.dart reported 4 hints:

line 110 col 8: 'deliverChanges' is deprecated and shouldn't be used.

line 318 col 5: 'notifyPropertyChange' is deprecated and shouldn't be used.

line 319 col 5: 'notifyPropertyChange' is deprecated and shouldn't be used.

line 320 col 5: 'notifyPropertyChange' is deprecated and shouldn't be used.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use observable.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.55.0 <3.0.0
collection ^1.11.0 1.14.11
dart_internal ^0.1.1 0.1.2
meta ^1.0.4 1.1.6
quiver >=0.24.0 <3.0.0 2.0.1
Transitive dependencies
matcher 0.12.4
path 1.6.2
stack_trace 1.9.3
Dev dependencies
build_runner >=0.8.0 <2.0.0
build_test ^0.10.0
build_web_compilers >=0.3.1 <2.0.0
dart_style ^1.0.9
test ^1.3.0