Skip to content

Commit

Permalink
Merge pull request #4870 from emberjs/hjdivad/cleanup-names-many-array
Browse files Browse the repository at this point in the history
More record -> internalModel fixes
  • Loading branch information
stefanpenner authored Mar 16, 2017
2 parents 5036248 + d7d77b6 commit c8e45ec
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions addon/-private/system/many-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {

//a hack for not removing new records
//TODO remove once we have proper diffing
let newRecords = this.currentState.filter(
let newInternalModels = this.currentState.filter(
// only add new records which are not yet in the canonical state of this
// relationship (a new record can be in the canonical state if it has
// been 'acknowleged' to be in the relationship via a store.push)
(internalModel) => internalModel.isNew() && toSet.indexOf(internalModel) === -1
);
toSet = toSet.concat(newRecords);
toSet = toSet.concat(newInternalModels);

// diff to find changes
let diff = diffArray(this.currentState, toSet);
Expand Down Expand Up @@ -186,15 +186,15 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
},

//TODO(Igor) optimize
internalRemoveRecords(records) {
internalRemoveInternalModels(records) {
for (let i=0; i < records.length; i++) {
let index = this.currentState.indexOf(records[i]);
this.internalReplace(index, 1);
}
},

//TODO(Igor) optimize
internalAddRecords(records, idx) {
internalAddInternalModels(records, idx) {
if (idx === undefined) {
idx = this.currentState.length;
}
Expand All @@ -205,10 +205,10 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
let records;
if (amt > 0) {
records = this.currentState.slice(idx, idx+amt);
this.get('relationship').removeRecords(records);
this.get('relationship').removeInternalModels(records);
}
if (objects) {
this.get('relationship').addRecords(objects.map(obj => obj._internalModel), idx);
this.get('relationship').addInternalModels(objects.map(obj => obj._internalModel), idx);
}
},

Expand Down
2 changes: 1 addition & 1 deletion addon/-private/system/relationships/has-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default function hasMany(type, options) {

let relationship = this._internalModel._relationships.get(key);
relationship.clear();
relationship.addRecords(records.map(record => get(record, '_internalModel')));
relationship.addInternalModels(records.map(record => get(record, '_internalModel')));
return relationship.getRecords();
}
}).meta(meta);
Expand Down
4 changes: 2 additions & 2 deletions addon/-private/system/relationships/state/has-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class ManyRelationship extends Relationship {
}
super.addRecord(record, idx);
// make lazy later
this.manyArray.internalAddRecords([record], idx);
this.manyArray.internalAddInternalModels([record], idx);
}

removeCanonicalRecordFromOwn(record, idx) {
Expand Down Expand Up @@ -125,7 +125,7 @@ export default class ManyRelationship extends Relationship {
//TODO(Igor) not used currently, fix
manyArray.currentState.removeAt(idx);
} else {
manyArray.internalRemoveRecords([record]);
manyArray.internalRemoveInternalModels([record]);
}
}

Expand Down
22 changes: 11 additions & 11 deletions addon/-private/system/relationships/state/relationship.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
addCanonicalRecord,
addCanonicalRecords,
addRecord,
addRecords,
addInternalModels,
clear,
findLink,
flushCanonical,
Expand All @@ -21,7 +21,7 @@ const {
removeRecord,
removeRecordFromInverse,
removeRecordFromOwn,
removeRecords,
removeInternalModels,
setHasData,
setHasLoaded,
updateLink,
Expand All @@ -31,7 +31,7 @@ const {
'addCanonicalRecord',
'addCanonicalRecords',
'addRecord',
'addRecords',
'addInternalModels',
'clear',
'findLink',
'flushCanonical',
Expand All @@ -45,7 +45,7 @@ const {
'removeRecord',
'removeRecordFromInverse',
'removeRecordFromOwn',
'removeRecords',
'removeInternalModels',
'setHasData',
'setHasLoaded',
'updateLink',
Expand Down Expand Up @@ -125,15 +125,15 @@ export default class Relationship {
}
}

removeRecords(records) {
heimdall.increment(removeRecords);
records.forEach((record) => this.removeRecord(record));
removeInternalModels(internalModels) {
heimdall.increment(removeInternalModels);
internalModels.forEach((intenralModel) => this.removeRecord(intenralModel));
}

addRecords(records, idx) {
heimdall.increment(addRecords);
records.forEach(record => {
this.addRecord(record, idx);
addInternalModels(internalModels, idx) {
heimdall.increment(addInternalModels);
internalModels.forEach(internalModel => {
this.addRecord(internalModel, idx);
if (idx !== undefined) {
idx++;
}
Expand Down

0 comments on commit c8e45ec

Please sign in to comment.