autonotify_observe 1.0.0+14

  • README.md
  • Installing
  • Versions
  • 0

Auto notify support for (yet to be released) polymer-dart 1.0

a.k.a. : get rid of all those fancy set, add, remove, etc. calls

the problem

In polymer 1.0 you have to call a bunch of API (set and list accessor methods) on the polymer component whenever you have to apply a change on the model instead of changing the model directly. To make things worse if you have two or more independent components, for example two different views of the same model that are not inheriting the model one from the other by means of binding constructs (i.e. {{ }} or [[ ]]), then you will have to call those API on each of component.

Other then being very annoying this makes nearly impossible to follow consolidated patterns like MVC when building an app using vanilla polymer 1.0 : infact the controller (C) should always interact directly with the view (V) to update the model (M).

The opposite is true for polymer before 1.0 and that's one of the reason many appreciated that framework even though it was slower and less browser independent.

enters autonotify

This package will add support for autonotify in polymer-dart 1.0, making it possible to write your code more or less in the same way you used to do with previous polymer version.

how it works

You just have to annotate properties with @observable and extend/mixin the familiar Observable mixin, exactly like for previous polymer version, and polymer_autnotify will take care of calling polymer accessor API automatically for you.

The model

Any class you intend to use as a model object should be extend or mixin Observable. Any property you want to be available for unidirectional or bidirectional binding should be annotatated by @observable. For example:


import "package:observe/observe.dart";

class MyModel extends Observable {
 @observable String field1;
 @observable AnotherModel field2;
}

class AnotherModel extends Object with Observable {
 @observable String field3;
}

The element

Your polymer element should be defined as usual and mixin both AutonotifyBehavior and Observable, properties should be annotated both with @observable and @property (or @Property(...)). Use ObservableList for mutable collections :

...
import "package:polymer_autonotify/polymer_autonotify.dart" show AutonotifyBehavior;

@PolymerRegister("my-element")
class MyElement extends PolymerElement with AutonotifyBehavior,Observable {
 @observable @property List<MyModel> prop1  = new ObservableList();
 @observable @property String prop2;
 
 
 MyElement.created() : super.created();

 @reflectable
 void doChange1([_,__]) {
  prop1.add(new MyModel());
 }
 
 @reflectable
 void doChange2([ev,__]) {
   new DomRepeatModel.fromEvent(convertFromJs(ev))["item"].field2="hello!";
 }

}

Notice : you do not have to call list API accessor neither set method, just update the model and the bidings will get updated, but this should not be a big surprise after all it is all this package is all about.

using the transformer

To enable observability you have to add the autonotify_observe transformer to all you dart project that are using it (both your main application and any other libraries that your main application depends on and that will define model classes and/or polymer elements).

The transformer can be used in place of the polymer transformer, in that case your pubspec.yaml will be simple and like this:

...
transformers:
 - autonotify_observe:
    entry_points:
    - web/index.html

...

(entry points are those defined by the polymer transformer, see polymer documentations for that).

If you prefer to use the original polymer transformer then you can (as a matter of fact at the moment there is no reason for doing that, but anyway the choice is yours). In this case your pubspec.yaml should be like this:

...
transformers:
 - autonotify_observe
 - polymer:
    entry_points:
    - web/index.html

...

Just avoid to specify any entry_point for the autonotify_observe and enlist that transformer before polymer one.

As already stated before if your main app imports models classes or elements from other packages then you should declare the autonotify_observe also in the corresponding pubspec.yaml, like this:

...
transformers:
 - autonotify_observe
...

notes

autonotify_observe requires a modified observe library that you can find here. You do not have to explicitly declare a dependency because you will implicitly get it as a dependency of this package.

Use this package as a library

1. Depend on it

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


dependencies:
  autonotify_observe: ^1.0.0+14

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:autonotify_observe/autonotify_observe.dart';
  
Version Uploaded Documentation Archive
1.0.0+14 Jul 24, 2017 Go to the documentation of autonotify_observe 1.0.0+14 Download autonotify_observe 1.0.0+14 archive
1.0.0+10 Jul 18, 2016 Go to the documentation of autonotify_observe 1.0.0+10 Download autonotify_observe 1.0.0+10 archive
1.0.0+8 Jun 13, 2016 Go to the documentation of autonotify_observe 1.0.0+8 Download autonotify_observe 1.0.0+8 archive
1.0.0+7 Jan 14, 2016 Go to the documentation of autonotify_observe 1.0.0+7 Download autonotify_observe 1.0.0+7 archive
1.0.0+6 Jan 12, 2016 Go to the documentation of autonotify_observe 1.0.0+6 Download autonotify_observe 1.0.0+6 archive
1.0.0+5 Jan 12, 2016 Go to the documentation of autonotify_observe 1.0.0+5 Download autonotify_observe 1.0.0+5 archive
1.0.0+4 Jan 10, 2016 Go to the documentation of autonotify_observe 1.0.0+4 Download autonotify_observe 1.0.0+4 archive
1.0.0+3 Jan 10, 2016 Go to the documentation of autonotify_observe 1.0.0+3 Download autonotify_observe 1.0.0+3 archive
1.0.0+2 Jan 9, 2016 Go to the documentation of autonotify_observe 1.0.0+2 Download autonotify_observe 1.0.0+2 archive
1.0.0+1 Jan 9, 2016 Go to the documentation of autonotify_observe 1.0.0+1 Download autonotify_observe 1.0.0+1 archive

All 12 versions...

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

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0