-
-
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 uniqBy] Adds Enumerable.uniqBy and Computed.uniqBy #12875
Conversation
@@ -363,6 +364,47 @@ export function uniq(...args) { | |||
} | |||
|
|||
/** | |||
A computed property which returns a new array with all the unique |
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 im assuming this code/docs also needs to be feature flagged?
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.
Yes, the docs should be inside the feature flags.
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.
done.
Thanks for the continued polish on this @seanjohnson08 :-) |
We should also ensure that a module is added to ember-cli-shims when Ember.computed.uniqBy is present. |
@mixonic thanks for all of the feedback/help. One last issue: When I flag off |
You have to also flag the new tests to only run when the feature is enabled. Then you can check the checkbox in the test runner environment for "enable optional features". |
Alright - so I've moved the tests to the right place, but I don't believe I'm flagging off the tests correctly. They all pass locally (with |
} | ||
}); | ||
|
||
// QUnit.test('uniqBy is readOnly', function() { |
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 be removed, I expect.
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 uncommented this out only because it was messing with my editor's formatting, I've added it back. Good catch. :)
I believe the current failures are due to caching of glimmer-engine, which should have been fixed by #12882. Can you rebase? Also, before merging we will need to squash these commits down to a single commit with a prefix of |
1094923
to
e9d6bc7
Compare
@rwjblue - rebased and squashed. |
37b8074
to
572895b
Compare
should be good to go now - thanks for all of your help/feedback. 👍 |
☔ The latest upstream changes (presumably #12575) made this pull request unmergeable. Please resolve the merge conflicts. |
@rwjblue - I've resolved conflicts, any further discussion on the fate of this PR? |
Should be good, will review one last time... |
+1. It would be a good computed feature to have. |
☔ The latest upstream changes (presumably #12991) made this pull request unmergeable. Please resolve the merge conflicts. |
9e307a5
to
7348dce
Compare
I've once again rebased on latest changes - the latest commit included @mmun's |
@seanjohnson08 WeakMap is not intended to be used as a short-lived object. This leaks memory. Please see the comment at ember.js/packages/ember-metal/lib/weak_map.js Lines 17 to 21 in 4a404de
Fortunately the fix is simple. Just use a
|
7348dce
to
8585dc4
Compare
☔ The latest upstream changes (presumably #13100) made this pull request unmergeable. Please resolve the merge conflicts. |
@seanjohnson08 this is very much still a go. Can I ask you for a fresh rebase? I'm checking through the implementation again, but we are likely good to go!! |
export function uniqBy(dependentKey, propertyKey) { | ||
return computed(`${dependentKey}.[]`, function() { | ||
var uniq = emberA(); | ||
var seen = {}; |
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.
Wasn't @mmun asking that this use EmptyObject
instead of {}
? Can we do that?
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've rebased and switched to EmptyObject
. Thanks!
1d84cf8
to
643b101
Compare
Thank you @seanjohnson08! |
ORIGINAL PR: #12758
Almost all of the enumerable methods that serve to produce some new result from a list follow the following pattern:
filter
filterBy
map
mapBy
find
findBy
reject
rejectBy
uniq
Except
uniq
! My proposal is to add auniqBy
method to both theEnumerable
class and to the computed reduce macros to allow the user to reduce a list down to its unique values given some key. A prime example is if I'm dealing with a list of records, or objects returned that have a primary key:var records = Ember.A([ {id: 1, name: 'Adam' }, {id: 2, name: 'Eve' }, {id: 1, name: 'Adam'} ]);
If I wanted to remove the duplicate records, I would then be able to use the result of
records.uniqBy('id')
to get a list of just the unique records in the list.This would not alter or modify the existing
uniq
methods, it would just serve to fill in a blank.