3

I need to do mapper between dart and JS object. I don't like to write "unncessary' code so I would like DartEditor wrote it for me :)

What i would like to write:

DartInvoice extends jsw.TypedProxy {
     @Parser(attributName="invoice")
     String number;
     @Parser(attributName=amount)
     Number sum;
}

What i would like to achieve:

DartInvoice extends jsw.TypedProxy {
     set number(String number) => toJs.set('invoice' : number);
     String number => toJs.get(invoice);
     set sum(Number sum) => toJs.set('amount' : sum);
     Number get sum => toJs.get(amount);
}

The question is :) how dart or dart editor can help me? Tell me what i should read. :)

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Bzik
  • 78
  • 7
  • [Custom build scripts](https://www.dartlang.org/tools/editor/build.html) might be a good place to start for things like this. – MarioP Nov 15 '13 at 09:56

1 Answers1

4

I started the js_wrapping_generator project to do something like that but its not quite ready for prime time. I used the analyzer package to parse dart files an generate other files.

You can have a look at dart_generator.dart to have a sample.

The current version is based on a simple AST and I'm working on a new version based on a resolved AST to simplify templating even more.

Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132
  • GREAT This is what i wanted to do :)) It would be great to have ability to change attribute name. For example when JS object has name that isn't appropriate for me. That's why I wanted to use annotations. THIS GONNA BE GREAT library for anyone who is porting js libraries to dart. Please, consider ability to change attribute / class names between JS and Dart object. – Bzik Nov 16 '13 at 15:35
  • Please [file an issue](https://github.com/a14n/dart-js-wrapping-generator/issues/new) to track this. – Alexandre Ardhuin Nov 18 '13 at 10:03