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

Possibly a BUG: Child computed property does not change reactively when bound to parent's computed property. #169

Open
AndyRightNow opened this issue Mar 13, 2017 · 5 comments

Comments

@AndyRightNow
Copy link

Version:

0.5.1

Description:

When a parent computed property is bound to a child computed property, the child computed property setter is not called after the parent computed property is altered.

Reproduction:

Codepen Example

Please take a look and see if it is my problem or it is just a bug. Thanks very much!

@leeluolee
@rainfore

@fengzilong
Copy link
Member

I can explain a little why this happens

Because get method for computed property childData is the only source of truth it gets value from.

During digesting, child-component gets childData's value for comparing.

It invokes get method, and "This is child." is got.

But childData's last value is also "This is child.".

Nothing changes, right?

@fengzilong
Copy link
Member

fengzilong commented Mar 13, 2017

I've modified your codepan example to make it work

http://codepen.io/anon/pen/mWwJzw

@AndyRightNow
Copy link
Author

AndyRightNow commented Mar 13, 2017

@fengzilong

Hi,

I see what you did to the example and that is definitely a solution for only using _parentData. However now two components are tightly coupled right? I wouldn't see that as a good way to design a component. Also, what if I do have to bind it to a computed property instead of one certain data member? Because I may use a computed property to represent multiple data members conditionally.

The problem is that why the setter of the child computed property is not called while the parent computed setter can be called?

I made some modification to the example and you can see when the childData computed property is altered, the setter of parentData is called, but not the other way around.

Please take a look: Modified Example

@fengzilong
Copy link
Member

Yay, you are right, maybe it can be improved

But I don't recommend using computed property in that way

It's unnecessary to use computed property in your case

http://codepen.io/anon/pen/bqREQB

@AndyRightNow
Copy link
Author

@fengzilong

😂 Sure it is definitely not necessary in your example to use computed properties lol...

I made that just for simple demonstration. My case is actually using a computed property to represent multiple nested data members with different conditions and it is pretty complicated without computed properties.

This example can present a closer example to what I am actually facing.
More accurate example

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

2 participants