FIX: Stop trying to set values on destroyed bookmark component (#11909)

* sometimes the AJAX promise to create/save the bookmark did
  not come back before the component destroyed, causing an error
  when trying to set the model id afterward. this just eliminates
  the set code and uses the response.id instead
This commit is contained in:
Martin Brennan 2021-02-01 10:23:06 +10:00 committed by GitHub
parent 3e3f3f7b7e
commit 0fab711e4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -203,18 +203,17 @@ export default Component.extend({
return ajax(`/bookmarks/${this.model.id}`, {
type: "PUT",
data,
}).then(() => {
this._executeAfterSave(reminderAtISO);
}).then((response) => {
this._executeAfterSave(response, reminderAtISO);
});
} else {
return ajax("/bookmarks", { type: "POST", data }).then((response) => {
this.set("model.id", response.id);
this._executeAfterSave(reminderAtISO);
this._executeAfterSave(response, reminderAtISO);
});
}
},
_executeAfterSave(reminderAtISO) {
_executeAfterSave(response, reminderAtISO) {
if (!this.afterSave) {
return;
}
@ -222,7 +221,7 @@ export default Component.extend({
reminderAt: reminderAtISO,
reminderType: this.selectedReminderType,
autoDeletePreference: this.autoDeletePreference,
id: this.model.id,
id: this.model.id || response.id,
name: this.model.name,
});
},