polymer_ajax_backed_model_behavior 0.0.2

  • README.md
  • Installing
  • Versions
  • 31


Pub Travis

A Dart Polymer behavior that provides a Polymer element with a model derived from an ajax request.


First, make your model class implement AjaxBackedModel and its abstract method setFromJsonString. This method handles deserialization of JSON into an existing instance of the model.

Next, create a Polymer element that will utilize the model, by implementing AjaxBackedModelBehavior. The element must implement get modelInstance which returns an instance of the model class above.

With the above wiring, the polymer element gains additional attributes which simplify its use. For example:

<my-element auto-load ajax-url="http://mydomain/api/data.json"></my-element>

With the usage above, the json returned from data.json will be converted to the model object and assigned to the "ajaxModel" attribute when the element is readied. The element's html can reference model data as [[ajaxModel.myField]].


  • file 
  • result in the model being updated with the result of a new ajax 
  •  where it is not necessary to look up the model via ajax


AjaxBackedModelBehavior may fire the following three events

  • ajax-model-request, detail: String containing url
  • ajax-model-response, detail: AjaxBackedModel
  • ajax-model-error, detail: Map containing 'status' and 'statusText'

Changing the model attribute name

If desired, the model attribute name can be changed from the default ("ajaxModel"). Override the method get modelName. See example.

Future improvements

I would like to provide a @AjaxModel annotation, and create a transformer automatically provide the wiring described above.


The following code illustrates a simple example of a model and a custom Polymer element using it an ajax backed model.

class Country extends Object with AjaxBackedModel, JsProxy {

  @reflectable int id;
  @reflectable String name;


  setFromJsonString(String json) {
    id = o['id'];
    name = o['country'];

class CountryDetail extends PolymerElement with AjaxBackedModelBehavior {

  CountryDetail.created() : super.created();

  AjaxBackedModel get modelInstance => new Country();


An full example can be found in the example directory and run via pub serve example or viewed online


To run on dartium (default): pub run test As usual, tests can be run on other platforms with -p<platform>

To run tests as javascript, the pub serve and test execution must be performed separately. Run pub serve test --port=8080 from one terminal and pub run test -pchrome --pub-serve=8080 from a second.

Note that tests are specifically blocked from running on Firefox currently in order to utilize Travis CI.

Use this package as a library

1. Depend on it

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

  polymer_ajax_backed_model_behavior: "^0.0.2"

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:polymer_ajax_backed_model_behavior/polymer_ajax_backed_model_behavior.dart';
Version Uploaded Documentation Archive
0.0.2 Aug 31, 2016 Go to the documentation of polymer_ajax_backed_model_behavior 0.0.2 Download polymer_ajax_backed_model_behavior 0.0.2 archive
0.0.1 Aug 31, 2016 Go to the documentation of polymer_ajax_backed_model_behavior 0.0.1 Download polymer_ajax_backed_model_behavior 0.0.1 archive


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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


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


Detected platforms: web

Primary library: package:polymer_ajax_backed_model_behavior/polymer_ajax_backed_model_behavior.dart with components: html.


  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Package is getting outdated.

    The package was released 97 weeks ago.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 2 hints.

    Run dartfmt to format lib/ajax_backed_model.dart.

    Run dartfmt to format lib/polymer_ajax_backed_model_behavior.dart.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use polymer_ajax_backed_model_behavior.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.13.0 <2.0.0
dart_to_js_script_rewriter ^1.0.1 1.0.3
polymer ^1.0.0-rc.16 1.0.0-rc.19
Transitive dependencies
analyzer 0.29.5 0.32.3
args 0.13.7 1.4.3
async 2.0.7
barback 0.15.2+16
charcode 1.1.2
cli_util 0.1.3
code_transformers 0.5.1+5
collection 1.14.10
convert 2.0.1
crypto 2.0.6
csslib 0.14.4
dart_style 0.2.16 1.1.2
glob 1.1.6
html 0.13.3+1
initialize 0.6.2+7
isolate 0.2.3 2.0.1
logging 0.11.3+1
meta 1.1.5
package_config 1.0.3
path 1.6.1
plugin 0.2.0+2
polymer_interop 1.0.0-rc.10
pool 1.3.5
reflectable 1.0.3 2.0.1
source_maps 0.10.6
source_span 1.4.0
stack_trace 1.9.2
string_scanner 1.0.2
typed_data 1.1.5
utf 0.9.0+4
watcher 0.9.7+9
web_components 0.12.5
yaml 2.1.14
Dev dependencies
polymer_elements ^1.0.0-rc.8
test ^0.12.5+1