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

Only call super on validations class if it exists via shouldCallSuper #170

Merged
merged 3 commits into from
Apr 16, 2016

Conversation

offirgolan
Copy link
Collaborator

All credit goes to @rwjblue for thinking this up. (Savage)

Resolves #149


// Count number of mixins to bypass super check if there is more than 1
this.__validationsMixinCount__ = this.__validationsMixinCount__|| 0;
this.__validationsMixinCount__++;
Copy link
Member

@rwjblue rwjblue Apr 16, 2016

Choose a reason for hiding this comment

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

Small tweak here, we should store the resulting integer in a closure scoped variable:

let Validations, validationMixinIndex;
// ...snip...

validationMixinIndex = this.__validationsMixinCount__++;

Then below, the guard for calling super in __validationsClass__ would look like:

if(shouldCallSuper(this, '__validationsClass__') || validationMixinIndex > 1) {
  inheritedClass = this._super();
}

This ensures that the first mixin with a __validationsClass__ only calls _super if the superclass passes the shouldCallSuper check, and the second (and any more) validation mixins always call _super.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 Added the fix

@offirgolan offirgolan merged commit aeccc03 into master Apr 16, 2016
@offirgolan offirgolan deleted the underscore-super branch April 16, 2016 04:50
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