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

For computed properties, change the way dependencies are specified #878

Closed
tinius opened this issue Sep 28, 2017 · 3 comments
Closed

For computed properties, change the way dependencies are specified #878

tinius opened this issue Sep 28, 2017 · 3 comments

Comments

@tinius
Copy link

tinius commented Sep 28, 2017

Hi,

I was very surprised when I found out today that in the computed object, the dependencies for each computed property are identified by the names of the parameters passed into the respective functions. This seems to be at odds with what I thought was a common principle in JS, namely that I can call my parameters whatever I want in the function head and worry about what is passed in elsewhere. I guess another problem with the current design of computed is that you can't dynamically determine the dependencies of a property.

May I ask what the rationale behind this is? I believe a more intuitive approach would be to specify dependencies in the form of a list of (string) keys, similar to how component.observe works for example.

@Conduitry
Copy link
Member

Having the computed property dependencies be fixed makes them able to be analyzed at compile time, so that Svelte can output code to recompute only the computed properties that might have changed. As for the syntax, it is a bit magical, but provides a very succinct way of declaratively specifying these dependencies.

If you have a problem that is more general than computed properties can solve, a reasonable solution would probably be to just attach some .observe handlers to the component in its oncreate hook.

@Crisfole
Copy link
Contributor

Crisfole commented Jan 4, 2018

Can this be closed in light of #1069 ? I believe they address the same issue.

@arxpoetica
Copy link
Member

arxpoetica commented Jan 8, 2018

Closing with ongoing discussion about destructured syntax. (See #1069)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants