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
I have not tested it, but it should work and I think its notable less code if you have more such properties.
@CustomTag('click-counter')
class ClickCounter extends PolymerElement {
int _count;
@observable int get count => _count;
set count(int val) {
notifyPropertyChange(#count,_count,val);
notifyPropertyChange(#strcount, _count.toString(), val.toString());
_count = val;
@observable String get strcount {
// print("TOSTRING "+_count.toString());
return _count.toString();}
set strcount(String val) {
count = int.parse(val); // set the new value using the setter not the field to fire property change
}
ClickCounter.created() : super.created();
void increment() {
count++;
}
}