Sitelet https://github.com/coderenaissance/knockout.viewmodel/issues/38
Skip to content

Custom mappings replace observables instead of updating #38

Description

@CuinnWylie

Hi,

When implementing the custom mapping option and returning an observable the observable is replaced on update instead of actually being updated. ie. If I implement a custom mapping for DOB that converts to a date in a specific way then on update it recreates the observable instead of updating and breaks all bindings on the page.

I sorted this out for the time being by modifying the recursiveUpdate function as below. I'm sure that the way I've done it is not the best, but it works for me and I've put it here just so you can see what I've done.

Original

 unwrapped[p] = childMap(modelObj[p]);

Modified

                    if (isObservable(unwrapped[p])) {
                        if (isObservable(childMap(modelObj[p]))) {
                            unwrapped[p](childMap(modelObj[p])());
                        } else {
                            unwrapped[p](childMap(modelObj[p]));
                        }
                    } else {
                        unwrapped[p] = childMap(modelObj[p]);
                    }

Thanks.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions