-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Bug using "with binding", get "You cannot apply bindings multiple times to the same element" error message #2285
Comments
You can reproduce this error here: http://jsfiddle.net/epabon/g15jphta/4/ |
Thanks for the detailed information. It looks like this was introduced in 3.4.1 because your example works correctly in 3.4.0. |
Yes, It was working correctly in 3.4.0 but I updated to 3.4.1 and this bug appeared |
Here's a more concise example: http://jsfiddle.net/g15jphta/6/ The issue was that the |
With the changes in #2234, functions passed to the |
why am I wrong prefering the new behavior? |
@miellaby Can you elaborate? |
My apologies if I missed something. But, if I understand well, when the developer puts a function value as an attribute of a "with" data-bind, this function is evaluated and its result is bound to $data? That looks odd to me. An ordinary function is not a Subscribable, so there is no reason to "unwrap" it. What if I want to pass functions as values? |
Oups, my bad. Here the function is directly bound to "with", not as an attribute of "with". So there is less a concern. That being said, and now that I leaved lurking-mode, I can't help myself signaling that auto-unwrapping Functions and Subscribables is the aspect of KO I dislike the most. It looks like a good idea at first, but me and every developper I trained to KO have difficulties to grasp the huge difference of "dot notations" vs "JS expressions" in bindings. For example, the inconsistency between these 2 sequences is incomprehensible to many developpers I've dealt with:
So I teached all my team mates to always put parenthesis after a observable, and never relay on observable auto-unwrapping, as it leads to evolution bugs every time someone turns an auto-unwrapped dot notation into an expression. |
This works for one-way bindings, but not for two-way bindings such as |
Just as a matter of interest, in |
@brianmhunt this enhancement obviously changes the deal. But does the parser silently deals with missing attributes like in Angular, or is there still a way to handle observable reference by itself without unwrapping? because I'm accustomed now to build up expressions based on observable references. For example, I put many regular JS guards inside bindings, à la "disabled: $data.readOnly && readOnly()" (yet another case of mandatory parenthesis in ko by the way) so to implement reusable views with optional data model features.
I I would like to disagree, if I may. I find it more hygienic distinguishing observable references from observable unwrapped values. The difference between "text: observable()", or "value: someObservable" conveys a meaning which is useful for the general comprehension IMHO. I suppose my opinion on that is due to my low-level programming background. My apologies. On a side node, does "value: observableReferenceObservable()" works as I expect in production KO? I won't recommend it of course, but you get the idea: according to me, such a sequence makes more sens with a consistent parenthesis unwrapping rule. |
My understanding of this case, and please others correct me if i'm wrong, when you bind to the de-refrenced observableReferenceObservable (by accessing it via ()). Your binding is to the underlying value, not an observable so changing the reference to somethign else via observableReferenceObservable(otherValue) will not signal an update to the tracker. If the inner object is an observable, i think the dependency tracking will capture change in the inner object and push a change notification if the inner observable is set. But I'm assuming your observableReferenceObservable is wrapping a raw value (not an observable). I agree that sometimes the () notation around observables looks painful, but I've come to appreciate knowing exactly when you intended to de-ref an observable vs not. I think other frameworks treat everything as 'observable' but nice thing about having that fine-grained control over which things are actually observable makes the overall app more efficient. |
@miellaby Tko auto-unwraps only when there's an operator (because operations on the observable functions are generally nonsensical). So |
In the view model:
This return the error message "You cannot apply bindings multiple times to the same element" when a Level Value changes. If I change the binding to: data-bind="with: $root.getData($data)" the error disappears but when the getData return 0 the binging change it to null or undefined.
The text was updated successfully, but these errors were encountered: