-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
Oh awesome, thanks for getting this implementation done! |
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 Aliasing |
@bmeurant Thanks :-)
|
@mixonic thx for your feedback. I updated this PR to keep current implementation for
Does it means that I should also remove |
I believe that the deprecation should be included here when the feature flag is enabled. |
@mixonic I added feature flag and move deprecation behind it. Let me know if I forgotten something. I also removed But I was wondering: doing that, users will loose the information that |
@bmeurant Yeah the documentation may require some followup tweaks. Feature flagging things like the |
|
||
* `ember-runtime-enumerable-contains` | ||
|
||
Deprecates `Enumerable.contains` and `Array.contains` in favor of `Enumerable.includes` and `Array.includes` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again here I lean toward Enumerable#contains
, per emberjs/website#2600 (comment). It is a Rubyish approach, curious if there are other thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Enumerable#contains
is the convention in Ember even though it was originally a rubyism - at least it has the advantage that it's not valid syntax for something that is completely different
(See for example the changelog where it's used extensively)
@bmeurant heh, there are no tests for This is looking pretty good after some tweaks! |
@return {Boolean} `true` if object is found in the array. | ||
@public | ||
*/ | ||
includes(obj, startAt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function (and the enumerable one) must be added only when the feature flag is enabled. For example:
let ArrayMixin = Mixin.create(Enumerable, {
/* snip */
});
if (isEnabled('ember-runtime-enumerable-includes')) {
ArrayMixin.reopen({
includes(obj, startAt) {
/* ... */
}
});
}
export default ArrayMixin;
Thx for feedbacks, I'll work on it ASAP |
It seemed to me that Array#contains tests are also imported and run from Enumerable#contains tests. Did I miss something ? |
Ah I see @bmeurant :-) right there is no |
I wanted to add a test to verify assertion calling |
@@ -811,7 +820,9 @@ var Enumerable = Mixin.create({ | |||
@public | |||
*/ | |||
without(value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have a problem line 832 during k !== value
. If the feature is enabled, without
becomes inconsistent because NaN !== NaN
is true
return found; | ||
}, | ||
|
||
without(value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefered replacing without
behind feature flag to not add multiple isEnabled
calls in original method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@bmeurant it seems ok to add a test for |
Thanks for your continued work on this 😄 it looks really close, and quite nice! |
Looking nice. A rebase/squash to some number is semantically meaningful commits (one or more) would be great, each prefixed with |
Done 👌 |
☔ The latest upstream changes (presumably #13328) made this pull request unmergeable. Please resolve the merge conflicts. |
Looks pretty great to me @bmeurant! Thank you! I'll get someone else on core to review and we can with their 👍 |
var len = get(this, 'length'); | ||
var idx, currentObj; | ||
|
||
if (Ember.isNone(startAt)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not use the global here (Ember.isNone
), if we need isNone
it should be imported. Can we just do the null
/ undefined
check ourselves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwjblue using the global here was surely a mistake, sorry. isNone
is already imported and used in slice
. I'll update. But why do you prefer to not use imported isNone
and doing null
/ undefined
check ourselves in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, explicit null check is unnecessary as we only iterating on idx = startAt
. I removed it.
This looks good, only one small tweak and this is good to go... |
…udes and deprecate Enumerable#contains
This is great! Thank you @bmeurant! |
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. |
Update documentation to move from contains to includes Related to emberjs/ember.js#13553. To be merged when feature has been released.
This is required as .contains seems to be deprecated in ember-3. See emberjs/ember.js#13553 for more information
Implementation of emberjs/rfcs#136
TODO :
Enumerable.includes
Array.includes
contains
under feature flagcontains
byincludes