Skip to content

Commit

Permalink
[Cleanup]: Remove RECORD_ARRAY_MANAGER_IDENTIFIERS (#7394)
Browse files Browse the repository at this point in the history
* [Cleanup]: Remove RECORD_ARRAY_MANAGER_IDENTIFIERS
  • Loading branch information
snewcomer authored Dec 5, 2020
1 parent f162241 commit 7756aed
Show file tree
Hide file tree
Showing 16 changed files with 1,255 additions and 2,693 deletions.
2 changes: 0 additions & 2 deletions packages/-ember-data/node-tests/fixtures/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ module.exports = {
'(private) @ember-data/store RecordArray#objectAtContent',
'(private) @ember-data/store RecordArray#store',
'(private) @ember-data/store RecordArrayManager#_associateWithRecordArray',
'(private) @ember-data/store RecordArray#_pushInternalModels',
'(private) @ember-data/store RecordArray#_removeInternalModels',
'(private) @ember-data/store RecordArray#_unregisterFromManager',
'(private) @ember-data/store SnapshotRecordArray#_recordArray',
'(private) @ember-data/store SnapshotRecordArray#_snapshots',
Expand Down
87 changes: 26 additions & 61 deletions packages/-ember-data/tests/integration/record-array-manager-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { A } from '@ember/array';
import OrderedSet from '@ember/ordered-set';
import { settled } from '@ember/test-helpers';

import { module, test } from 'qunit';

import { setupTest } from 'ember-qunit';

import RESTAdapter from '@ember-data/adapter/rest';
import { RECORD_ARRAY_MANAGER_IDENTIFIERS } from '@ember-data/canary-features';
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import { recordIdentifierFor } from '@ember-data/store';

Expand Down Expand Up @@ -102,48 +100,32 @@ module('integration/record_array_manager', function(hooks) {

assert.equal(allSummary.called.length, 0, 'initial: no calls to all.willDestroy');
assert.equal(adapterPopulatedSummary.called.length, 0, 'initial: no calls to adapterPopulated.willDestroy');
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
assert.equal(
manager.getRecordArraysForIdentifier(internalPersonModel.identifier).size,
1,
'initial: expected the person to be a member of 1 recordArrays'
);
} else {
assert.equal(
internalPersonModel._recordArrays.size,
1,
'initial: expected the person to be a member of 1 recordArrays'
);
}
assert.equal(
manager.getRecordArraysForIdentifier(internalPersonModel.identifier).size,
1,
'initial: expected the person to be a member of 1 recordArrays'
);
assert.equal('person' in manager._liveRecordArrays, true, 'initial: we have a live array for person');

all.destroy();
await settled();

if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
assert.equal(
manager.getRecordArraysForIdentifier(internalPersonModel.identifier).size,
0,
'expected the person to be a member of no recordArrays'
);
} else {
assert.equal(internalPersonModel._recordArrays.size, 0, 'expected the person to be a member of no recordArrays');
}
assert.equal(
manager.getRecordArraysForIdentifier(internalPersonModel.identifier).size,
0,
'expected the person to be a member of no recordArrays'
);
assert.equal(allSummary.called.length, 1, 'all.willDestroy called once');
assert.equal('person' in manager._liveRecordArrays, false, 'no longer have a live array for person');

manager.destroy();
await settled();

if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
assert.equal(
manager.getRecordArraysForIdentifier(internalPersonModel.identifier).size,
0,
'expected the person to be a member of no recordArrays'
);
} else {
assert.equal(internalPersonModel._recordArrays.size, 0, 'expected the person to be a member of no recordArrays');
}
assert.equal(
manager.getRecordArraysForIdentifier(internalPersonModel.identifier).size,
0,
'expected the person to be a member of no recordArrays'
);
assert.equal(allSummary.called.length, 1, 'all.willDestroy still only called once');
assert.equal(adapterPopulatedSummary.called.length, 1, 'adapterPopulated.willDestroy called once');
});
Expand Down Expand Up @@ -269,41 +251,24 @@ module('integration/record_array_manager', function(hooks) {
});

test('createRecordArray with optional content', function(assert) {
let content;
let record;
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
record = store.push({
data: {
type: 'car',
id: '1',
attributes: {
make: 'BMC',
model: 'Mini Cooper',
},
},
});
content = A([recordIdentifierFor(record)]);
} else {
let internalModel = {
_recordArrays: new OrderedSet(),
getRecord() {
return record;
let record = store.push({
data: {
type: 'car',
id: '1',
attributes: {
make: 'BMC',
model: 'Mini Cooper',
},
};

content = A([internalModel]);
}
},
});
let content = A([recordIdentifierFor(record)]);

let recordArray = manager.createRecordArray('foo', content);

assert.equal(recordArray.modelName, 'foo', 'has modelName');
assert.equal(recordArray.isLoaded, true, 'isLoaded is true');
assert.equal(recordArray.manager, manager, 'recordArray has manager');
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
assert.deepEqual(recordArray.get('content'), [recordIdentifierFor(record)], 'recordArray has content');
} else {
assert.equal(recordArray.get('content'), content);
}
assert.deepEqual(recordArray.get('content'), [recordIdentifierFor(record)], 'recordArray has content');
assert.deepEqual(recordArray.toArray(), [record], 'toArray works');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { setupTest } from 'ember-qunit';

import Adapter from '@ember-data/adapter';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import { RECORD_ARRAY_MANAGER_IDENTIFIERS } from '@ember-data/canary-features';
import Model, { attr } from '@ember-data/model';
import JSONAPISerializer from '@ember-data/serializer/json-api';
import { recordIdentifierFor } from '@ember-data/store';
Expand Down Expand Up @@ -68,17 +67,10 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula

let results = store.push(payload);

if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
recordArray._setIdentifiers(
results.map(r => recordIdentifierFor(r)),
payload
);
} else {
recordArray._setInternalModels(
results.map(r => r._internalModel),
payload
);
}
recordArray._setIdentifiers(
results.map(r => recordIdentifierFor(r)),
payload
);

assert.equal(recordArray.get('length'), 3, 'expected recordArray to contain exactly 3 records');

Expand Down Expand Up @@ -123,17 +115,10 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula
};

let results = store.push(payload);
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
recordArray._setIdentifiers(
results.map(r => recordIdentifierFor(r)),
payload
);
} else {
recordArray._setInternalModels(
results.map(r => r._internalModel),
payload
);
}
recordArray._setIdentifiers(
results.map(r => recordIdentifierFor(r)),
payload
);
assert.equal(recordArray.get('meta.foo'), 'bar', 'expected meta.foo to be bar from payload');
});

Expand Down Expand Up @@ -171,17 +156,10 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula
};

let results = store.push(payload);
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
recordArray._setIdentifiers(
results.map(r => recordIdentifierFor(r)),
payload
);
} else {
recordArray._setInternalModels(
results.map(r => r._internalModel),
payload
);
}
recordArray._setIdentifiers(
results.map(r => recordIdentifierFor(r)),
payload
);

assert.equal(
recordArray.get('links.first'),
Expand Down
Loading

0 comments on commit 7756aed

Please sign in to comment.