Merged
Conversation
Collaborator
Author
|
One thing I couldn't figure out is how to extend |
Skn0tt
commented
Jul 31, 2020
| throw new Error('Trying to deserialize unknown class'); | ||
| } | ||
|
|
||
| return Object.assign(Object.create(clazz.prototype), json); |
Collaborator
Author
There was a problem hiding this comment.
This is where the magic happens btw. Object.create(clazz.prototype) creates a new, empty instance of clazz, which is much faster than changing the prototype of the existing value using Object.setPrototypeOf
This was referenced Aug 3, 2020
Merged
Contributor
|
@Skn0tt Hmm don’t really have any ideas about the types. Is it mergeable with looser typing? |
Collaborator
Author
|
@merelinguist this is the best I could come up with: 29d10cc. This will effectively downgrade our types to |
merelinguist
approved these changes
Aug 10, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #34
Implements revival of ES6 classes by attaching the original prototypes during revival. It requires registering all neccessary classes using
SuperJSON.registerClass(...).In the future, this could be done automatically in a compile-step (Which poses it's own issues, e.g. figuring out which classes are actually used and which classes to bundle therefore, but would make it opaque to Blitz users).