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

Fix leaky state with nested objects #163

Merged
merged 2 commits into from
Apr 14, 2016
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
16 changes: 16 additions & 0 deletions addon/validations/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ function createValidationsClass(inheritedValidationsClass, validations = {}) {
set(lastObject, '_model', model);
}
});
},

destroy() {
this._super(...arguments);
validatableAttributes.forEach(attribute => {
// Remove model reference from nested objects
const path = attribute.split('.');
const lastObject = get(this, path.slice(0, path.length - 1).join('.'));

if (!isNone(get(lastObject, '_model'))) {
set(lastObject, '_model', null);
}
});
}
});

Expand Down Expand Up @@ -259,6 +272,9 @@ function createValidationsClass(inheritedValidationsClass, validations = {}) {
const validatableAttrs = get(this, 'validatableAttributes');
const debouncedValidations = get(this, '_debouncedValidations');

// Initiate attrs destroy to cleanup any remaining model references
this.get('attrs').destroy();

// Cancel all debounced timers
validatableAttrs.forEach(attr => {
const attrCache = get(debouncedValidations, attr);
Expand Down