Skip to content

Commit

Permalink
make sure record-array can still push internalModels if flag is off
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Dec 16, 2019
1 parent 1238ec4 commit bcee390
Showing 1 changed file with 51 additions and 23 deletions.
74 changes: 51 additions & 23 deletions packages/store/addon/-private/system/record-arrays/record-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@module @ember-data/store
*/
import ArrayProxy from '@ember/array/proxy';
import { RECORD_ARRAY_MANAGER_IDENTIFIERS } from '@ember-data/canary-features';
import { computed, get, set } from '@ember/object';
import { DEBUG } from '@glimmer/env';

Expand Down Expand Up @@ -32,7 +33,7 @@ function internalModelForIdentifier(store, identifier) {
@uses Ember.Evented
*/

export default ArrayProxy.extend(DeprecatedEvented, {
const RecordArray = ArrayProxy.extend(DeprecatedEvented, {
init(args) {
this._super(args);

Expand Down Expand Up @@ -173,28 +174,6 @@ export default ArrayProxy.extend(DeprecatedEvented, {
return this.store.findAll(this.modelName, { reload: true });
},

/**
Adds identifiers to the `RecordArray` without duplicates
@method _pushIdentifiers
@internal
@param {StableRecordIdentifier[]} identifiers
*/
_pushIdentifiers(identifiers) {
get(this, 'content').pushObjects(identifiers);
},

/**
Removes identifiers from the `RecordArray`.
@method _removeIdentifiers
@internal
@param {StableRecordIdentifier[]} identifiers
*/
_removeIdentifiers(identifiers) {
get(this, 'content').removeObjects(identifiers);
},

/**
Saves all of the records in the `RecordArray`.
Expand Down Expand Up @@ -272,3 +251,52 @@ export default ArrayProxy.extend(DeprecatedEvented, {
return get(this, 'content').map(identifier => internalModelForIdentifier(this.store, identifier).createSnapshot());
},
});

if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
/**
Adds identifiers to the `RecordArray` without duplicates
@method _pushIdentifiers
@internal
@param {StableRecordIdentifier[]} identifiers
*/
RecordArray.prototype._pushIdentifiers = function _pushIdentifiers(identifiers) {
get(this, 'content').pushObjects(identifiers);
};

/**
Removes identifiers from the `RecordArray`.
@method _removeIdentifiers
@internal
@param {StableRecordIdentifier[]} identifiers
*/
RecordArray.prototype._removeIdentifiers = function _removeIdentifiers(identifiers) {
get(this, 'content').removeObjects(identifiers);
};
} else {
/**
Adds an internal model to the `RecordArray` without duplicates
@method _pushInternalModels
@private
@param {InternalModel} internalModel
*/
RecordArray.prototype._pushInternalModels = function _pushInternalModels(internalModels) {
// pushObjects because the internalModels._recordArrays set was already
// consulted for inclusion, so addObject and its on .contains call is not
// required.
get(this, 'content').pushObjects(internalModels);
};

/**
Removes an internalModel to the `RecordArray`.
@method removeInternalModel
@private
@param {InternalModel} internalModel
*/
RecordArray.prototype._removeInternalModels = function _removeInternalModels(internalModels) {
get(this, 'content').removeObjects(internalModels);
};
}

export default RecordArray;

0 comments on commit bcee390

Please sign in to comment.