Skip to content

Commit

Permalink
Use array notation instead of at for accessing values (#8184)
Browse files Browse the repository at this point in the history
Array.at isn't supported in Safari until 15.4, using brackets isn't as
pretty, but enjoys universal support.
  • Loading branch information
jrjohnson authored Sep 16, 2022
1 parent b1ff997 commit 8947cb8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
42 changes: 42 additions & 0 deletions packages/-ember-data/tests/unit/record-arrays/record-array-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,48 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) {
}
);

deprecatedTest(
'#lastObject and #firstObject',
{ id: 'ember-data:deprecate-array-like', until: '5.0', count: 2 },
async function (assert) {
this.owner.register('model:tag', Tag);
let store = this.owner.lookup('service:store');

let records = store.push({
data: [
{
type: 'tag',
id: '1',
attributes: {
name: 'first',
},
},
{
type: 'tag',
id: '3',
},
{
type: 'tag',
id: '5',
attributes: {
name: 'fifth',
},
},
],
});

let recordArray = new RecordArray({
type: 'recordType',
identifiers: records.map(recordIdentifierFor),
store,
});

assert.strictEqual(recordArray.length, 3);
assert.strictEqual(recordArray.firstObject.id, '1');
assert.strictEqual(recordArray.lastObject.id, '5');
}
);

test('#update', async function (assert) {
let findAllCalled = 0;
let deferred = RSVP.defer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ class IdentifierArray {
if (DEPRECATE_ARRAY_LIKE) {
if (prop === 'firstObject') {
deprecateArrayLike(self.DEPRECATED_CLASS_NAME, prop, '[0]');
return receiver.at(0);
return receiver[0];
} else if (prop === 'lastObject') {
deprecateArrayLike(self.DEPRECATED_CLASS_NAME, prop, 'at(-1)');
return receiver.at(-1);
return receiver[receiver.length - 1];
}
}

Expand Down

0 comments on commit 8947cb8

Please sign in to comment.