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

Trap "toJSON" to allow serialization of proxies #31

Open
CheloXL opened this issue Jul 3, 2018 · 2 comments
Open

Trap "toJSON" to allow serialization of proxies #31

CheloXL opened this issue Jul 3, 2018 · 2 comments

Comments

@CheloXL
Copy link

CheloXL commented Jul 3, 2018

Hi,
I just found an issue while trying to store objects on IDB. It seems that IDB can't serialize proxied objects, and throws an error (Serialization error: Can't serialize [object object] on xxx...).

So, in order for me to be able to store these objects, I have to serialize/deserialize the object manually (so effectively removing the proxy).

I was thinking that maybe you can trap the checks for "has toJSON" to return true and then when that method is invoked, return the raw object. That would solve the serialization issue.

If the object already has a toJSON method, you should not have to do anything.

What do you think?

@solkimicreb
Copy link
Member

solkimicreb commented Jul 3, 2018

Hi!

I will look into it. In the meantime you can use raw, like:

import { observable, raw } from '@nx-js/observer-util'

const obs = observable({})
const json = raw(obj).toJSON()

See the relevant docs here

@CheloXL
Copy link
Author

CheloXL commented Jul 3, 2018

Yes, I know.. I just wanted to know if I can get rid of that "automagically" :)
Thanks!

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

2 participants