-
-
Notifications
You must be signed in to change notification settings - Fork 597
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
base: alpha
Are you sure you want to change the base?
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 Report
@@ Coverage Diff @@
## master #924 +/- ##
=========================================
- Coverage 91.87% 91.5% -0.38%
=========================================
Files 53 53
Lines 5073 5073
Branches 1144 1144
=========================================
- Hits 4661 4642 -19
- Misses 412 431 +19
Continue to review full report at Codecov.
|
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. |
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