dart-archive / observe

Support for marking objects as observable, and getting notifications when those objects are mutated
https://pub.dartlang.org/packages/observe
BSD 3-Clause "New" or "Revised" License
13 stars 6 forks source link

transformer generated setter missing original metadata #73

Open Ticore opened 9 years ago

Ticore commented 9 years ago

issue find in stackoverflow

Wrong decode() from redstone_mapper about observable object in web app

original class:

class User extends Object with ChangeNotifier {
  @Field()
  @observable
  String username;
  @Field()
  @observable
  String password;
  toString() => 'User("$username", "$password");';
}

transformer generated:

class User extends Object with ChangeNotifier {
  @reflectable @Field()
  @observable
  String get username => __$username; String __$username; @reflectable set username(String value) { __$username = notifyPropertyChange(#username, __$username, value); }
  @reflectable @Field()
  @observable
  String get password => __$password; String __$password; @reflectable set password(String value) { __$password = notifyPropertyChange(#password, __$password, value); }
  toString() => 'User("$username", "$password");';
}

@Field() metadata missing in generated setter

sigmundch commented 9 years ago

Patches are welcome :)

I'd prefer that rather than always adding it to the setter, to only do it if you specify a flag in the pubspec.yaml file, though. In particular, the current behavior is by design (see https://github.com/dart-lang/observe/blob/master/lib/transformer.dart#L368), because most of the time only getters need the annotation. This indirectly helps reduce some redundant metadata dart2js would preserve for a deployed app.

Another alternative, could redstone_mapper to use the annotation from the getter in their automatic encode/decode logic?