-
Notifications
You must be signed in to change notification settings - Fork 310
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
rv-if does not update children when model changes #452
Comments
It seems that rivets can't handle when a bound object's property is totally replaced with a new one (the target property you are binding in the template) so, if you changed only a property of the target object, this will work just fine: |
Yes I realise that, but I want to replace the whole object - you can do that anywhere except inside an 'rv-if' statement! |
This seems to be the case with arbitrary bindings (e.g. rv-text and rv-value: http://jsfiddle.net/v001txq3/4/) |
And the sub-elements of the rv-if element are updated otherwise: http://jsfiddle.net/v001txq3/6/ |
Ah...the rv-if binding does not update its subelements at all: http://jsfiddle.net/v001txq3/8/ Is this how rv-if is supposed to work? Is there an alternative to rv-if that updates? I know there is rv-show but you can't do this
because accessing model.foo.bar is an error when model.foo is undefined |
@diachedelic rivets' default adapter is a defineProperty based adapter so it listens the object it is provided at first binding time (at the rivets.bind phase). If you want to override the current object with new one you need to inform the view about model change with view.update (view object is returned from rivets.bind). You can see the result here : http://jsfiddle.net/opdow1sb/ Best Regards. |
Oh wow, yeah that works. But why is this only an issue for rv-if?
|
i think this is because each binders gets the reference of the sub object and listens that reference so completely replacing sub object affects the root view but not rv-if because rv-if has old reference of sub object.
in this object sub object has a reference to key-value and rv-if listens that reference not whole object. and if you set a new object instance you change the reference.
if i did not miss anything this is how default binding of objects work. |
#512 seems to be related |
It seems like |
@diachedelic what can you see in output? I see both "updated" which seems OK. |
Oops I forgot to fork that fiddle. I have made a new one which shows the exact problem I'm having: |
@diachedelic by trying this, you can see that rivets.bind(document, model);
setTimeout(() => {model.foo = null;}) // image for a while disappears
setTimeout(() => {model.foo = friesURL;},1000) // image reappear but still with old URL |
Look at this weirdness - neither |
I have a simple fix for this problem by not copying model in rv-if's routine in src/binders.coffee - models = {}
- models[key] = model for key, model of @view.models
+ models = @view.models But don't know if it may cause other problems? |
@luikore I'm still note sure what was the purpose of creating a new object because I didn't look into that too deeply. However, you might want to look here: |
In the svelte fork i changed how scope is created, basically by not shallow copying the models in the nested scopes. Instead, it uses prototype like inheritance. It searches the property to bind in the current scope, if not find search in parent scope until find the root scope. Each scope has a $parent property pointing to parent scope. This is similar how vue works. It has some advantages. Fixes #486 #512 #417 and this bug Also allows to bind to properties in parent scopes. See https://codepen.io/blikblum/pen/eBQzJO . Try to edit one of the input fields that are bound to a property in the parent model Now do the same with https://codepen.io/blikblum/pen/MKXXOX?editors=1010#0 svelte fork it behaves similar to vue: https://codepen.io/blikblum/pen/ZQRRmm |
I don't know for sure if this is related or not. In our code, we have:
This works fine, unless it's the last item in the array. Because we also have, in the html, some For now instead I'm working around the issue, by not calling |
@arantius |
Any binding deeper than one level within an rv-if statement is not updated when the object representing the deep binding is replaced, ala:
http://jsfiddle.net/v001txq3/
The text was updated successfully, but these errors were encountered: