binding: computedFrom doesn't observe lists
In other words.
@computedFrom('filter', 'list')
get filteredList() {
// filter the list
}
list.splice(index, 1); // filteredList doesn't recompute
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 3
- Comments: 23 (11 by maintainers)
Even if the official solution is “use a value converter”, an error message would be much more valuable than the current approach of “try it in futility for an hour, google it and find this issue.” Can
@computedFrom
do a typeof check to see if the observed property is an array, and throw an error if so?Yep! That is a completely viable strategy. See https://github.com/aurelia/binding/blob/master/src/observer-locator.js#L159
This will not observe changes to array elements, however. So if you do
list[1] = 'new value';
, it will not recompute.Observing array length with
@computedFrom("array.length")
works, is it officially supported?@jdanyow I’m for an explicit option. We should be able to differentiate between property change and changes to the value.
I recommend creating a value converter. Try looking at this article by Rob Eisenberg for more information on value converters.
Using
@computedFrom
with any array mutation will not work.