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

[FEATURE ember-runtime-enumerable-includes] Implements Array.includes and deprecates Array.contains #13553

Merged
merged 1 commit into from Jun 4, 2016

Conversation

Projects
None yet
5 participants
@bmeurant
Contributor

bmeurant commented May 24, 2016

Implementation of emberjs/rfcs#136

TODO :

  • Implement Enumerable.includes
  • Implement Array.includes
  • Deprecate contains under feature flag
  • Replace usages of contains by includes
  • Update docs, guides (emberjs/guides#1439) & API. To be merged once feature enabled.
  • Write deprecation guide (emberjs/website#2600) & add url in deprecate call
  • Rebase / squash
@alexspeller

This comment has been minimized.

Show comment
Hide comment
@alexspeller

alexspeller May 24, 2016

Contributor

Oh awesome, thanks for getting this implementation done!

Contributor

alexspeller commented May 24, 2016

Oh awesome, thanks for getting this implementation done!

@bmeurant

This comment has been minimized.

Show comment
Hide comment
@bmeurant

bmeurant May 24, 2016

Contributor

Here is a first proposal for emberjs/rfcs#136. Work is in progress and feedbacks expected.

I made the asumption that we have to keep Enumerable & Array APIs consistent and then have to provide a consistent includes method in Enumerable (with no index). Let me know if this is not expected.

Aliasing contains with the new includes method can break some existing apps because, according to the spec (https://tc39.github.io/ecma262/2016/#sec-array.prototype.includes), includes relies on the SameValueZero algorithm and actual contains relies on strict equality leading to differences in NaN detections (I will document it). Can we still make this ?

Contributor

bmeurant commented May 24, 2016

Here is a first proposal for emberjs/rfcs#136. Work is in progress and feedbacks expected.

I made the asumption that we have to keep Enumerable & Array APIs consistent and then have to provide a consistent includes method in Enumerable (with no index). Let me know if this is not expected.

Aliasing contains with the new includes method can break some existing apps because, according to the spec (https://tc39.github.io/ecma262/2016/#sec-array.prototype.includes), includes relies on the SameValueZero algorithm and actual contains relies on strict equality leading to differences in NaN detections (I will document it). Can we still make this ?

@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic May 24, 2016

Member

@bmeurant Thanks :-)

contains should not be aliased to includes. Contains should keep its current implementation, and we can deprecate it though we will likely do that in a separate PR. In this PR it should simply retain its current behavior.

Member

mixonic commented May 24, 2016

@bmeurant Thanks :-)

contains should not be aliased to includes. Contains should keep its current implementation, and we can deprecate it though we will likely do that in a separate PR. In this PR it should simply retain its current behavior.

@bmeurant

This comment has been minimized.

Show comment
Hide comment
@bmeurant

bmeurant May 24, 2016

Contributor

@mixonic thx for your feedback.

I updated this PR to keep current implementation for Enumerable.contains & Array.contains.

we can deprecate it though we will likely do that in a separate PR

Does it means that I should also remove @deprecated and deprecation warning for now ?

Contributor

bmeurant commented May 24, 2016

@mixonic thx for your feedback.

I updated this PR to keep current implementation for Enumerable.contains & Array.contains.

we can deprecate it though we will likely do that in a separate PR

Does it means that I should also remove @deprecated and deprecation warning for now ?

@rwjblue

This comment has been minimized.

Show comment
Hide comment
@rwjblue

rwjblue May 24, 2016

Member

I believe that the deprecation should be included here when the feature flag is enabled.

Member

rwjblue commented May 24, 2016

I believe that the deprecation should be included here when the feature flag is enabled.

@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic May 24, 2016

Member

@rwjblue I am easily convinced, was just erring on the conservative side. @bmeurant please include the deprecation behind the feature flag! :-)

Member

mixonic commented May 24, 2016

@rwjblue I am easily convinced, was just erring on the conservative side. @bmeurant please include the deprecation behind the feature flag! :-)

@bmeurant

This comment has been minimized.

Show comment
Hide comment
@bmeurant

bmeurant May 25, 2016

Contributor

@mixonic I added feature flag and move deprecation behind it. Let me know if I forgotten something.

I also removed @deprecated from API because contains is not actually deprecated if feature is not enabled, right ?

But I was wondering: doing that, users will loose the information that contains will be deprecated soon and that they should use includes instead. Is it exists a way to provide this kind of information in APIs ?

Contributor

bmeurant commented May 25, 2016

@mixonic I added feature flag and move deprecation behind it. Let me know if I forgotten something.

I also removed @deprecated from API because contains is not actually deprecated if feature is not enabled, right ?

But I was wondering: doing that, users will loose the information that contains will be deprecated soon and that they should use includes instead. Is it exists a way to provide this kind of information in APIs ?

@bmeurant bmeurant changed the title from [WIP][FEATURE contains-to-includes] Implements Array.includes and deprecates Array.contains to [FEATURE contains-to-includes] Implements Array.includes and deprecates Array.contains May 25, 2016

@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic May 27, 2016

Member

@bmeurant Yeah the documentation may require some followup tweaks. Feature flagging things like the @deprecated flag is tricky :-/. I think you should feel free to create a followup issue of things to do once the feature is "go'd" for beta.

Member

mixonic commented May 27, 2016

@bmeurant Yeah the documentation may require some followup tweaks. Feature flagging things like the @deprecated flag is tricky :-/. I think you should feel free to create a followup issue of things to do once the feature is "go'd" for beta.

@mixonic

View changes

Show outdated Hide outdated FEATURES.md
@mixonic

View changes

Show outdated Hide outdated packages/ember-runtime/lib/mixins/enumerable.js
@mixonic

View changes

Show outdated Hide outdated packages/ember-runtime/lib/mixins/mutable_array.js
var suite = SuiteModuleBuilder.create();
suite.module('includes');

This comment has been minimized.

@mixonic

mixonic May 27, 2016

Member

Should include a test/tests without a starting position

@mixonic

mixonic May 27, 2016

Member

Should include a test/tests without a starting position

This comment has been minimized.

@bmeurant

bmeurant May 27, 2016

Contributor

Tests without starting position are imported from Enumerable test suite, no ?

@bmeurant

bmeurant May 27, 2016

Contributor

Tests without starting position are imported from Enumerable test suite, no ?

This comment has been minimized.

@mixonic

mixonic May 27, 2016

Member

I'm unsure what you mean, maybe I am missing something. This code tests the implementation of Array#includes. How are the tests for Enumerable#includes applied to an array?

@mixonic

mixonic May 27, 2016

Member

I'm unsure what you mean, maybe I am missing something. This code tests the implementation of Array#includes. How are the tests for Enumerable#includes applied to an array?

@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic May 27, 2016

Member

@bmeurant heh, there are no tests for Array#contains?! Can you add one asserting basic behavior and the deprecation please?

This is looking pretty good after some tweaks!

Member

mixonic commented May 27, 2016

@bmeurant heh, there are no tests for Array#contains?! Can you add one asserting basic behavior and the deprecation please?

This is looking pretty good after some tweaks!

@mixonic

View changes

Show outdated Hide outdated packages/ember-runtime/lib/mixins/array.js
@mixonic

View changes

Show outdated Hide outdated packages/ember-runtime/tests/suites/enumerable/includes.js
@mixonic

View changes

Show outdated Hide outdated features.json
@mixonic

View changes

Show outdated Hide outdated packages/ember-runtime/lib/mixins/enumerable.js
@bmeurant

This comment has been minimized.

Show comment
Hide comment
@bmeurant

bmeurant May 27, 2016

Contributor

Thx for feedbacks, I'll work on it ASAP

Contributor

bmeurant commented May 27, 2016

Thx for feedbacks, I'll work on it ASAP

@bmeurant

This comment has been minimized.

Show comment
Hide comment
@bmeurant

bmeurant May 27, 2016

Contributor

It seemed to me that Array#contains tests are also imported and run from Enumerable#contains tests. Did I miss something ?

Contributor

bmeurant commented May 27, 2016

It seemed to me that Array#contains tests are also imported and run from Enumerable#contains tests. Did I miss something ?

@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic May 27, 2016

Member

Ah I see @bmeurant :-) right there is no contains on arrays, only on enumerable 👍

Member

mixonic commented May 27, 2016

Ah I see @bmeurant :-) right there is no contains on arrays, only on enumerable 👍

@bmeurant

This comment has been minimized.

Show comment
Hide comment
@bmeurant

bmeurant May 27, 2016

Contributor

I wanted to add a test to verify assertion calling Enumerable#includes with a second argument but, because tests defined on Enumerable are also run on Array suites, I did not find a good way to do it. Any advice ?

Contributor

bmeurant commented May 27, 2016

I wanted to add a test to verify assertion calling Enumerable#includes with a second argument but, because tests defined on Enumerable are also run on Array suites, I did not find a good way to do it. Any advice ?

@bmeurant

View changes

Show outdated Hide outdated packages/ember-runtime/lib/mixins/enumerable.js
return found;
},
without(value) {

This comment has been minimized.

@bmeurant

bmeurant May 27, 2016

Contributor

I prefered replacing without behind feature flag to not add multiple isEnabled calls in original method

@bmeurant

bmeurant May 27, 2016

Contributor

I prefered replacing without behind feature flag to not add multiple isEnabled calls in original method

This comment has been minimized.

@mixonic

mixonic May 30, 2016

Member

👍

@mixonic
deprecate(
'`Enumerable#contains` is deprecated, use `Enumerable#includes` instead.',
false,
{ id: 'ember-runtime.enumerable-contains', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_enumerable-contains' }

This comment has been minimized.

@bmeurant

bmeurant May 27, 2016

Contributor

I did not change deprecation id because feature is about includes but deprecation is about contains.

But I don't know if it is accepted. Let me know

@bmeurant

bmeurant May 27, 2016

Contributor

I did not change deprecation id because feature is about includes but deprecation is about contains.

But I don't know if it is accepted. Let me know

This comment has been minimized.

@mixonic

mixonic May 30, 2016

Member

the deprecation id and feature id are totally distinct. Seems fine to use different names 👍

@mixonic

mixonic May 30, 2016

Member

the deprecation id and feature id are totally distinct. Seems fine to use different names 👍

},
without(value) {
if (!this.includes(value)) {

This comment has been minimized.

@mixonic

mixonic May 30, 2016

Member

Calling includes before the forEach means we walk the contents of the array twice. Additionally it seems a bit unexpected for without() to sometimes return a new array, and sometimes return the array passed in.

I'd prefer to drop the includes check and just run the array builder.

@mixonic

mixonic May 30, 2016

Member

Calling includes before the forEach means we walk the contents of the array twice. Additionally it seems a bit unexpected for without() to sometimes return a new array, and sometimes return the array passed in.

I'd prefer to drop the includes check and just run the array builder.

This comment has been minimized.

@bmeurant

bmeurant May 30, 2016

Contributor

I think I'd also prefer but it seems that returning the same instance if not included (or not contained), is part of the API since it is tested here : https://github.com/emberjs/ember.js/blob/master/packages/ember-runtime/tests/suites/enumerable/without.js#L19

Does this PR should also change this behaviour?

I could make it, of course, and update the deprecation guide. But in any case, I propose to update without API doc to explicitely mention it.

@bmeurant

bmeurant May 30, 2016

Contributor

I think I'd also prefer but it seems that returning the same instance if not included (or not contained), is part of the API since it is tested here : https://github.com/emberjs/ember.js/blob/master/packages/ember-runtime/tests/suites/enumerable/without.js#L19

Does this PR should also change this behaviour?

I could make it, of course, and update the deprecation guide. But in any case, I propose to update without API doc to explicitely mention it.

This comment has been minimized.

@mixonic

mixonic May 30, 2016

Member

👍 to updating the docs and keeping the current behavior. Great catch.

The without method on enumerables and on mixins just should just 🔥 🔥 🔥. On enumerables we can just use reject which seems more sane, and on mixins the functionality is only used for native array prototype application. I attempted killing it once and ran out of steam.

@mixonic

mixonic May 30, 2016

Member

👍 to updating the docs and keeping the current behavior. Great catch.

The without method on enumerables and on mixins just should just 🔥 🔥 🔥. On enumerables we can just use reject which seems more sane, and on mixins the functionality is only used for native array prototype application. I attempted killing it once and ran out of steam.

@mixonic

View changes

Show outdated Hide outdated packages/ember/tests/component_registration_test.js
@mixonic

View changes

Show outdated Hide outdated packages/ember-runtime/lib/mixins/mutable_array.js
@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic May 30, 2016

Member

@bmeurant it seems ok to add a test for contains without an offset in packages/ember-runtime/tests/mixins/enumerable_test.js, since it only impacts enumerables.

Member

mixonic commented May 30, 2016

@bmeurant it seems ok to add a test for contains without an offset in packages/ember-runtime/tests/mixins/enumerable_test.js, since it only impacts enumerables.

@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic May 30, 2016

Member

Thanks for your continued work on this 😄 it looks really close, and quite nice!

Member

mixonic commented May 30, 2016

Thanks for your continued work on this 😄 it looks really close, and quite nice!

@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic May 30, 2016

Member

Looking nice. A rebase/squash to some number is semantically meaningful commits (one or more) would be great, each prefixed with [FEATURE ember-runtime-enumerable-includes] would be great.

Member

mixonic commented May 30, 2016

Looking nice. A rebase/squash to some number is semantically meaningful commits (one or more) would be great, each prefixed with [FEATURE ember-runtime-enumerable-includes] would be great.

@mixonic mixonic changed the title from [FEATURE contains-to-includes] Implements Array.includes and deprecates Array.contains to [FEATURE ember-runtime-enumerable-includes] Implements Array.includes and deprecates Array.contains May 30, 2016

@bmeurant

This comment has been minimized.

Show comment
Hide comment
@bmeurant

bmeurant May 30, 2016

Contributor

Done 👌

Contributor

bmeurant commented May 30, 2016

Done 👌

@homu

This comment has been minimized.

Show comment
Hide comment
@homu

homu Jun 1, 2016

Contributor

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

Contributor

homu commented Jun 1, 2016

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

@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic Jun 3, 2016

Member

Looks pretty great to me @bmeurant! Thank you! I'll get someone else on core to review and we can :shipit: with their 👍

Member

mixonic commented Jun 3, 2016

Looks pretty great to me @bmeurant! Thank you! I'll get someone else on core to review and we can :shipit: with their 👍

@rwjblue

View changes

Show outdated Hide outdated packages/ember-runtime/lib/mixins/array.js
@rwjblue

This comment has been minimized.

Show comment
Hide comment
@rwjblue

rwjblue Jun 3, 2016

Member

This looks good, only one small tweak and this is good to go...

Member

rwjblue commented Jun 3, 2016

This looks good, only one small tweak and this is good to go...

@mixonic mixonic merged commit b0332ef into emberjs:master Jun 4, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@mixonic

This comment has been minimized.

Show comment
Hide comment
@mixonic

mixonic Jun 4, 2016

Member

This is great! Thank you @bmeurant!

Member

mixonic commented Jun 4, 2016

This is great! Thank you @bmeurant!

@homu homu referenced this pull request Jun 4, 2016

Merged

ESLint #13549

2 of 2 tasks complete
@rwjblue

This comment has been minimized.

Show comment
Hide comment
@rwjblue

rwjblue Aug 25, 2016

Member

FYI - I created https://github.com/rwjblue/ember-runtime-enumerable-includes-polyfill to make this a bit easier for addons to avoid deprecations, use the newer syntax, and continue to support older versions of Ember.

Member

rwjblue commented Aug 25, 2016

FYI - I created https://github.com/rwjblue/ember-runtime-enumerable-includes-polyfill to make this a bit easier for addons to avoid deprecations, use the newer syntax, and continue to support older versions of Ember.

homu added a commit to emberjs/guides that referenced this pull request Oct 18, 2016

Auto merge of #1439 - bmeurant:master, r=locks
Update documentation to move from contains to includes

Related to emberjs/ember.js#13553.

To be merged when feature has been released.

ecksun pushed a commit to Manetos/ember-searchable-select that referenced this pull request Sep 4, 2018

Linus Wallgren
Migrate to use Array.includes from .contains
This is required as .contains seems to be deprecated in ember-3.

See emberjs/ember.js#13553 for more information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment