-
Notifications
You must be signed in to change notification settings - Fork 215
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
mechanism to marshal immutable Set/Map #16
Comments
Not yet complete, but good enough to merge. refs Agoric#16
Make Cosmic-Swingset use ERTP instead of copied Mint
…gration-test/lodash-4.17.14 build(deps): bump lodash from 4.17.11 to 4.17.14 in /integration-test
👍 Just came across an example in the wallet and autoswap backend code in cosmic-swingset where this would be very helpful. |
Just came across another case in Zoe where a frozen Map would be incredibly useful. I'm adding "roles" to Zoe, which are user-defined unique identifiers for assays/units/payments. For instance, to create an auction, the user should define the terms, including the roles and assays. Maybe:
But, we can't do that, because on the Zoe side, we would have to use computed property names in order to easily access the assays. Computed property names are notoriously unsafe. So maybe instead we remove the user defined keys and use pre-determined ones:
This is pretty lengthy and unwieldy. Maybe instead what we want is to pass a frozen map. JavaScript maps can already be transformed to and from 2D Arrays. We could make helper functions to hydrate/dehydrate these 2D Arrays into and out of Map form. But, it would be so much easier to do this in |
The wallet example was: It'd be nice to be able to supply a wallet with assays and their suggested petnames:
or:
|
See #838 |
As I said in closing #838
So closing this in favor of passable collections. |
We commonly use objects as maps, but of course this suffers from confusion between "own properties" and inherited ones (i.e. don't use a key named
toString
). In the current code, if you send a Map or a Set (after callingharden()
on it, of course, which freezes the API but not the actual data), it will probably be recognized as a pass-by-presence object, and the remote end will wind up with a Presence on which they could callm~.get(key)
orm~.set(key, value)
, but they wouldn't be able to do immediate/near/synchronous operations.I think it'd be useful to have a way to pass-by-copy a frozen Map or Set, so the recipient gets a data structure that they can query locally. We should be able to do this without rendering the source object immutable, so the sender is really providing a snapshot of their Map to the far end. JavaScript doesn't currently have immutable collections (but we have a proposal to add them), but maybe
marshal
should provide a utility function that takes a regular mutable Set/Map and produce an object which will be recognized as pass-by-copy by the marshaller. On the receiving end, the deserializer creates a regular Map/Set, populates it with the inbound data, then wraps it with a facet that only provides read-only methods.and:
I can immediately think of a couple of problems:
MapSnapshot
appears earlier than the very end of the function, other code might have a chance to modify the mutable Map before the serializer does it's thing, which would be confusingMapSnapshot
object? Or a different one that behaves the same way?Obviously we want this to align with the Readonly Collections proposal, but I guess I'm wondering if we should have a mechanism that can be used without shimming both sides to understand the new types and
snapshot()
/diverge()
methods which the proposal adds to the builtin collection types.The text was updated successfully, but these errors were encountered: