New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
computedFrom doesn't observe lists #249
Comments
there are any workaround this? |
one workaround would be to write |
@andrevlins So this is actually a bad design practice. Observing lists via splice is working, and modifying a list with another variable through value converters is working. Thus if you want a computed list you should bind the list and add a value convert to modify it. However, I think we're agreed that this should eventually work, too, @jdanyow? Since there might be a case where you'd want to access the modified list in a viewModel rather than simply bound to the view. |
@davismj I agree, the best way to do this would be with a value converter. There are other enhancement requests for |
related to #149 |
Using app.ts import { computedFrom } from "aurelia-framework";
export class App {
selectedOptions = [];
options = [1, 2, 3, 4];
@computedFrom("selectedOptions")
get selectedItemsSeparetedWithComma(): string {
return this.selectedOptions.join(", ");
}
} app.html <template>
<ul>
<li repeat.for="item of options">
<label><input type="checkbox" model.bind="item" checked.bind="$parent.selectedOptions" >${item}</label>
</li>
</ul>
<div>${selectedItemsSeparetedWithComma}</div>
</template> selectedItemsSeparetedWithComma is never fired when selectedOptions change. |
Using |
@davismj how can I make it work? |
I recommend creating a value converter. Try looking at this article by Rob Eisenberg for more information on value converters. |
@davismj thanks! |
@jdanyow, any progress with |
@atsu85 - the binding system observes property changes- if you put Perhaps we could do that in the |
@jdanyow I'm for an explicit option. We should be able to differentiate between property change and changes to the value. |
I understand, that if I'd need to use Here is an example of my use-case: <template>
${computedGetter.value}
<template> with @computedFrom("bindableArray", "bindableId")
get computedGetter() {
// return item from `this.bindableArray` by `this.bindableId`
} |
@atsu85 As mentioned above, I haven't seen a case where this couldn't be solved with a value converter, which is much more efficient. So instead you might have: <template>
${bindableArray | filter: bindableId}
</template> export class FilterValueConverter {
toView(array, id) {
// return item from `array` by `id`
}
} I've even written a small library that does this for you here: http://foursails.github.io/bouncer/ |
@jdanyow As the person who originally opened this issue, I recommend we close it, as I don't see this as a valuable enhancement. What do you think? |
@davismj, my example was a lot simplified from real use-case. I also need the result of |
Is it intended that the value converter ( |
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 |
Value converters don't work at all for this use case. |
Observing array length with |
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 |
In other words.
The text was updated successfully, but these errors were encountered: