Skip to content

Commit

Permalink
Merge pull request #4594 from emberjs/revert-4277-Unload-Record-Does-…
Browse files Browse the repository at this point in the history
…Not-Remove-Observers

Revert "unloadRecord does not remove observers"
  • Loading branch information
pangratz committed Oct 19, 2016
2 parents 26f9a57 + 2f723be commit a136f67
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 42 deletions.
4 changes: 2 additions & 2 deletions addon/-private/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ var Model = Ember.Object.extend(Ember.Evented, {
@type {Boolean}
@readOnly
*/
hasDirtyAttributes: Ember.computed('currentState', function() {
return this.get('_internalModel.currentState.isDirty');
hasDirtyAttributes: Ember.computed('currentState.isDirty', function() {
return this.get('currentState.isDirty');
}),
/**
If this property is `true` the record is in the `saving` state. A
Expand Down
4 changes: 2 additions & 2 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ Store = Service.extend({
*/
unloadRecord(record) {
record.unloadRecord();
record.destroy();
},

// ................
Expand Down Expand Up @@ -1622,7 +1621,8 @@ Store = Service.extend({

for (let i = 0; i < records.length; i++) {
record = records[i];
this.unloadRecord(record);
record.unloadRecord();
record.destroy(); // maybe within unloadRecord
}

typeMap.metadata = new EmptyObject();
Expand Down
39 changes: 1 addition & 38 deletions tests/unit/store/unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ testInDebug("unload a dirty record asserts", function(assert) {
});

test("unload a record", function(assert) {
assert.expect(6);
assert.expect(5);

run(function() {
store.push({
Expand All @@ -87,7 +87,6 @@ test("unload a record", function(assert) {
});

assert.equal(get(record, 'hasDirtyAttributes'), false, "record is not dirty");
assert.equal(get(record, 'isDestroyed'), true, 'record is destroyed');
assert.equal(get(record, 'isDeleted'), true, "record is deleted");

tryToFind = false;
Expand All @@ -98,42 +97,6 @@ test("unload a record", function(assert) {
});
});

test("unload a record - observers should be removed", function(assert) {
assert.expect(4);

run(function() {
store.push({
data: {
type: 'record',
id: '1',
attributes: {
title: 'toto'
}
}
});

store.findRecord('record', 1).then(function(record) {
Ember.addObserver(record, 'title', record, function() {
assert.ok(false, 'observer for record.title');
});

let observers = Ember.observersFor(record, 'title');
assert.equal(observers.length, 1, 'record should have 1 observer');

run(function() {
store.unloadRecord(record);
});

run(function() {
let observers = Ember.observersFor(record, 'title');
assert.equal(get(record, 'isDeleted'), true, 'record is deleted');
assert.equal(get(record, 'isDestroyed'), true, 'record is destroyed');
assert.equal(observers.length, 0, 'record should not have observers');
});
});
});
});

module("DS.Store - unload record with relationships");


Expand Down

0 comments on commit a136f67

Please sign in to comment.