Skip to content

Prefer generic insertAt over prototype_extensions#16048

Closed
wongpeiyi wants to merge 4 commits intoemberjs:masterfrom
wongpeiyi:array-internals-insertAt
Closed

Prefer generic insertAt over prototype_extensions#16048
wongpeiyi wants to merge 4 commits intoemberjs:masterfrom
wongpeiyi:array-internals-insertAt

Conversation

@wongpeiyi
Copy link

#15501 insertAt

Duplicated one test for testing the prototype extension still works.

@wongpeiyi
Copy link
Author

@Serabe can you see if this is in line with what the epic requires? Don't think insertAt was actually extracted despite the checkbox being checked.

Would like to take a stab at the remainder in this fashion if this looks ok

suite.module('insertAt');

suite.test('[].insertAt(0, X) => [X] + notify', function() {
suite.test('insertAt([], 0, X) => [X] + notify', function() {
Copy link
Member

Choose a reason for hiding this comment

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

I think its beneficial to have some tests still use the array prototype until it is fully removed. I'm not sure if we have tests that specific check for this already elsewhere or if we should add those checks here

Copy link
Author

Choose a reason for hiding this comment

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

I followed the example of https://github.com/emberjs/ember.js/pull/13534/files#diff-d1dc85945ef368d3bcdd3e01234d3f8eR118 and duplicated the last test, keeping it to use the array prototype extension. See https://github.com/emberjs/ember.js/pull/16048/files/ac0a1455b73d59a5b1256f81096343a90f846ebd#diff-eaa813784954ae3195242cb1d1763b7dR171

I agree it's not very clear though. I can change the test's label but not sure if the test itself needs to be more specific.

Copy link
Member

Choose a reason for hiding this comment

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

I guess what I'm trying to get at is that we should maintain at least one test that simply checks that the prototypes are still extended. This could simply be something like:

test('that prototypes are properly extended', function(assert) {
  assert.equal(typeof [].insertAt, 'function');
  // ... all other extensions
});

I don't know if we have something like this already but if not we should add it

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean something like https://github.com/emberjs/ember.js/blob/master/packages/ember-runtime/tests/system/string/camelize_test.js#L6-L10 but the inverse?

Added a commit for that for both removeAt and insertAt

Copy link
Member

Choose a reason for hiding this comment

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

Yep that looks good. Thanks @wongpeiyi

@Serabe
Copy link
Member

Serabe commented Jan 5, 2018

LGTM. Need approval from core yet.

@locks
Copy link
Contributor

locks commented Jan 8, 2018

I see with my little eye some git conflicts. Can you take a look @wongpeiyi?

@wongpeiyi wongpeiyi force-pushed the array-internals-insertAt branch 3 times, most recently from 80207d6 to d12f046 Compare January 9, 2018 13:22
@wongpeiyi
Copy link
Author

@locks thanks, rebased.

@locks locks requested a review from krisselden January 9, 2018 15:13
@mmun mmun self-requested a review January 10, 2018 06:48
return array;
}

return array.splice(idx, amt, ...objects);
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, when the array has .replace we return the mutated array, but if it doesn't we return the deleted elements.

Can you tweak this so that its consistent?

Copy link
Author

@wongpeiyi wongpeiyi Jan 16, 2018

Choose a reason for hiding this comment

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

Thanks, added a commit to address that. Also brought it more in line with NativeArray

@rwjblue tagging in case this was missed. Had to rebase again, tests failing because of master

import Enumerable from './enumerable';
import { Error as EmberError } from 'ember-debug';

function replace(array, idx, amt, objects) {
Copy link
Member

Choose a reason for hiding this comment

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

I would have expected this to be much closer to NativeArray#replace...

@wongpeiyi wongpeiyi force-pushed the array-internals-insertAt branch 2 times, most recently from ef3e851 to 9d9c96f Compare January 16, 2018 07:16
@wongpeiyi wongpeiyi force-pushed the array-internals-insertAt branch from 9d9c96f to 0f23feb Compare January 17, 2018 12:55
@wongpeiyi
Copy link
Author

@rwjblue can I get your eyes on this again? Had to rebase, and tests failed because of master at that time

@mmun
Copy link
Member

mmun commented Feb 23, 2018

@wongpeiyi FYI, I think we're going to take a slightly different approach. I will lay the foundation down soon and possibly start up a new quest issue.

@rwjblue rwjblue closed this Feb 24, 2018
@rwjblue
Copy link
Member

rwjblue commented Feb 24, 2018

Sorry for the run around here @wongpeiyi ☹️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants