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 mappings replace observables instead of updating #38

Open
CuinnWylie opened this issue Jul 15, 2013 · 2 comments
Open

Custom mappings replace observables instead of updating #38

CuinnWylie opened this issue Jul 15, 2013 · 2 comments

Comments

@CuinnWylie
Copy link

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.

@spring1975
Copy link

I prefer whatever conversion that's necessary be handled by a computed.

I use momentjs to covert my dates, so I see how this could be a problem if
I were storing that conversion back to the model. If you're storing that
conversion back to the model, aren't the corresponding "modified" events
being fired?

I realize your DOB example is just that, an example. But essentially,
you're modifying the data. Adding more checks on whether the data is
observable ads overhead I personally haven't found necessary.
On Jul 14, 2013 7:06 PM, "Cuinn Wylie" [email protected] wrote:

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.


Reply to this email directly or view it on GitHubhttps://github.com//issues/38
.

@coderenaissance
Copy link
Owner

Thanks, will look into it.

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