How can I get the unique records of two computed properties?


How can I compare computed properties that hold collections against one another and return only the unique records?


users: Ember.computed.alias('workspace.users'),
sharedUsers: Ember.computed.alias('workspace.sharedUsers'),

I’ve tried Ember.computed.uniq, which appears to essential merge the two properties and remove duplicates.


If I correctly understand your question a combination of intersect and setDiff should do the job like in this example:

var obj = Ember.Object.createWithMixins({
   adaFriends: ['Charles Babbage', 'John Hobhouse', 'William King', 'Mary Somerville'],
   charlesFriends: ['William King', 'Mary Somerville', 'Ada Lovelace', 'George Peacock'],
   friendsInCommon: Ember.computed.intersect('adaFriends', 'charlesFriends'),
   allFriends: Ember.computed.union('adaFriends', 'charlesFriends'),
   exclusiveFriends: Ember.computed.setDiff('allFriends', 'friendsInCommon')

console.log('Common friends:', obj.get('friendsInCommon'));
console.log('Exclusive friends:', obj.get('exclusiveFriends'));