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

[BUGFIX beta] Don't use prototype extensions (arrayContent{Did,Will}Change, removeAt) #13534

Merged
merged 3 commits into from
Jun 16, 2016

Conversation

btecu
Copy link
Contributor

@btecu btecu commented May 20, 2016

Do not rely on prototype extensions for removeAt.
Related to #9269 and #10899.

colors.removeAt(0); // ['green', 'blue', 'yellow', 'orange']
colors.removeAt(2, 2); // ['green', 'blue']
colors.removeAt(4, 2); // Error: Index out of range
removeAt(colors, 0); // ['green', 'blue', 'yellow', 'orange']
Copy link
Member

Choose a reason for hiding this comment

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

These examples are showing how to use the mutable array mixin itself, I would think that we want to leave them as colors.removeAt(2, 2).

@rwjblue
Copy link
Member

rwjblue commented May 22, 2016

I'm not 100% sure on this. It seems like the right direction, but I wouldn't expect so many changes in tests that were already using things extended by NativeArray (i.e. Ember.A()). We still support Ember.A().removeAt(...) and friends, so we should continue to test them.

@krisselden
Copy link
Contributor

This is much like moving away from global API internally. In general, the tests migrated to the modules API but we should have tests that test we export the API onto Ember.

@stefanpenner
Copy link
Member

nice!

@krisselden
Copy link
Contributor

we should probably get this in ASAP as it is likely to bit quickly with the churn in glimmer 2 PRs

@krisselden
Copy link
Contributor

@rwjblue I think NativeArray could have a test but that any other tests not testing NativeArray directly should be using the standalone methods.

@btecu
Copy link
Contributor Author

btecu commented May 24, 2016

I've added one test and updated those comments.

@homu
Copy link
Contributor

homu commented May 24, 2016

☔ The latest upstream changes (presumably #13542) made this pull request unmergeable. Please resolve the merge conflicts.

@btecu
Copy link
Contributor Author

btecu commented May 24, 2016

Rebased

@@ -33,6 +35,40 @@ var EMPTY = [];

function K() { return this; }

export function removeAt(array, start, len) {
if ('number' === typeof start) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why extract this? it doesn't let you fire the events for this operation without using Ember.A().

Copy link
Contributor

Choose a reason for hiding this comment

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

the first argument is still required to be an ember array.

This isn't the equivalent of Ember.set(obj, key, val) where the obj can be a pojo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@krisselden to be able to call removeAt(array, 1, 2); in some other files such as arranged_content_test.js, although there might not be any advantage over array.removeAt(1, 2);.

Copy link
Contributor

@krisselden krisselden Jun 7, 2016

Choose a reason for hiding this comment

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

it if requires it to be an array, there isn't a point to the standalone, there is only value migrating to extend prototypes being false by default if Ember isn't doing Ember.A() all over the place, which is very slow (when extend prototypes is false).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. I've reverted that chage.

@homu
Copy link
Contributor

homu commented Jun 15, 2016

☔ The latest upstream changes (presumably #13680) made this pull request unmergeable. Please resolve the merge conflicts.

@btecu
Copy link
Contributor Author

btecu commented Jun 15, 2016

Rebased.

@rwjblue rwjblue merged commit ade1ca6 into emberjs:master Jun 16, 2016
@rwjblue
Copy link
Member

rwjblue commented Jun 16, 2016

Thanks @btecu, sorry for letting this linger so long.

@workmanw
Copy link

I'm not sure where or how to direct this feedback, so I'm going to do so here. If there is a better place for this discussion please let me know.

These commits are problematic for ember-data-model-fragments. The root of the problem is that because replace (and others) no longer call this.arrayContentDidChange(...), instead calling (arrayContentDidChange(this, ...), we are unable to override this function in our subclasses array. See here: array/stateful.js#L178-L190.

Ultimately I acknowledge that this an model-fragments issue. We were overriding a public API and now the way it's invoked internally from ember has change. So I don't think this is exactly API breakage, but I can definitely see this as problematic for anyone else in a similar situation.

@stefanpenner
Copy link
Member

@workmanw that sounds like a breaking change to me

@workmanw
Copy link

@stefanpenner If that's the case, I'd like to get this fixed up before ember 2.8 ships so it doesn't become an upgrade blocker for us, or anyone else. I can submit a PR to revert part of this commit so that internally ember will call this.arrayContentDidChange(...) instead of arrayContentDidChange(this, ...) if you think that's the right direction.

@btecu
Copy link
Contributor Author

btecu commented Aug 22, 2016

Seems unlikely that breaking the overriding of an api can be considered a breaking change.

@stefanpenner
Copy link
Member

@btecu it is a public API, although maybe this is a gray area?

@workmanw can you open an issue so we can track and decide if it is an issue or not?

@Serabe
Copy link
Member

Serabe commented Aug 22, 2016

@stefanpenner it seems so. Though a public API, it is a method to call to notify about the change, not to be notified about it. Interesting issue!

@workmanw
Copy link

@stefanpenner Yea, absolutely.

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.

7 participants