dart - How do you create custom Polymer and PolymerDart annotations? -


i doing research polymerdart , various annotations can applied dart files. it: @property, @property, @observe, @reflectable, @polymerregister, or @htmlimport.

so, started concept of dart , how make annotations them. saw on stackoverflow can this.

class datatable {   final string name;   const datatable(this.name); } 

which can additional information inside constructor optionally.

class datatable {   final string name;   const datatable(this.name) {     console.log("$name referenced.");   } } 

so, can create , implement variety of annotations leverage, starts fishy.

i curious if there way create annotations polymerdart? locked down, or can there way create ones simple functions, maybe example: creating annotation executes @property(computed:"") functionality.

i wanted create sort of customization our team use.

for record, know can like

const mycustomannotation = const property(); 

which allow me do:

@mycustomannotation 

i thinking like:

class mycustomcomputed extends property {   final string functionname;   const mycustomcomputed() : property(computed: this.functionname); } 

to allow me like:

@mycustomcomputed("testfunction(vara)") 

this big topic, brief answer is, yes, describe technically possible not trivial.

dart annotations available @ runtime via reflection, used pub transformers during build process. purpose of transformer modify assets (e.g. dart code) new form before runtime.

the polymer annotations mentioned above handled polymer transformer. transformer handles identifying annotations mentioned above , automatically rewriting annotated code include necessary implementations , wiring such behaves expect polymer elements.

so there's nothing stopping defining own annotations , transformers, including build upon existing polymer transformers, , packaging own or others' use.

i note though complex topic (ref polymer transformer) , there seem few simple code-rewriting transformer examples build on.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -