# Ember.Set replacement

**URL:** <https://discuss.emberjs.com/t/ember-set-replacement/6618>\
**Category:** Uncategorized\
**Created:** [November 3, 2014, 10:05pm UTC](https://discuss.emberjs.com/t/ember-set-replacement/6618 "2014-11-03T22:05:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElteHupkes](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/eltehupkes/32/14894_2.png) [@ElteHupkes](https://discuss.emberjs.com/u/ElteHupkes)\
**Post date:** [November 3, 2014, 10:05pm UTC](https://discuss.emberjs.com/t/ember-set-replacement/6618/1 "2014-11-03T22:05:04Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![mmun](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mmun/32/14872_2.png) [@mmun](https://discuss.emberjs.com/u/mmun)\
**Post date:** [November 3, 2014, 10:24pm UTC](https://discuss.emberjs.com/t/ember-set-replacement/6618/2 "2014-11-03T22:24:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ElteHupkes](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/eltehupkes/32/14894_2.png) [@ElteHupkes](https://discuss.emberjs.com/u/ElteHupkes)\
**Post date:** [November 4, 2014, 9:57am UTC](https://discuss.emberjs.com/t/ember-set-replacement/6618/3 "2014-11-04T09:57:04Z")

</div>

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 ;).

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [November 4, 2014, 3:29pm UTC](https://discuss.emberjs.com/t/ember-set-replacement/6618/4 "2014-11-04T15:29:38Z")

</div>

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](http://jsfiddle.net/NQKvy/1472/)

---

<div class="post-metadata">

**Author:** ![ElteHupkes](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/eltehupkes/32/14894_2.png) [@ElteHupkes](https://discuss.emberjs.com/u/ElteHupkes)\
**Post date:** [November 4, 2014, 9:41pm UTC](https://discuss.emberjs.com/t/ember-set-replacement/6618/5 "2014-11-04T21:41:26Z")

</div>

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