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

enable structured cloning #127

Closed
bblfish opened this issue Jan 12, 2016 · 1 comment
Closed

enable structured cloning #127

bblfish opened this issue Jan 12, 2016 · 1 comment

Comments

@bblfish
Copy link

bblfish commented Jan 12, 2016

Many use upickle is to enable structured cloning ( eg. scalajs-rx-idb, others to pass objects between WebWorkers, etc... ).

But the way upickle is written it is

  • not efficient as some types of objects can be cloned just because they extend js.Any without needing to be serialised by upickle ( see @sjrd's comment on the structured cloning thread )
  • does not support Opaque Objects - as these are exactly objects that cannot be transformed the way upickle does into simple basic json types.

I actually tried to see if I could make some minor changes to upickle for this to work with PR 122: enable non serializable objects.

Writing seems relatively straightforward.
The problem comes from reading JS Objects. To do that correctly one would need to know what the objects were going to be serialised to first. ( see note in json.readJs function ): after all one may not want to walk through an object that is going to be mapped to a class extending js.Any, since it can just be transformed to that object with an jsobj.asInstanceOf[ScalaClass]

This is for example how scalajs-rx-idb uses that function.

    readJs[K](json.readJs(cursor.key)) -> readJs[V](json.readJs(cursor.value))

It passes it to readJS that then constructs the object. It seems that what would be needed would be a merger of the two functions, so upickle's Types.readJs[K] could make the decision as to wether it should bother mapping the object at all...

@bblfish
Copy link
Author

bblfish commented Jan 26, 2016

I found it easiest to remove the dependency on uPickle from viagraphs/scalajs-rx-idb . See commit: bblfish/scalajs-rx-idb@d5a6d7e

@bblfish bblfish closed this as completed Jan 26, 2016
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

1 participant