-
Notifications
You must be signed in to change notification settings - Fork 309
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
Updating the model from within an rv-each doesn't update the DOM #700
Comments
I think it has something to do with passing the model in your event handling function. It's not the same model object it looks like. If you remove it, it works. |
... you're right. That's pretty damn bizarre... so am I right in thinking accessing the model passed in by rivets, or the original declaration of model (declared when binding rivets for the first time) is exactly the same? Is there a best practice for one or the other? |
I always access the "higher scope" variable if I may call it that way. Never tried to do it your way :) Maybe the internals of rivets clone the model. |
Ok thanks, I'll do the same :) |
Rivets clone the properties of the model. It has some side effects like the above. |
Ok sorry for missing this one. This actually has There is another closed issue regarding this precise problem but I can't find it now. TL;DR: all top-level properties of the model object must be objects or arrays. Top-level primitives will not be observed for changes. The problem derives partly from how One approach is to do this instead: The approach I use is simply to put everything in an object. SECOND EDIT: What actually happens (translated to JS) is:
Rivets copies each property of the top-level object you pass in – |
These are related issues: #486 #512 #417
They are observed, just evaluate with devtools scope.main and scope.nested properties from this fiddle and note that these properties are transformed with getters and setters. But due to property being copied in
This is an workaround to the limitation of the current implementation. With a rivets version that does not copies the properties, observing root properties with primitive values works. See this fiddle from #512 I also created a more complex example to highlight the issue: Try to use the input fields and see the difference |
@blikblum Sorry to ping an old issue, but is there an issue I can follow for fixing the "observing root properties with primitive values" problem? |
AFAIK no. I proposed it, among other changes, in #558 . Later when i already implemented i pointed how to fix through #486 (comment) |
Hi all,
I'm trying to update my model from within an rv-each but the DOM isn't updating as a result.
I use rv-each to create a bunch of inputs, one for each object in a list. On input keyup, I check the validity of the input value, and update a "valid" flag on the model. This all works and the console prints the correct value for the validity flag, but the DOM isn't updated as a result.
My sleuthing suggests that the model parameter passed to the validation function is a different object to the one that is bound to the DOM.
Here's a simplified example on jsfiddle to show you what I'm talking about:
https://jsfiddle.net/maxmumford/9pazye3c/2/
Either I'm doing something very wrong, or this is a bug. Any help?
Max
The text was updated successfully, but these errors were encountered: