I have a strange situation. Basically, I have two custom bindings that are used to animate the DOM element for it with a new value. These are aWidth and aRight, which expect width and right values.
I implemented bindings like this:
<div class='classname' data-bind="aRight: right, aWidth: containerWidth, style: { zIndex: zindex, left: (left() + 'px'), height: (containerHeight() + 'px') }">
... and user bindings look like this:
ko.bindingHandlers.aWidth = { update: function (element, valueAccessor, allBindingsAccessor, context) {
So, the problem arises when we change the observable other than my two special observable observables, for example zindex.
If we change the observed zindex, the value will be correctly updated in the DOM, but for some reason my aRight binding also works! ...
I don't have a link to it in my custom aRight binding, so maybe there could be a dependency?
My aRight binding also starts when aWidth binding is also activated, which is also a bit strange!
Does anyone have any ideas about this?
Thanks a lot!
Andy.
Update
This is part of the view model, which updates the index, which when I call my automatic aRight to fire (this, by the way, is a very psudo code!):
var page = function() { this.zindex = ko.observable(0); this.right = ko.observable(0);
Update
I just read the post here: http://groups.google.com/group/knockoutjs/browse_thread/thread/26a3157ae68c7aa5/44c96d1b748f63bb?lnk=gst&q=custom+binding+firing#44c96d1b748f63bb
Saying:
In addition, the binding will start the update function again if another binding in the same data binding attribute is also triggered.
Does this mean that what I see is that my custom binding is triggered when any other data binding attribute binding is triggered (as it happens, it is possible that zindex is the first thing I see a change)? Isn't that a little weird / wrong? ...
Update
I have a simple violin that I think pretty much sums up my problem. It seems like any binding to the same data binding attribute, as many custom bindings will force it to update!
http://jsfiddle.net/J6EPx/2/
Hmmm ... I think I have to get around this by manually checking my user bindings to see if the value really changed or not! Does this mean that it does not spoil the actual anchor point?
I also posted a more specific question on the Knockout forums: http://groups.google.com/group/knockoutjs/browse_thread/thread/d2290d96e33f1d5a