Ember.Set replacement

I’m attempting to modify a codebase for Ember 1.8. Now there happen to be some important uses of Ember.Set in there (unaware it was a private API) which throw deprecation warnings I’d like to get rid of. I figured using the browser’s native Set with an es6-shim polyfill would work here, however this is more complicated than I anticipated since I need the Set to be observable. Worse than that, strange things happen when I use the native Set, for instance:

var O = Ember.Object.extend({
   init: function() {
       this.set('s', new Set());
       this.set('s2', new Ember.Set());
   },

   l1: Ember.computed.alias('s.size'),
   l2: Ember.computed.alias('s2.length'),

   o1: function() { console.log('Native set observer'); }.observes('s.size'),
   o2: function() { console.log('Ember.Set observer'); }.observes('s2.length'),
});

var o = O.create();
o.get('s').add('a');
o.get('s2').addObject('a');
console.log('Size of native Set: '+o.get('l1'));
console.log('Direct size of native Set: '+o.get('s').size);
console.log('Native set has a: '+o.get('s').has('a'));

console.log('Size of Ember Set: '+o.get('l2'));
console.log('Ember Set has a: '+o.get('s').has('a'));

Apart from the deprecation warning this outputs (in Chrome 38):

Ember.Set observer
Ember.Set observer
Size of native Set: 0
Direct size of native Set: 0
Native set has a: true
Size of Ember Set: 1
Ember Set has a: true

So apart from the observers not being fired on the native Set, its size property is no longer updated properly. Does anyone know something I can use to truly replace Ember.Set, or should I write something myself which wraps the native set? Changing some method / property names around is no problem of course, as long as the core mechanics work. It does seem a bit strange to deprecate such a nice feature when no real alternative is available…

You should write your own wrapper around ES6 Set (or a sham of it) and publish it as an ember addon! :slight_smile:

If I find the time I just might… first I’m gonna sit here for a while hoping someone says something that makes me not have to ;).

I’ve never used this ES6 API (or Ember.Set), but hopefully this is enough to get you on your way to Ember Latest - JSFiddle - Code Playground

I’ll try it ASAP, but from the looks of it that’s what I need! Thanks @jasonmit!