-
-
Notifications
You must be signed in to change notification settings - Fork 595
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
feat(ParseObject): enable subclasses to set initial values for props #924
feat(ParseObject): enable subclasses to set initial values for props #924
Conversation
* Test failing with error "Expected 'default' to be 'foo'." * `jasmine.DEFAULT_TIMEOUT_INTERVAL` was increased to `10000` because the first cases often failed when starting integration testing. Related to issue parse-community/parse-server#5521
I found that the problem is in the `ParseObject` class
Sobclasses of `ParseObject` where unable to set initial values for their props and maintain them after fetching from the server. The function `ParseObject.fromJSON()` has been modified to allow this feature. Two test cases have been added. It may close parse-community/parse-server/#5521
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## alpha #924 +/- ##
==========================================
+ Coverage 92.34% 92.38% +0.03%
==========================================
Files 54 54
Lines 5294 5302 +8
Branches 1191 1194 +3
==========================================
+ Hits 4889 4898 +9
+ Misses 405 404 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/ParseObject.js
Outdated
@@ -1701,7 +1701,7 @@ class ParseObject { | |||
throw new Error('Cannot create an object without a className'); | |||
} | |||
const constructor = classMap[json.className]; | |||
const o = constructor ? new constructor() : new ParseObject(json.className); | |||
const o = constructor ? new constructor(json) : new ParseObject(json.className, Object.assign(json, { className: undefined })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const o = constructor ? new constructor(json) : new ParseObject(json.className)
should be fine for your test to work.
There are other issues this brings up. There are other Subclasses of ParseObject like _User
and _Session
that will try to set readonly fields. You could try to clone the json and delete the readonly fields before passing to the constructor but I don't know what other issue this would cause.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RaschidJFR Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry I didn’t reply earlier. I’ve already done that with good results. Haven’t pushed though.
I’ve got almost all tests passing now, just a couple left. What I’m trying to figure out now is a way to prevent pending ops from overwriting the properties set in the constructor.
Tomorrow I’ll push my progress so anyone can have a look.
* reserved field prevented the creation of some classes such as ParseUser * fix test 'retrieve subclass objects' in ParseObjectTest.js
@dplewis So I pushed my last commit... it turns out that it was just what you suggested. I havn't continued working on it since a couple of weeks so I can't remember exactly where I am, I'll retake it hopefully soon. For now there are only a couple of tests failing for |
@RaschidJFR @dplewis Any update on this PR? Are we going to merge it anytime soon? Thanks! |
Hi @victorx98 Sorry, work is keeping me busy so I won't be able to re-take it at least for the next 4 weeks. I see there's been increasing activity around this topic lately so I will dive into it when I'm out of homework. Meanwhile anyone how wishes to retake the subject is welcome to give a hand. |
Closing as this feature already exists. You can override the initialize function.
|
@dplewis That looks interesting, have we documented this use of |
https://parseplatform.org/Parse-SDK-JS/api/6.0.0/Parse.Object.html#.extend Should probably remove the docs for Backbone compatibility |
Sobclasses of
ParseObject
where unable to set initial values for their props and maintain them after fetching from the server. The functionParseObject.fromJSON()
has been modified to allow this feature. Two test cases have been added.It may close parse-community/parse-server#5521