-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Introduce a generic object serializer/deserializer for WebWorker transfers #5143
Comments
This is elegant from the point of view of the serialize/deserialize code, but I think the verbosity it requires in client code is a bit much: (Object.defineProperty: any)(this, '_cached', {
writable: true,
enumerable: false,
value: this.n * this.n
}); Since classes have to be registered anyway, an alternative would be to allow an optional |
I suppose we could also reduce verbosity with a helper function |
I'm 👍 on a |
See sketch here.
The idea is to replace all our manually-defined
serialize
methods with a generic serializer function that recursively serializes the own-properties of an object and records the constructor name, and all our manually-defineddeserialize
methods with a generic deserializer that looks up the constructor name in a class registry, then usesObject.create
to reconstitute an instance without triggering the constructor.Properties that should not be serialized (e.g. cached computed values) shall be marked as non-enumerable.
In the sketch above,
Tranferable
s that should be transferred can be flagged by setting atransfer: true
property on theTransferable
. But I think it would be better to makeserialize
a transfer-only operation, and require you to copy ahead of time of anyTransferable
s you need to copy.The text was updated successfully, but these errors were encountered: