-
Notifications
You must be signed in to change notification settings - Fork 35
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
Preserve object prototypes #71
base: master
Are you sure you want to change the base?
Conversation
Hi! Sorry for taking so long to respond, and thanks for looking into this. Originally we didn't expect to use anything but plain JSON objects in atoms, mostly due to difficulties around consistently defining equality, update semantics and type safety. I don't immediately see why it wouldn't work with a case like you presented in the unit test (thanks for the tests BTW!), but I feel there might be issues with such implementation in general. For example if there are side effects in the class constructor, they won't be executed when you Could you elaborate a bit more on what's your actual use case? What does you app's state look like? Thanks! |
My app's state is similar to the test cases: a data class with some extra pure functions attached. However, my app does some polymorphic array serialization and deserialization, so type information needs to remain attached for https://github.com/typestack/class-transformer to work properly. I agree |
Makes sense. In principle I'm fine with this change if:
|
I tried to set up a jsperf page, but I ran into this issue: jsperf/jsperf.com#527 The performance difference seems negligible, since the results only range from ~0.4μs to ~1.2μs. If you want, I could change it to the code for "Object.assign with blank object and prototype prop", which is slightly faster than my original code and does the same thing (I think). I've already tested a local version and it correctly preserves object prototypes. |
Thanks! I've ran the benchmark a couple times in different browsers, here are the results: It seems that preserving the prototype in this way makes it almost two times slower for this particular case. I've tried adding more properties to the updated object, and now iteration seems to be the slowest: |
Closes #69
Supersedes #70