data-class function is called multiple times in KO 3.0
lisovin opened this issue · 6 comments
This is best can be demonstrated by following jsbin-s - same exact code results in different behavior in KO 2.3 and 3.0:
KO 2.3: http://jsbin.com/ULovitA/3 (number of calls is 1)
KO 3.0: http://jsbin.com/ULovitA/2 (number of calls is 4)
I suspect the issue is related to the change in KO 3.0 that now evaluates every binding independently (and thus calling binding function multiple times). I wonder what a good workaround might be though.
classBindingProvider would need to be updated to use getBindingAccessors
.
yes- that has been on my list of things to look at (providing getBindingAccessors for 3.0 support).
I worked on a prototype for this back in August. I pulled that out again and make some tweaks to get it working optimally with Knockout 3.0. See #19.
In general, you'll get the most benefit from Knockout 3.0 if you pass the observables themselves to bindings instead of unwrapping them in your bindings.
Thus you should have
counter: function () {
return {
text: this.counter
};
}
instead of
counter: function () {
return {
text: this.counter()
};
}
@rniemeyer: New version of classBindingProvider seems to have resolved the issue. Thanks a lot!