Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Ember.Map / Ember.MapWithDefault / Ember.OrderedSet #16678

Closed
rwjblue opened this issue May 23, 2018 · 4 comments
Closed

Deprecate Ember.Map / Ember.MapWithDefault / Ember.OrderedSet #16678

rwjblue opened this issue May 23, 2018 · 4 comments

Comments

@rwjblue
Copy link
Member

rwjblue commented May 23, 2018

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

The deprecations should be until: '3.5.0'.

@sly7-7
Copy link
Contributor

sly7-7 commented Dec 18, 2018

@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")

@rwjblue
Copy link
Member Author

rwjblue commented Dec 18, 2018

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.

@sly7-7
Copy link
Contributor

sly7-7 commented Dec 19, 2018

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 ?

@rwjblue
Copy link
Member Author

rwjblue commented Dec 19, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants