eredo / dartson

Dartson is a Dart library that can be used to convert Dart objects into a JSON string.
MIT License
79 stars 29 forks source link

dartson and polymer observable #25

Closed pjjjv closed 9 years ago

pjjjv commented 9 years ago

Dartson works on this example class, but when I add extends Observable and @observable, it stops working. The object is just null. How to fix this?

Here is the modified example code:


@Entity()
class EntityClass extends Observable{
  @observable String name;
  String _setted;

  @Property(name:"renamed")
  bool otherName;

  @Property(ignore:true)
  String notVisible;

  List<EntityClass> children;

  set setted(String s) => _setted = s;
  String get setted => _setted;

  EntityClass();

  factory EntityClass.fromJson(string){
    var dson = new Dartson.JSON();
    EntityClass object = dson.decode(string, new EntityClass());
    return object;
  }
}
pjjjv commented 9 years ago

My config:

dependencies: browser: '>=0.10.0 <0.11.0'

firebase: '>=0.5.1 <0.6.0'

firebase: path: ../firebase-dart dartson: "^0.2.3" paper_elements: '>=0.7.0 <0.8.0' polymer: '>=0.16.0 <0.17.0' transformers:

You can find my test project at https://github.com/pjjjv/test_arrays_binding/blob/a96ae100dffb009665f6c17006b0d4156f02bc31/lib/pane_edit.dart

eredo commented 9 years ago

After some digging I found a solution which is as simple as switching the order of the transformers array. Put dartson in front of polymer.

Your pubspec.yaml should look like this:

name: 'test_arrays_binding'
version: 0.0.1
description: A web app built using polymer.dart.
environment:
  sdk: '>=1.0.0 <2.0.0'
dependencies:
  browser: '>=0.10.0 <0.11.0'
  paper_elements: '>=0.7.0 <0.8.0'
  polymer: '>=0.16.0 <0.17.0'
  dartson: '>=0.2.3 <0.3.0'
transformers:
- dartson
- polymer:
    entry_points: web/index.html

That causes the CodeTransformer for the @observable annotation to be called after dartson has created it's mapping methods which will then use the getter and setter methods created by the Observable CodeTransformer instead of the private properties (__$...) created by the Observable CodeTransformer.

I'm thinking about a proper warning message or detection for these cases.

pjjjv commented 9 years ago

Thanks, I'll look into it and try converting my project