HeroicEric / ember-group-by

An Ember addon that adds a computed property macro for grouping objects by a given property.
MIT License
53 stars 17 forks source link

[ENHANCEMENT] Added optional comparator property to handle complex value #10

Open Fed03 opened 8 years ago

Fed03 commented 8 years ago

Ember findBy method compare by identity and that's good for primitive values, but when we deal with objects identity could not be the perfect solution.

For example, 2 different Date objects referring both to today are !==, however are equals conceptually. To handle this I've added a comparator property that works like this

import Ember from 'ember';
import groupBy from 'ember-group-by';

export default Ember.Controller.extend({
  modelByDate: groupBy('model', 'date', function(previousDate, currentDate) {
    return previousDate.getTime() === currentDate.getTime();
  })
});

Hope this gets merged, cause I think there're many use case where this could be useful. P.S. I've also updated the ember-cli version and added test

miguelcobain commented 1 year ago

@Fed03 you're probably not interested anymore, but this is a great idea. If, by any change, you're still interested, you could rebase this PR and I could merge it in.