Skip to content

Commit

Permalink
[BUGFIX beta] Removes get record from InternalModel. (#4901)
Browse files Browse the repository at this point in the history
* [BUGFIX beta] Removes `get record` from InternalModel. Prefer `getRecord `.

Fixes #4756

* Node version for tests.

* `getRecord` instead of `_record` on `RecordReference.prototype.value`.
  • Loading branch information
esbanarango authored and bmac committed Mar 28, 2017
1 parent b7166f6 commit 551e39a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
42 changes: 19 additions & 23 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function extractPivotName(name) {

function areAllModelsUnloaded(internalModels) {
for (let i=0; i<internalModels.length; ++i) {
let record = internalModels[i].record;
let record = internalModels[i]._record;
if (record && !(record.get('isDestroyed') || record.get('isDestroying'))) {
return false;
}
Expand Down Expand Up @@ -316,10 +316,6 @@ export default class InternalModel {
return this.currentState.dirtyType;
}

get record() {
return this._record;
}

getRecord() {
if (!this._record && !this._isDematerializing) {
heimdall.increment(materializeRecord);
Expand Down Expand Up @@ -364,9 +360,9 @@ export default class InternalModel {
}

dematerializeRecord() {
if (this.record) {
if (this._record) {
this._isDematerializing = true;
this.record.destroy();
this._record.destroy();
this.destroyRelationships();
this.updateRecordArrays();
this.resetRecord();
Expand All @@ -388,14 +384,14 @@ export default class InternalModel {
startedReloading() {
this.isReloading = true;
if (this.hasRecord) {
set(this.record, 'isReloading', true);
set(this._record, 'isReloading', true);
}
}

finishedReloading() {
this.isReloading = false;
if (this.hasRecord) {
set(this.record, 'isReloading', false);
set(this._record, 'isReloading', false);
}
}

Expand Down Expand Up @@ -515,7 +511,7 @@ export default class InternalModel {
}

destroy() {
assert("Cannot destroy an internalModel while its record is materialized", !this.record || this.record.get('isDestroyed') || this.record.get('isDestroying'));
assert("Cannot destroy an internalModel while its record is materialized", !this._record || this._record.get('isDestroyed') || this._record.get('isDestroying'));

this.store._internalModelDestroyed(this);
this._isDestroyed = true;
Expand Down Expand Up @@ -543,7 +539,7 @@ export default class InternalModel {
this.pushedData();

if (this.hasRecord) {
this.record._notifyProperties(changedKeys);
this._record._notifyProperties(changedKeys);
}
this.didInitializeData();
}
Expand Down Expand Up @@ -709,25 +705,25 @@ export default class InternalModel {

notifyHasManyAdded(key, record, idx) {
if (this.hasRecord) {
this.record.notifyHasManyAdded(key, record, idx);
this._record.notifyHasManyAdded(key, record, idx);
}
}

notifyHasManyRemoved(key, record, idx) {
if (this.hasRecord) {
this.record.notifyHasManyRemoved(key, record, idx);
this._record.notifyHasManyRemoved(key, record, idx);
}
}

notifyBelongsToChanged(key, record) {
if (this.hasRecord) {
this.record.notifyBelongsToChanged(key, record);
this._record.notifyBelongsToChanged(key, record);
}
}

notifyPropertyChange(key) {
if (this.hasRecord) {
this.record.notifyPropertyChange(key);
this._record.notifyPropertyChange(key);
}
}

Expand Down Expand Up @@ -763,7 +759,7 @@ export default class InternalModel {
this.send('rolledBack');

if (dirtyKeys && dirtyKeys.length > 0) {
this.record._notifyProperties(dirtyKeys);
this._record._notifyProperties(dirtyKeys);
}
}

Expand Down Expand Up @@ -818,7 +814,7 @@ export default class InternalModel {

this.currentState = state;
if (this.hasRecord) {
set(this.record, 'currentState', state);
set(this._record, 'currentState', state);
}

for (i = 0, l = setups.length; i < l; i++) {
Expand Down Expand Up @@ -857,7 +853,7 @@ export default class InternalModel {
return;
}
let triggers = this._deferredTriggers;
let record = this.record;
let record = this._record;
let trigger = record.trigger;
for (let i = 0, l= triggers.length; i<l; i++) {
trigger.apply(record, triggers[i]);
Expand Down Expand Up @@ -977,8 +973,8 @@ export default class InternalModel {
setId(id) {
assert('A record\'s id cannot be changed once it is in the loaded state', this.id === null || this.id === id || this.isNew());
this.id = id;
if (this.record.get('id') !== id) {
this.record.set('id', id);
if (this._record.get('id') !== id) {
this._record.set('id', id);
}
}

Expand All @@ -987,7 +983,7 @@ export default class InternalModel {
this.isError = true;

if (this.hasRecord) {
this.record.setProperties({
this._record.setProperties({
isError: true,
adapterError: error
});
Expand All @@ -999,7 +995,7 @@ export default class InternalModel {
this.isError = false;

if (this.hasRecord) {
this.record.setProperties({
this._record.setProperties({
isError: false,
adapterError: null
});
Expand Down Expand Up @@ -1035,7 +1031,7 @@ export default class InternalModel {

if (!data) { return; }

this.record._notifyProperties(changedKeys);
this._record._notifyProperties(changedKeys);
}

addErrorMessageToAttribute(attribute, message) {
Expand Down
4 changes: 3 additions & 1 deletion addon/-private/system/references/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ RecordReference.prototype.push = function(objectOrPromise) {
@return {DS.Model} the record for this RecordReference
*/
RecordReference.prototype.value = function() {
return this.internalModel.record;
if (this.internalModel.hasRecord) {
return this.internalModel.getRecord();
}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion addon/-private/system/relationships/state/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class BelongsToRelationship extends Relationship {

// reload record, if it is already loaded
if (this.inverseRecord && this.inverseRecord.hasRecord) {
return this.inverseRecord.record.reload();
return this.inverseRecord.getRecord().reload();
}

return this.findRecord();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/store/adapter-interop-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ test('store._scheduleFetchMany should not resolve until all the records are reso

return run(() => {
return store._scheduleFetchMany(internalModels).then(() => {
let unloadedRecords = Ember.A(internalModels.map(r => r.record)).filterBy('isEmpty');
let unloadedRecords = Ember.A(internalModels.map(r => r.getRecord())).filterBy('isEmpty');

assert.equal(get(unloadedRecords, 'length'), 0, 'All unloaded records should be loaded');
});
Expand Down

0 comments on commit 551e39a

Please sign in to comment.