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

Props are not reactive! #158

Closed
AndresSepar opened this issue Sep 23, 2017 · 4 comments
Closed

Props are not reactive! #158

AndresSepar opened this issue Sep 23, 2017 · 4 comments

Comments

@AndresSepar
Copy link

When I update some data by the set method in the root application ... the components are not updating the props data. I think it should work as one-way binding

@LeviSchuck
Copy link

LeviSchuck commented Sep 23, 2017

Would you please provide a minimal example?

I encountered this when I was setting nested properties. (on Monx at least)

@kbrsh
Copy link
Owner

kbrsh commented Sep 23, 2017

@AndresSepar A reproduction would definitely be helpful.

Also, in v0.11, setting nested properties updates the object, but keeps the reference. When Moon diffs the elements, it tests for reference to see if props are the same.

In v1, you can use an object or set on a shallow property.

@AndresSepar
Copy link
Author

Here you can see the test. https://jsfiddle.net/andressepar/tp5x5tpx/6/

@kbrsh
Copy link
Owner

kbrsh commented Sep 24, 2017

Just as I suspected. The reference to items stays the same, but you update things inside of it. When Moon checks to see if the props are the same as last time, it checks if the reference of both are the same.

In this case, they are, and Moon skips updating the component. Moon components are all treated as pure, which is why there is a check in the first place (pure components have an output that depends only on the props passed to it).

For now, an easy fix would be doing:

var items = instance.get('items').slice(0);

Edit: Another thing. @AndresSepar In your example you use new Moon().mount(), why not provide the root option instead?

That's the purpose of the root option (to directly mount after processing options), and it's faster if you just include it in the options.

@kbrsh kbrsh closed this as completed in 50c91f5 Sep 25, 2017
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

3 participants