Skip to content
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

Deep watching for computeds? #674

Closed
jperkelens opened this issue Jan 12, 2015 · 4 comments

Comments

@jperkelens
Copy link

@jperkelens jperkelens commented Jan 12, 2015

Is there support for deep watching of computed dependencies?

In my case I have a computed whose dependency is an array of objects. In each of these objects (i.e. {selected: true}) is a boolean property, I'd like the computed to return the result of ANDing all the values of this field.

Currently, a change to one of the objects in this array does not trigger a reevaluation of the computed. Is there a way to do this, or is this an unsupported feature?

Edit: Attaching fiddle: http://jsfiddle.net/rmk83v5v/2/

@jperkelens

This comment has been minimized.

Copy link
Author

@jperkelens jperkelens commented Jan 12, 2015

EDIT: I'm actually having trouble figuring out what exactly is causing the difference between my code and the fiddle. I'm going to close this until I can reproduce consistently.

@jperkelens jperkelens closed this Jan 12, 2015
@jperkelens

This comment has been minimized.

Copy link
Author

@jperkelens jperkelens commented Jan 12, 2015

I've been able to reproduce this in the fiddle by more closely replicating what I'm doing in my code. I can't tell what exactly the problem is, but it seems that it's something to do with setting of the parent list after compilation.

@jperkelens jperkelens reopened this Jan 12, 2015
@TMiguelT

This comment has been minimized.

Copy link

@TMiguelT TMiguelT commented Jan 13, 2015

It's not that Vue doesn't support deep watching of dependencies, its that Vue doesn't register selected as a dependency because initially it doesn't exist in the list objects. This is exactly the same issue as #660, which I posted a couple of weeks ago.

I've simplified your fiddle to the absolute minimum here, and you'll notice that it still doesn't work (allSelected doesn't change). However if you define the selected property at the very start, even if it has a null/undefined value, the code will work, as in this fiddle. The only thing I changed here was making list equal to this:

list: [
    { selected: undefined },
    { selected: undefined },
    { selected: undefined },
    { selected: undefined },
]
@jperkelens

This comment has been minimized.

Copy link
Author

@jperkelens jperkelens commented Jan 13, 2015

Thanks for the explanation. It seems that the $add function exists in order to add things after compile, and should re-register dependencies. I've fixed my code and will close this issue, as there's a related one already open

@jperkelens jperkelens closed this Jan 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.