Skip to content
Permalink
Browse files

fix(lib): fix teardown of lib objects

  • Loading branch information...
anehx committed Jul 23, 2019
1 parent 9272cf1 commit bd583a245ce1edd0e4dada5907661bcc2d738a15
Showing with 45 additions and 13 deletions.
  1. +5 −3 addon/components/cf-content.js
  2. +9 −1 addon/lib/document.js
  3. +8 −0 addon/lib/field.js
  4. +8 −0 addon/lib/fieldset.js
  5. +15 −9 addon/lib/navigation.js
@@ -60,7 +60,11 @@ export default Component.extend(ComponentQueryManager, {
willDestroy() {
this._super(...arguments);

this.calumaStore.clear();
this.document.destroy();

if (this.navigation) {
this.navigation.destroy();
}
},

/**
@@ -152,8 +156,6 @@ export default Component.extend(ComponentQueryManager, {
"allForms.edges"
)).map(({ node }) => node);

this.calumaStore.clear();

return Document.create(getOwner(this).ownerInjection(), {
raw: parseDocument({ ...answerDocument, form })
});
@@ -38,7 +38,7 @@ export default Base.extend({

_createRootForm() {
const rootForm =
this.calumaStore.find(`Form:${this.raw.rootForm}`) ||
this.calumaStore.find(`Form:${this.raw.rootForm.slug}`) ||
Form.create(getOwner(this).ownerInjection(), {
raw: this.raw.rootForm
});
@@ -60,6 +60,14 @@ export default Base.extend({
this.set("fieldsets", fieldsets);
},

willDestroy() {
this._super(...arguments);

const fieldsets = this.fieldsets;
this.set("fieldsets", []);
fieldsets.forEach(fieldset => fieldset.destroy());
},

/**
* The uuid of the document
*
@@ -94,6 +94,14 @@ export default Base.extend(ObjectQueryManager, {
this.set("_errors", []);
},

willDestroy() {
this._super(...arguments);

if (this.answer) {
this.answer.destroy();
}
},

_createQuestion() {
const question =
this.calumaStore.find(`Question:${this.raw.question.slug}`) ||
@@ -41,6 +41,14 @@ export default Base.extend({
this._createFields();
},

willDestroy() {
this._super(...arguments);

const fields = this.fields;
this.set("fields", []);
fields.forEach(field => field.destroy());
},

_createForm() {
const form =
this.calumaStore.find(`Form:${this.raw.form.slug}`) ||
@@ -16,15 +16,14 @@ export const NavigationItem = Base.extend({

init() {
assert("A fieldset `fieldset` must be passed", this.fieldset);
assert("A navigation `navigation` must be passed", this.navigation);

defineProperty(this, "pk", {
writable: false,
value: `NavigationItem:${this.fieldset.pk}`
});

this._super(...arguments);

this.set("_items", []);
},

/**
@@ -33,8 +32,8 @@ export const NavigationItem = Base.extend({
* @property {NavigationItem} parent
* @accessor
*/
parent: computed("_parentSlug", "_items.@each.slug", function() {
return this._items.find(item => item.slug === this._parentSlug);
parent: computed("_parentSlug", "navigation.items.@each.slug", function() {
return this.navigation.items.find(item => item.slug === this._parentSlug);
}),

/**
@@ -43,8 +42,8 @@ export const NavigationItem = Base.extend({
* @property {NavigationItem[]} children
* @accessor
*/
children: computed("slug", "_items.@each._parentSlug", function() {
return this._items.filter(item => item._parentSlug === this.slug);
children: computed("slug", "navigation.items.@each._parentSlug", function() {
return this.navigation.items.filter(item => item._parentSlug === this.slug);
}),

/**
@@ -219,6 +218,14 @@ export const Navigation = Base.extend({
this._createItems();
},

willDestroy() {
this._super(...arguments);

const items = this.items;
this.set("items", []);
items.forEach(item => item.destroy());
},

_createItems() {
const items = this.document.fieldsets
.filter(fieldset => fieldset.field)
@@ -228,13 +235,12 @@ export const Navigation = Base.extend({
return (
this.calumaStore.find(pk) ||
NavigationItem.create(getOwner(this).ownerInjection(), {
fieldset
fieldset,
navigation: this
})
);
});

items.forEach(item => item.set("_items", items));

this.set("items", items);
},

0 comments on commit bd583a2

Please sign in to comment.
You can’t perform that action at this time.