polymer_ajax_backed_model_behavior 0.0.2

  • README.md
  • Installing
  • Versions
  • 34

ajax-backed-model-behavior

Pub Travis

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

Usage

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]].

Attributes

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

Events

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.

Example

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;

  Country();

  setFromJsonString(String json) {
    id = o['id'];
    name = o['country'];
  }
}
@HtmlImport('country_detail.html')

@PolymerRegister('country-detail')
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

Testing

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.

1. Depend on it

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


dependencies:
  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

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

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

Platforms

Detected platforms: web

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

Suggestions

  • Maintain CHANGELOG.md.

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

  • 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.

Dependencies

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.31.1
args 0.13.7 1.4.2
async 2.0.6
barback 0.15.2+15
charcode 1.1.1
cli_util 0.1.2+1
code_transformers 0.5.1+4
collection 1.14.9
convert 2.0.1
crypto 2.0.2+1
csslib 0.14.1
dart_style 0.2.16 1.0.10
glob 1.1.5
html 0.13.3
initialize 0.6.2+7
isolate 0.2.3 2.0.0
logging 0.11.3+1
meta 1.1.2
package_config 1.0.3
path 1.5.1
plugin 0.2.0+2
polymer_interop 1.0.0-rc.10
pool 1.3.4
reflectable 1.0.3 2.0.0
source_maps 0.10.4
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+7
web_components 0.12.5
yaml 2.1.13
Dev dependencies
ghpages_generator
polymer_elements ^1.0.0-rc.8
test ^0.12.5+1