knockout.mapping icon indicating copy to clipboard operation
knockout.mapping copied to clipboard

Fixed an issue: ko.isWriteableObservable incorrectly returns false for computed observables in the mapping context.

Open fsoikin opened this issue 12 years ago • 4 comments

The withProxyDependentObservable function replaces ko.dependentObservable, but does not replace ko.isWriteableObservable, which causes the latter to always return false for computeds. At the same time, the mapping plugin itself uses isWriteableObservable a lot in the mapping process to determine whether it should use the existing observable or replace it with a new, writeable one. Since all computeds look like non-writeable at this point, the mapping procedure will replace all computeds with new observables, thus screwing up the viewmodel inner mechanics.

The solution is simple: when replacing ko.dependentObservable with a proxy, also replace ko.isWriteableObservable.

fsoikin avatar Oct 03 '13 14:10 fsoikin

This doesn't work - you get infinite recursion

Should be var isWriteable = localIWO(o);

instead of
var isWriteable = ko.isWriteableObservable(o);

(inside the ko.isWriteableObservable function)

simeyla avatar Jun 10 '15 00:06 simeyla

Indeed. But this request is so old, and I'm not even sure it's into the right repository anymore. Is anybody even interested in this? I've stopped using ko.mapping a long time ago.

fsoikin avatar Jun 10 '15 00:06 fsoikin

It's a shame the mapping seems to have been neglected - it definitely has some issues and I wish it had been maintained - but I'm stuck with using it for now :-)

The reason I needed this change was I'd created a simple writeable observable to auto-convert a string or date to a proper Date object and I wanted it to work with the mapper. Making the change I suggested is working just fine.

simeyla avatar Jun 10 '15 01:06 simeyla

Well, glad to be of help. Good luck.

fsoikin avatar Jun 10 '15 01:06 fsoikin