As agreed on in emberjs/rfcs#237, we need to deprecate creating the following objects:
@ember/map - Deprecation message should suggest to replace usage with native Map usage.@ember/map/with-default - Deprecation should suggest to replace usage with native Map usage.@ember/ordered-set - Deprecation should mention adding @ember/ordered-set addon.The deprecations should be until: '3.5.0'.
@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...
Most helpful comment
The basic issue is with transpilation. Its difficult to subclass native Map / Set / Error / Array objects and _also_ transpile away the
classsyntax (you will get the error message you reported when the transpiledsuper()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.