-
Notifications
You must be signed in to change notification settings - Fork 1
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
Set value on SetterObservable when it's set #33
Comments
Update: I found another scenario where I was still getting extraneous set calls on my view model, this time from the correct value to the same correct value again. I was able to fix it by checking if the new value matches the current value before calling the setter. The full fix now looks like this:
|
What an awesome bug report! Thanks. I hope to get to this tomorrow. If not, please remind me Monday. |
BTW, you could do this:
Essentially, the default empty object will be used to create an instance of the inline |
@RyanMilligan what warning are you expecting to see? I'm confused a bit by the example, which I've made small changes to here: https://justinbmeyer.jsbin.com/wecija/1/edit?html,js,console,output
So subProp's getter will make that object subProp: {
get(val) {
console.log(val);
return parseInt(val);
}
} This is why the input element is Is this expected? |
@RyanMilligan I get the warning now. You expected to see it on a change of the input element. I'm going to see if I can produce it with something a bit closer to what I think your code might look like (getting passed a number instead of an object). |
Sorry, I should have been clearer; yes, the warning appears when you change the textbox. And also, yes, the whole thing with the converter and the object came out weird because I was trying to reproduce the larger scenario. I should have gone back and tidied it up before submitting but I'd already spent quite a lot of time debugging the issue to begin with. Thanks for taking the time to untangle it. |
oddly, when I update the example to something that seems to make more sense, the problem goes away: https://justinbmeyer.jsbin.com/wecija/2/edit?js,console,output Part of the issue I'm struggling with, is that setting the SetterObservable I feel like So, I could use an example that more or looks like the way something "should" be written. I'm going to keep experimenting, but if you have ideas / thoughts, that would help. Thanks! |
Here's another example that produces the warning right away, but not when the input changes: https://justinbmeyer.jsbin.com/sofahel/2/edit?html,js,console,output I'm going to try to write out what happens:
Now the big question is why does it log:
again? It seems it does this because after setting up observables for both sides of Eventually, however,
This will make
Which will run:
This will re-run the getter:
Since
Finally, the log is present because the child of I'm going to try to do a similar run down for your example. |
In this case which is identical to your situation: https://justinbmeyer.jsbin.com/rinipuk/1/edit?js,output After changing the input to 1, it logs:
When the input changes to 1,
That change is going to fire off the converter's setter, logging:
That sets the
The real question here is why does It seems that when
So this means that This is due to the TWO two-way bindings. Ah ...I think I identified the problem. As It will then read the
Which changes the value back to |
@RyanMilligan so in summary, I'm not sure what to change here. In my opinion, I see a few options:
|
Hi @justinbmeyer , sorry I haven't been monitoring this! I don't seem to be getting any notifications from GitHub when I get mentioned and I just forgot to check back. I think there's still something missing from the repro that we have in our real scenario, because I'm seeing it compare the "new" value to the original value that the parent was originally initialized to, and then setting the child to that for no good reason. The warning comes up either then (which is relatively ok because we don't want it set to that anyway) or when it tries to change it back (which is not ok, because then it gets stuck on the old, incorrect value). The end result that I'm seeing is that if I make a selection in my I think a live debugging session might be the best way for me to show you what's going on. I also have a separate issue in a prototype I'm working on that I'd like to run past you as well. |
In migrating one of our applications to Can 4, I've encountered what appears to be a pretty low-level problem in SetterObservable: specifically, when you call its setter, it never actually updates its
value
property. I assume this is because it's expected that theobservation
handler will be used to retrieve the value, but when can-bind calls the setter in updateValue (args.observable
will be aSetterObservable
in the case where value that's changing is bound to a converter), it then immediately calls the getter on the same observable.This would be fine, except that because
bound
is true, the getter (implemented in get-set.js) skips using theobservation
function and returnsthis.value
directly, which returns whatever the parent value was at the time the binding was set up.This has a few negative side effects when using two-way binding through a converter:
updateValue
function referenced above will cycle multiple times trying to get the parent and child values to agree (even though they already do; it's simply looking at an old snapshot of the parent value to do the comparison), which involves overwriting the child value with the original value of the parent, which will basically always be wrongI've created a jsbin that reproduces my binding scenario and demonstrates the warning: https://jsbin.com/kevolovonu/4/edit?html,js,console,output
I was unable to get it to reproduce the multiple sets, but I think the warning is probably sufficient to demonstrate that there's a problem here. The solution I found was to add
this.value =
to the beginning of SetterObservable.prototype.set.The text was updated successfully, but these errors were encountered: