A Replacement for Ember’s Deprecated Ember.Set

Article summary

Having a Set datatype can be really handy in many situations. From Ember.js 0.9 all the way up to 1.8, Ember.js supplied a Set type with an interface loosely based on an early ES6 proposal. Unfortunately, since the ES6 API had drifted and the maintainers of Ember deemed it more suitable for an external library or add-on package, the class has been deprecated.

In several places throughout the application I’m currently working on, we’re using a Set to store data. Some mentions of people creating a replacement for the built-in Ember library came up when I went looking for a replacement, but I could not find any that had actually made it out to Github. As such, I made my own Ember.Set replacement.


To install the ember set replacement, you’ll need two things: an ember-cli project, and an implementation of the ES6 Set api.

To get the add-on into your ember-cli project is easy.

npm install --save-dev ember-cli-set-replacement

If you’re using a recent (0.1.7 or greater) version of ember-cli, the 6to5 add-on, which is included already, has a Set polyfill that will get you up and running on any browsers that don’t support the ES6 set natively. Unfortunately, at the moment it’s a trifle difficult to include. This situation will likely improve in the very near future, but until then, I manually copied the polyfill into my application’s vendor/ folder, and then added it into my Brocfile.js:

app.import ('vendor/browser-polyfill.js', {type: 'vendor', prepend: true});


I made an effort to keep the replacement set’s API relatively close to the now-deprecated Ember.Set. The only methods that I didn’t implement are firstObject and lastObject, which I concluded really don’t make much sense in an unordered collection.

To create a new replacement Set, all you need to do is import the library, and you’re on your way.

import EmberSet from 'ember-cli-set-replacement';

var newSet = new EmberSet();