hyperhyperspace / hyperhyperspace-core

A library to create p2p applications, using the browser as a full peer.
https://www.hyperhyperspace.org
MIT License
195 stars 12 forks source link

WIP checkpoint export/import for mutable types #44

Closed micahscopes closed 1 year ago

micahscopes commented 1 year ago

This contains my work in progress on mutable type import/export for checkpoints. Two things I'm unsure about:

  1. I couldn't figure out how to use the HashedSet literalization correctly
  2. The toLiteral and fromLiteral functions I wrote for the multimap types doesn't handle generic key types and isn't consistent with the literalization pattern used elsewhere (which I'm still learning!)

So I'd love a review.

sbazerque commented 1 year ago

OK - tests are passing now!

One detail I noticed is that literalize / deliteralize methods were added to MultiMap and ArrayMap, up to now all the literalizable things are acceptable as fields in HashedObjects (they have a _type field that allows the main HashedObject.deliteralizeInContext function to know which deliteralizer to call). Since MultiMap and ArrayMap are not accepted inside HashedObjects ATM, I think we should either change the naming slightly so it doesn't clash (say asArrays instead of literalizeor something along that line) or -if we feel these may be used inside the immutable part of state that is actually literalized) add support for them in HashedObject.deliteralizeInContext). Since this is not an immediate problem and the functions seem to work really well I didn't change anything in the code.