observe 0.15.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 81

observe

Support for marking objects as observable, and getting notifications when those objects are mutated.

This library is used to observe changes to AutoObservable types. It also has helpers to make implementing and using [Observable][] objects easy.

You can provide an observable object in two ways. The simplest way is to use dirty checking to discover changes automatically:

import 'package:observe/observe.dart';
import 'package:observe/mirrors_used.dart'; // for smaller code

class Monster extends Unit with AutoObservable {
  @observable int health = 100;

  void damage(int amount) {
    print('$this takes $amount damage!');
    health -= amount;
  }

  toString() => 'Monster with $health hit points';
}

main() {
  var obj = new Monster();
  obj.changes.listen((records) {
    print('Changes to $obj were: $records');
  });
  // No changes are delivered until we check for them
  obj.damage(10);
  obj.damage(20);
  print('dirty checking!');
  Observable.dirtyCheck();
  print('done!');
}

Note: by default this package uses mirrors to access getters and setters marked with @reflectable. Dart2js disables tree-shaking if there are any uses of mirrors, unless you declare how mirrors are used (via the MirrorsUsed annotation).

As of version 0.10.0, this package doesn't declare @MirrorsUsed. This is because we intend to use mirrors for development time, but assume that frameworks and apps that use this pacakge will either generate code that replaces the use of mirrors, or add the @MirrorsUsed declaration themselves. For convenience, you can import package:observe/mirrors_used.dart as shown on the first example above. That will add a @MirrorsUsed annotation that preserves properties and classes labeled with @reflectable and properties labeled with @observable.

If you are using the package:observe/mirrors_used.dart import, you can also make use of @reflectable on your own classes and dart2js will preserve all of its members for reflection.

Tools exist to convert the first form into the second form automatically, to get the best of both worlds.

0.15.1

  • Update to use new analyzer API

0.14.0

  • Update to be built on top of package:observable. Contains the following breaking changes:
    • Observable now lives in package:observable and behaves like the old ChangeNotifier did (except that it's now the base class) - with subclasses manually notifying listeners of changes via notifyPropertyChange().
    • ChangeNotifier has been removed.
    • ObservableList has been moved to package:observable.
    • ObservableMap has been moved to package:observable.
    • toObservable() has been moved to package:observable.
    • Observable (the one with dirty checking) in package:observe has been renamed AutoObservable

0.13.5

  • Fixed strong mode errors and warnings

0.13.4

  • Fixed strong mode errors and warnings

0.13.3+1

  • Add support for code_transformers 0.4.x.

0.13.3

  • Update to the test package.

0.13.2

  • Update to analyzer '^0.27.0'.

0.13.1+3

  • Sorting an already sorted list will no longer yield new change notifications.

0.13.1+2

  • Update to analyzer '<0.27.0'

0.13.1+1

  • Update to logging <0.12.0.

0.13.1

  • Update to analyzer <0.26.0.

0.13.0+2

  • Fixed close in PathObserver so it doesn't leak observers.
  • Ported the benchmarks from observe-js.

0.13.0+1

  • Widen the constraint on analyzer.

0.13.0

  • Don't output log files by default in release mode, and provide option to turn them off entirely.
  • Changed the api for the ObserveTransformer to use named arguments.

0.12.2+1

  • Cleanup some method signatures.

0.12.2

0.12.1+1

  • Expand stack_trace version constraint.

0.12.1

  • Upgraded error messages to have a unique and stable identifier.

0.12.0

  • Old transform.dart file removed. If you weren't use it it, this change is backwards compatible with version 0.11.0.

0.11.0+5

  • Widen the constraint on analyzer.

0.11.0+4

  • Raise the lower bound on the source_maps constraint to exclude incompatible versions.

0.11.0+3

  • Widen the constraint on source_maps.

0.11.0+2

  • Widen the constraint on barback.

0.11.0+1

  • Switch from source_maps' Span class to source_span's SourceSpan class.

0.11.0

  • Updated to match observe-js#e212e74 (release 0.3.4), which also matches observe-js#fa70c37 (release 0.4.2).
  • ListPathObserver has been deprecated (it was deleted a while ago in observe-js). We plan to delete it in a future release. You may copy the code if you still need it.
  • PropertyPath now uses an expression syntax including indexers. For example, you can write a.b["m"] instead of a.b.m.
  • breaking change: PropertyPath no longer allows numbers as fields, you need to use indexers instead. For example, you now need to write a[3].d instead of a.3.d.
  • breaking change: PathObserver.value= no longer discards changes (this is in combination with a change in template_binding and polymer to improve interop with JS custom elements).

0.10.0+3

  • minor changes to documentation, deprecated discardListChages in favor of discardListChanges (the former had a typo).

0.10.0

  • package:observe no longer declares @MirrorsUsed. The package uses mirrors for development time, but assumes frameworks (like polymer) and apps that use it directly will either generate code that replaces the use of mirrors, or add the @MirrorsUsed declaration themselves. For convinience, you can import 'package:observe/mirrors_used.dart', and that will add a @MirrorsUsed annotation that preserves properties and classes labeled with @reflectable and properties labeled with @observable.
  • Updated to match observe-js#0152d54

1. Depend on it

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


dependencies:
  observe: "^0.15.1"

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 packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:observe/observe.dart';
        
Version Uploaded Documentation Archive
0.15.1 May 3, 2017 Go to the documentation of observe 0.15.1 Download observe 0.15.1 archive
0.15.0 Nov 21, 2016 Go to the documentation of observe 0.15.0 Download observe 0.15.0 archive
0.14.0 Sep 30, 2016 Go to the documentation of observe 0.14.0 Download observe 0.14.0 archive
0.13.5 Mar 25, 2016 Go to the documentation of observe 0.13.5 Download observe 0.13.5 archive
0.13.4 Jan 22, 2016 Go to the documentation of observe 0.13.4 Download observe 0.13.4 archive
0.13.3+1 Jan 20, 2016 Go to the documentation of observe 0.13.3+1 Download observe 0.13.3+1 archive
0.13.3 Dec 16, 2015 Go to the documentation of observe 0.13.3 Download observe 0.13.3 archive
0.13.2 Dec 15, 2015 Go to the documentation of observe 0.13.2 Download observe 0.13.2 archive
0.13.1+3 Dec 7, 2015 Go to the documentation of observe 0.13.1+3 Download observe 0.13.1+3 archive
0.13.1+2 Aug 19, 2015 Go to the documentation of observe 0.13.1+2 Download observe 0.13.1+2 archive

All 81 versions...

Analysis

This feature is new.
We welcome feedback.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Dec 6, 2017
  • Dart: 2.0.0-dev.8.0
  • pana: 0.7.3+1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
92
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
79
Overall score:
Weighted score of the above. [more]
81

Platforms

Detected platforms: Flutter, server, web

all of the above

Suggestions

  • Fix lib/src/dirty_check.dart.

    Strong-mode analysis of lib/src/dirty_check.dart failed with the following error:

    line: 129 col: 7
    The argument type '(Zone, ZoneDelegate, Zone, () → dynamic) → () → dynamic' can't be assigned to the parameter type '<R>(Zone, ZoneDelegate, Zone, () → R) → () → R'.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

Dependencies

Package Constraint Resolved Available
Direct dependencies
analyzer >=0.29.11 <0.30.0 0.29.11 0.30.0+4
barback >=0.14.2 <0.16.0 0.15.2+13
code_transformers >=0.4.2 <0.6.0 0.5.1+3
func >=0.1.0 <2.0.0 1.0.0
logging >=0.9.0 <0.12.0 0.11.3+1
observable >=0.17.0 <0.21.0 0.20.4+1
path >=0.9.0 <2.0.0 1.5.1
smoke >=0.1.0 <0.4.0 0.3.6+3
source_maps >=0.9.4 <0.11.0 0.10.4
source_span ^1.0.0 1.4.0
utf ^0.9.0 0.9.0+3
Transitive dependencies
args 0.13.7 1.2.0
async 1.13.3 2.0.1
charcode 1.1.1
cli_util 0.0.1+2 0.1.2+1
collection 1.14.3
convert 2.0.1
crypto 2.0.2+1
csslib 0.14.1
glob 1.1.5
html 0.13.2
isolate 1.1.0
matcher 0.12.1+4
meta 1.1.2
package_config 1.0.3
plugin 0.2.0+2
pool 1.3.3
quiver 0.25.0 0.26.2
string_scanner 1.0.2
typed_data 1.1.5
watcher 0.9.7+4
when 0.2.0
which 0.1.3
yaml 2.1.13
Dev dependencies
benchmark_harness >=1.0.0 <2.0.0
browser any
chart >=1.0.8 <2.0.0
stack_trace >=0.9.1 <2.0.0 1.9.1
test ^0.12.18+1