Ember.js: Deprecate Ember.Map / Ember.MapWithDefault / Ember.OrderedSet

Created on 23 May 2018  路  4Comments  路  Source: emberjs/ember.js

As agreed on in emberjs/rfcs#237, we need to deprecate creating the following objects:

The deprecations should be until: '3.5.0'.

Deprecation Help Wanted

Most helpful comment

The basic issue is with transpilation. Its difficult to subclass native Map / Set / Error / Array objects and _also_ transpile away the class syntax (you will get the error message you reported when the transpiled super() call runs from the constructor).

I actually had handle this problem in ember-data when this issue was originally being worked on, my strategy there may be helpful to you.

All 4 comments

@rwjblue I'm currently trying to implement https://github.com/emberjs/ember.js/blob/master/packages/%40ember/map/with-default.js in my app, but I encounter this error during tests in CI:

Constructor Map requires 'new' 
'TypeError: Constructor Map requires 'new'
 at MapWithDefault.Map (<anonymous>)\\n    at new MapWithDefault

My implementation is simply this one:

export default class MapWithDefault extends Map {
  constructor(options) {
    super();
    this.defaultValue = options.defaultValue;
  }

  get(key) {
    let hasValue = this.has(key);
    if (hasValue) {
      return super.get(key);
    } else {
      let defaultValue = this.defaultValue(key);
      this.set(key, defaultValue);
      return defaultValue;
    }
  }
}

Is there something wrong with the compiler ? (I'm on "ember-cli-babel": "^7.1.3")

The basic issue is with transpilation. Its difficult to subclass native Map / Set / Error / Array objects and _also_ transpile away the class syntax (you will get the error message you reported when the transpiled super() call runs from the constructor).

I actually had handle this problem in ember-data when this issue was originally being worked on, my strategy there may be helpful to you.

Thanks a lot Robert for those explanations. So my missing piece was to implement the Map proxy. Do you know if the transpilation will resolve this is the future ?

I kinda doubt it for IE11, and all of the evergreen browsers can already handle it...

Was this page helpful?
0 / 5 - 0 ratings