enyo
enyo

Reputation: 16736

How to tell polymer dart that an attribute depends on another

I have a polymer element that has two properties, columWidth and columnWidthPercentage.

Now columnWidthPercentage is a getter like this:

@observable int columnWidth = 100;
@observable double get columnWidthPercentage => 100 * totalWidth / columnWidth;

Is there a way to tell Polymer that columnWidthPercentage depends on columnWidth without setting up a columnWidthChanged function that invoke notifyPropertyChange()?

Upvotes: 2

Views: 65

Answers (1)

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76363

You can use @ComputedProperty. Something like the following :

@observable
int columnWidth = 100;

@ComputedProperty('compute(columnWidth)')
double get columnWidthPercentage => readValue(#columnWidthPercentage);
double compute(int width) => 100 * totalWidth / width;

Upvotes: 2

Related Questions