Fallenreaper
Fallenreaper

Reputation: 10704

a property which observers another property?

I have a changing property.

@property Model selected;

After that, created another property to put in the markup, to toggle disabled based on a property of Model.

@property bool get isDeleted => selected.deleted;

but it seems that isDeleted doesnt change in the markup.

<my-element disabled$="{{isDeleted}}"></my-element>

I checked with both values so disabled works as intended but isDeleted doesnt update I am thinking.

That being said, can i add an observer to isDeleted to observe selected, or would i need to create a function and do a computed property instead of shorthand

@Property(observer:"selected") bool get isDeleted => ! selected.deleted;

or should i do something akin to:

@Property(computed:"toggle(selected)") bool isDeleted;

@reflectable bool toggle(Model m) => !m.deleted;

I tried to do computed based on a property, but it needs a function, therefore, I cant use shorthand.

Upvotes: 0

Views: 51

Answers (1)

Fallenreaper
Fallenreaper

Reputation: 10704

What i endedup doing was:

@property Model selected;
@property bool isDeleted

@Observe("selected")
toggle(selected){
  set("isDeleted", !selected.deleted);
}

Upvotes: 1

Related Questions