Reputation: 75
I have a computed property which is dependent on A and B:
@computedFrom(A, B)
get property() {
}
The property is used in element which has repeat.for
(5 elements in total):
<element repeat.for 1 to 5 elementProperty=$"{property}">
</element>
When value A
changes, I would expect property()
to be called just once, and all elements updated with the new value.
But property()
is called 6 times.
Why?
Edit: When I do this...
<template repeat.for 1 to 5>
<element elementProperty=$"{property}"></element>
</template>
...property()
is called 6 times too.
Is this how it should work?
Upvotes: 3
Views: 611
Reputation: 8047
If you have a repeat.for, then the source property of any bindings in it is called for each child element that is rendered. This is normal behavior as they are all separate binding instances.
If your binding source changes, all binding targets (in this case 6) need to be updated and that happens by calling the source property. Computed bindings tend to be such simple computations that this is generally not an issue.
If your computed bindings are computationally expensive, you might want to consider using a property observer for the dependent properties and simply setting the computed property when any of them change, rather than letting the binding engine call it on binding.
EDIT
To clarify: this doesn't really have anything to do with computedFrom
. A non-computed property would also be read 6 times but there is no getter to hook the debugger on, so you can't see that directly.
Upvotes: 2