Skip to content

Move invocation of initialize above setting of attributes and validation #81

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

Merged
merged 1 commit into from
Dec 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/ParseObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export default class ParseObject {
className: string;

constructor(className: ?string | { className: string, [attr: string]: mixed }, attributes?: { [attr: string]: mixed }, options?: { ignoreValidation: boolean }) {
// Enable legacy initializers
if (typeof this.initialize === 'function') {
this.initialize.apply(this, arguments);
}

var toSet = null;
this._objCount = objectCount++;
if (typeof className === 'string') {
Expand All @@ -121,10 +126,6 @@ export default class ParseObject {
if (toSet && !this.set(toSet, options)) {
throw new Error('Can\'t create an invalid Parse Object');
}
// Enable legacy initializers
if (typeof this.initialize === 'function') {
this.initialize.apply(this, arguments);
}
}

/** Prototype getters / setters **/
Expand Down Expand Up @@ -1366,17 +1367,18 @@ export default class ParseObject {
parentProto = classMap[adjustedClassName].prototype;
}
var ParseObjectSubclass = function(attributes, options) {
// Enable legacy initializers
if (typeof this.initialize === 'function') {
this.initialize.apply(this, arguments);
}

this.className = adjustedClassName;
this._objCount = objectCount++;
if (attributes && typeof attributes === 'object'){
if (!this.set(attributes || {}, options)) {
throw new Error('Can\'t create an invalid Parse Object');
}
}
// Enable legacy initializers
if (typeof this.initialize === 'function') {
this.initialize.apply(this, arguments);
}
};
ParseObjectSubclass.className = adjustedClassName;
ParseObjectSubclass.__super__ = parentProto;
Expand Down