Skip to content

Commit

Permalink
Only remove deleted records form record arrays when saved
Browse files Browse the repository at this point in the history
This is a backport of a major breaking change in Ember Data 2.0.

emberjs#3539
  • Loading branch information
Martin Muñoz committed Oct 12, 2021
1 parent 61a8bce commit 91c5538
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 94 deletions.
53 changes: 6 additions & 47 deletions ember-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8773,7 +8773,6 @@
// EVENTS
deleteRecord: function (internalModel) {
internalModel.transitionTo('deleted.uncommitted');
internalModel.disconnectRelationships();
},

didSetProperty: function (internalModel, context) {
Expand Down Expand Up @@ -8858,7 +8857,6 @@
});

ember$data$lib$system$model$states$$createdState.uncommitted.deleteRecord = function (internalModel) {
internalModel.disconnectRelationships();
internalModel.transitionTo('deleted.saved');
internalModel.send('invokeLifecycleCallbacks');
};
Expand All @@ -8883,7 +8881,6 @@

ember$data$lib$system$model$states$$updatedState.uncommitted.deleteRecord = function (internalModel) {
internalModel.transitionTo('deleted.uncommitted');
internalModel.disconnectRelationships();
};

var ember$data$lib$system$model$states$$RootState = {
Expand Down Expand Up @@ -9019,7 +9016,6 @@

deleteRecord: function (internalModel) {
internalModel.transitionTo('deleted.uncommitted');
internalModel.disconnectRelationships();
},

unloadRecord: function (internalModel) {
Expand Down Expand Up @@ -9132,6 +9128,7 @@
isDirty: false,

setup: function (internalModel) {
internalModel.clearRelationships();
var store = internalModel.store;
store._dematerializeRecord(internalModel);
},
Expand Down Expand Up @@ -9246,18 +9243,6 @@
}
},

disconnect: function () {
this.members.forEach(function (member) {
this.removeRecordFromInverse(member);
}, this);
},

reconnect: function () {
this.members.forEach(function (member) {
this.addRecordToInverse(member);
}, this);
},

removeRecords: function (records) {
var self = this;
ember$data$lib$system$relationships$state$relationship$$forEach.call(records, function (record) {
Expand Down Expand Up @@ -9355,12 +9340,6 @@
}
},

addRecordToInverse: function (record) {
if (this.inverseKey) {
record._relationships.get(this.inverseKey).addRecord(this.record);
}
},

removeRecordFromInverse: function (record) {
var inverseRelationship = record._relationships.get(this.inverseKey);
//Need to check for existence, as the record might unloading at the moment
Expand Down Expand Up @@ -9874,9 +9853,11 @@
return this.store.findMany(ember$data$lib$system$relationships$state$has$many$$map.call(manyArray.toArray(), function (rec) {
return rec._internalModel;
})).then(function () {
//Goes away after the manyArray refactor
manyArray.set('isLoaded', true);
return manyArray;
if (!manyArray.get('isDestroyed')) {
//Goes away after the manyArray refactor
manyArray.set('isLoaded', true);
return manyArray;
}
});
};
ember$data$lib$system$relationships$state$has$many$$ManyRelationship.prototype.notifyHasManyChanged = function () {
Expand Down Expand Up @@ -10855,7 +10836,6 @@
if (this.isDeleted()) {
//TODO: Should probably move this to the state machine somehow
this.becameReady();
this.reconnectRelationships();
}

if (this.isNew()) {
Expand Down Expand Up @@ -10967,7 +10947,6 @@
this.eachRelationship(function (name, relationship) {
if (this._relationships.has(name)) {
var rel = this._relationships.get(name);
//TODO(Igor) figure out whether we want to clear or disconnect
rel.clear();
rel.destroy();
}
Expand All @@ -10979,26 +10958,6 @@
});
},

disconnectRelationships: function () {
this.eachRelationship(function (name, relationship) {
this._relationships.get(name).disconnect();
}, this);
var model = this;
ember$data$lib$system$model$internal$model$$forEach.call(ember$data$lib$system$object$polyfills$$keysFunc(this._implicitRelationships), function (key) {
model._implicitRelationships[key].disconnect();
});
},

reconnectRelationships: function () {
this.eachRelationship(function (name, relationship) {
this._relationships.get(name).reconnect();
}, this);
var model = this;
ember$data$lib$system$model$internal$model$$forEach.call(ember$data$lib$system$object$polyfills$$keysFunc(this._implicitRelationships), function (key) {
model._implicitRelationships[key].reconnect();
});
},

/**
When a find request is triggered on the store, the user can optionally pass in
attributes and relationships to be preloaded. These are meant to behave as if they
Expand Down
53 changes: 6 additions & 47 deletions ember-data.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -8609,7 +8609,6 @@
// EVENTS
deleteRecord: function (internalModel) {
internalModel.transitionTo('deleted.uncommitted');
internalModel.disconnectRelationships();
},

didSetProperty: function (internalModel, context) {
Expand Down Expand Up @@ -8694,7 +8693,6 @@
});

ember$data$lib$system$model$states$$createdState.uncommitted.deleteRecord = function (internalModel) {
internalModel.disconnectRelationships();
internalModel.transitionTo('deleted.saved');
internalModel.send('invokeLifecycleCallbacks');
};
Expand All @@ -8718,7 +8716,6 @@

ember$data$lib$system$model$states$$updatedState.uncommitted.deleteRecord = function (internalModel) {
internalModel.transitionTo('deleted.uncommitted');
internalModel.disconnectRelationships();
};

var ember$data$lib$system$model$states$$RootState = {
Expand Down Expand Up @@ -8854,7 +8851,6 @@

deleteRecord: function (internalModel) {
internalModel.transitionTo('deleted.uncommitted');
internalModel.disconnectRelationships();
},

unloadRecord: function (internalModel) {
Expand Down Expand Up @@ -8967,6 +8963,7 @@
isDirty: false,

setup: function (internalModel) {
internalModel.clearRelationships();
var store = internalModel.store;
store._dematerializeRecord(internalModel);
},
Expand Down Expand Up @@ -9081,18 +9078,6 @@
}
},

disconnect: function () {
this.members.forEach(function (member) {
this.removeRecordFromInverse(member);
}, this);
},

reconnect: function () {
this.members.forEach(function (member) {
this.addRecordToInverse(member);
}, this);
},

removeRecords: function (records) {
var self = this;
ember$data$lib$system$relationships$state$relationship$$forEach.call(records, function (record) {
Expand Down Expand Up @@ -9190,12 +9175,6 @@
}
},

addRecordToInverse: function (record) {
if (this.inverseKey) {
record._relationships.get(this.inverseKey).addRecord(this.record);
}
},

removeRecordFromInverse: function (record) {
var inverseRelationship = record._relationships.get(this.inverseKey);
//Need to check for existence, as the record might unloading at the moment
Expand Down Expand Up @@ -9696,9 +9675,11 @@
return this.store.findMany(ember$data$lib$system$relationships$state$has$many$$map.call(manyArray.toArray(), function (rec) {
return rec._internalModel;
})).then(function () {
//Goes away after the manyArray refactor
manyArray.set('isLoaded', true);
return manyArray;
if (!manyArray.get('isDestroyed')) {
//Goes away after the manyArray refactor
manyArray.set('isLoaded', true);
return manyArray;
}
});
};
ember$data$lib$system$relationships$state$has$many$$ManyRelationship.prototype.notifyHasManyChanged = function () {
Expand Down Expand Up @@ -10659,7 +10640,6 @@
if (this.isDeleted()) {
//TODO: Should probably move this to the state machine somehow
this.becameReady();
this.reconnectRelationships();
}

if (this.isNew()) {
Expand Down Expand Up @@ -10771,7 +10751,6 @@
this.eachRelationship(function (name, relationship) {
if (this._relationships.has(name)) {
var rel = this._relationships.get(name);
//TODO(Igor) figure out whether we want to clear or disconnect
rel.clear();
rel.destroy();
}
Expand All @@ -10783,26 +10762,6 @@
});
},

disconnectRelationships: function () {
this.eachRelationship(function (name, relationship) {
this._relationships.get(name).disconnect();
}, this);
var model = this;
ember$data$lib$system$model$internal$model$$forEach.call(ember$data$lib$system$object$polyfills$$keysFunc(this._implicitRelationships), function (key) {
model._implicitRelationships[key].disconnect();
});
},

reconnectRelationships: function () {
this.eachRelationship(function (name, relationship) {
this._relationships.get(name).reconnect();
}, this);
var model = this;
ember$data$lib$system$model$internal$model$$forEach.call(ember$data$lib$system$object$polyfills$$keysFunc(this._implicitRelationships), function (key) {
model._implicitRelationships[key].reconnect();
});
},

/**
When a find request is triggered on the store, the user can optionally pass in
attributes and relationships to be preloaded. These are meant to behave as if they
Expand Down

0 comments on commit 91c5538

Please sign in to comment.