Skip to content
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

Support validations via inheritance #112

Merged
merged 1 commit into from
Feb 12, 2016
Merged

Conversation

offirgolan
Copy link
Collaborator

Resolves #111

Allows validations to persist through inheritance

const ParentValidations = buildValidations({...});
const Parent = Ember.Object.extend(ParentValidations);

const ChildValidations = buildValidations({...});
const Child = Parent.extend(ChildValidations);

var child = Child.create({...});

child.validateSync(); // should validate all props defined in parent and child

@offirgolan
Copy link
Collaborator Author

ping @rwjblue 😸

return createMixin(GlobalValidations, AttrValidations);
init() {
this._super(...arguments);
this.set('validations', Validations.create({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we usually want to do this on-demand via CP getter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what it was before, but because of this line, it goes into an infinite loop.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is an empty line :trollface:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL it changed after I made a commit. See here

For some reason, the getter keeps recomputing and doesnt cache the object, so it keeps calling itself when checking for an inherited validations object.

@offirgolan
Copy link
Collaborator Author

@stefanpenner ready for final review

}
});
// Caches
_validators: {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the caches want to be on the instance, not the prototype.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caches were always on the proto. That's how we decided to write them. They are cached by model guid. See test here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see the code for the cache. If we remove it from the proto, there isnt really a need for this...

offirgolan added a commit that referenced this pull request Feb 12, 2016
Support validations via inheritance
@offirgolan offirgolan merged commit 3a70c7e into master Feb 12, 2016
@offirgolan offirgolan deleted the support-inheritance branch February 12, 2016 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants