withProxyDependentObservable make ko.isWriteableObservable fail #163

youngjay opened this Issue Jun 25, 2013 · 0 comments

1 participant


when provide a "create" callback for mapping, then withProxyDependentObservable will change the global ko.dependentObservable

line 244

ko.dependentObservable = function (read, owner, options) {

in this closure when the program call ko.isWriteableObservable, it will internal compare

instance[protoProperty] === ko.dependentObservable

with global ko.dependentObservable has been changed, so ko.isWriteableObservable will always return false

I have a hot dirty fix in knockout.js

    var realKoDependentObservable = ko.dependentObservable;

    var protoProperty = "__ko_proto__";
    ko.isWriteableObservable = function (instance) {
        // Observable
        if ((typeof instance == "function") && instance[protoProperty] === ko.observable)
            return true;
        // Writeable dependent observable
        if ((typeof instance == "function") 
            && (instance[protoProperty] === ko.dependentObservable || instance[protoProperty] === realKoDependentObservable) 
            && (instance.hasWriteFunction))

            return true;
        // Anything else
        return false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment