Skip to content
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

Custom unmapping leads to infinite recursion #40

Open
aknuds1 opened this issue Aug 2, 2013 · 2 comments
Open

Custom unmapping leads to infinite recursion #40

aknuds1 opened this issue Aug 2, 2013 · 2 comments

Comments

@aknuds1
Copy link

aknuds1 commented Aug 2, 2013

Calling ko.viewmodel.toModel from a custom unmap function, as seen in one example on the project page, leads to infinite recursion. The example from the project page looks as follows:

options:{ 
    custom:{
        "{root}.users[i]": {
            map:function(user){
                var mapped = ko.viewmodel.fromModel(user);
                mapped().isDeleted= ko.observable(false);
                return mapped;
            },
            unmap:function(user){
                var unmapped = ko.viewmodel.toModel(user);
                delete unmapped.isDeleted;
                return unmapped;
            }
        }
    }
};

The call to ko.viewmodel.toModel in unmap leads to unmap being called recursively in my experience (using knockout.viewmodel 2.0.3 and Knockout 2.3.0). See my example fiddle to reproduce, although I've commented out the unmap function initially because it causes the page to crash in Chrome,

@coderenaissance
Copy link
Owner

I'll take a look at this problem for the release after the current one I'm working on (which I'm trying like crazy to make the time to wrap up). Thanks for your help.

@fgieseke
Copy link

Ups, I created a new Issue for this problem. But at least I described a workaround: See
#64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants