for my Polymer application I need one observable in two different flavors, for example as an integer-value and and string-value. I use getters and setters to encapsulate the state and internal representation. By doing this I have to implement notifyPropertyChange for every observable in every setter, which leads to much errorprone plumbing code. For example I need two times to notifyPropertyChange-Statements for two flavors, if I have to use 4 flavors, I have to use 4*4 = 16 notifyPropertyChange-Statements. I have modified the click-counter example to illustrate this:
@CustomTag('click-counter')
class ClickCounter extends PolymerElement {
int _count;
@observable int get count => _count;
@observable set count(int val) {
notifyPropertyChange(#count,_count,val);
_count = notifyPropertyChange(#strcount,_count,val);}
@observable String get strcount {
print("TOSTRING "+_count.toString());
return _count.toString();}
@observable set strcount(String val) {
notifyPropertyChange(#strcount,_count,int.parse(val));
_count = notifyPropertyChange(#count,_count,int.parse(val));}
ClickCounter.created() : super.created() {
}
void increment() {
count++;
}
}
Is there a better way to implement this without so much notifyPropertyChange-Statements?
Regards
Markus