Autonotify is a nice native feature of oldest
dart-polymer (< 1.0) version that was since version 1.0.
The package autonotify_observe allowed to restore this feature for dart-polymer
autonotify_observe is an nice package but had some issues:
- in order to implement observability a transformer was used that instrumented all the annotated classes with code for property change detection
- you had to extend or mixin a particular class (
Observable) and annotate any property with
@observableannotation to make them observable
- a whole graph of objects mirroring the data model was created and maintained in order to observe paths and notify properties as soon you assign the model to a polymer component field
Since v. 0.8.5
polymerize has a built in support for autonotify. All you have to do is to mixin the
AutonotifyBehavior and voilà!
In particular :
- no need to extend a particular mixin for all your classes
- no need to annotated properties
Autonotify support for
polymerize leverages the
Proxy support of modern browser to implement object observability. So it doesn’t need to modify your classes and for that reason it is much faster than before.
Other than that an observed version of a property is created as soon as it is read from an already observed object. Thus observation is implmented “on demand” as soon as it is needed.
See the todo_demo for an example on how to use
But What is this autonotify after all ?
Ok, ok. For people who doesn’t know it here’s an explanation.
Polymer requires you to inform the framework when a property is modified in order to update the view. This is accomplished with the
For example if the propertiy
name of the field
user gets changed you have to inform polymer calling
notifyPath('user.name'). In the same way this holds for element in an list:
- when an item is added you should call
- when an item is deleted you should call
- .. and so on
Actually for all the first level properties this is automatically done for you by polymer by means of replacing all the properties with dedicated accessors that will call
notifyPath for you. And there are cases when this is done even for deeper properties (when they are bound to other components properties that has been declared with the
notify flag to true - annotated with
But : this doesn’t holds generally but more importantly if you change the property outside the context of your component it doesn’t get automatically notified (see autonotify_observe for more explanations).
autonotify support you can have all your properties automatically notified for you (hence the name) at the cost of simply adding a mixin (
AutonotifyBehavior) to your element declaration. This in practice means that you can forget all about the notify API and the list accessors API too.
This greatly simplify working with polymer and allows to implement a realt
MVC pattern in your polymer based application.