Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update a test to fail #14843 #15110

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/ember-runtime/lib/mixins/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,23 @@ export function arrayContentDidChange(array, startIdx, removeAmt, addAmt) {
let cache = meta && meta.readableCache();

if (cache) {
let length = get(array, 'length') + removeAmt - addAmt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should likely avoid this get if we are not needing it.

This is getting complicated, if we go down this path we should do a helper function that can be unit tested (and more readable).

if (cache.firstObject !== undefined &&
objectAt(array, 0) !== cacheFor.get(cache, 'firstObject')) {
((startIdx === 0 && (addAmt > 0 || removeAmt > 0)) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still include objectAt(array, 0) !== cacheFor.get(cache, 'firstObject') guard?

(startIdx <= -length && (addAmt > 0 || removeAmt > 0)))) {
propertyWillChange(array, 'firstObject');
propertyDidChange(array, 'firstObject');
}

if (cache.lastObject !== undefined &&
objectAt(array, get(array, 'length') - 1) !== cacheFor.get(cache, 'lastObject')) {
((startIdx >= length && addAmt > 0) ||
(startIdx >= 0 && (startIdx + removeAmt >= length)) ||
(startIdx < 0 && (removeAmt >= -startIdx)))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still include objectAt(array, get(array, 'length') - 1) !== cacheFor.get(cache, 'lastObject')) { guard ?

propertyWillChange(array, 'lastObject');
propertyDidChange(array, 'lastObject');
}
}

return array;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/ember-runtime/tests/suites/mutable_array/insertAt.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,22 @@ suite.test('[A,B,C].insertAt(1,X) => [A,X,B,C] + notify', function() {
let after = [before[0], item, before[1], before[2]];
let obj = this.newObject(before);
let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
let objectAtCalls = [];

let objectAt = obj.objectAt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will require more test permutations, as the above code has many bounds

obj.objectAt = (ix) => {
objectAtCalls.push(ix);
return objectAt.call(obj, ix);
}

obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */

objectAtCalls.splice(0, objectAtCalls.length);

obj.insertAt(1, item);

deepEqual(objectAtCalls, [], 'objectAt is not called when only inserting items');

deepEqual(this.toArray(obj), after, 'post item results');
equal(get(obj, 'length'), after.length, 'length');

Expand Down