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

[BUGFIX beta] Use native Map if present. #5255

Merged
merged 1 commit into from
Mar 5, 2018

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Nov 9, 2017

When native Map is present, use it. Otherwise fallback to Ember.Map.

This positions ember-data for the eventual deprecation and dropping of Ember.Map and Ember.MapWithDefault in Ember itself (and using native classes should generally be better for us long term than shipping custom slightly different versions).

Note there are a few specific differences between native Map (and the MapWithDefault implementation that extends from the native Map when possible) and Ember's Ember.Map that we should be aware of:

  • Ember.Map has custom copy and isEmpty methods which are not present in native Map
  • Ember.Map adds a static create method (which simply instantiates itself with new Ember.Map())
  • Ember.Map does not accept constructor arguments
  • Ember.Map does not have:
    • @@species
    • @@iterator
    • entries
    • values

Addresses Ember.Map and Ember.MapWithDefault usages from #5254.

Copy link
Member

@hjdivad hjdivad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

My only concern is that we're dropping functions from the return type of public API.

Getting people off the "polyfill+" is definitely good, but maybe we can provide (at least in dev mode) a more useful error message than "undefined is not a function".

```
*/

export default class MapWithDefault {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add copy and isEmpty to warn/error with a useful message for people who may be relying on this?

It seems unlikely, but on the other hand, MapWithDefault is returned by some public API

Copy link
Member

@bmac bmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rwjblue
Copy link
Member Author

rwjblue commented Dec 6, 2017

I'm going to try and pick this back up today/tomorrow to cleanup and address the points @hjdivad mentioned above...

When native `Map` is present, use it. Otherwise fallback to `Ember.Map`.

This positions ember-data for the eventual deprecation and dropping
of `Ember.Map` and `Ember.MapWithDefault` in Ember itself (and using
native classes should generally be better for us long term than shipping
custom _slightly_ different versions).

Note there are a few specific differences between native `Map` (and the
`MapWithDefault` implementation that extends from the native `Map` when
possible) and Ember's `Ember.Map` that we should be aware of:

* `Ember.Map` has custom `copy` and `isEmpty` methods which are not
present in native `Map`
* `Ember.Map` adds a static `create` method (which simply instantiates
itself with `new Ember.Map()`)
* `Ember.Map` does not accept constructor arguments
* `Ember.Map` does not have:
  * `@@species`
  * `@@iterator`
  * `entries`
  * `values`
@rwjblue rwjblue changed the title Use native Map if present. [BUGFIX beta] Use native Map if present. Mar 5, 2018
@rwjblue
Copy link
Member Author

rwjblue commented Mar 5, 2018

OK, updated this to make it (AFAICT) completely backwards compatible. Also, documented inline to make it clear why the somewhat weirdo approach is required.

@hjdivad / @bmac / anyone else - this is ready for another review...

Copy link
Member

@hjdivad hjdivad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bmac bmac merged commit f60d1e9 into emberjs:master Mar 5, 2018
@bmac
Copy link
Member

bmac commented Mar 5, 2018

Thanks @rwjblue.

@rwjblue rwjblue deleted the use-native-map branch March 5, 2018 18:45
bmac pushed a commit that referenced this pull request Mar 15, 2018
When native `Map` is present, use it. Otherwise fallback to `Ember.Map`.

This positions ember-data for the eventual deprecation and dropping
of `Ember.Map` and `Ember.MapWithDefault` in Ember itself (and using
native classes should generally be better for us long term than shipping
custom _slightly_ different versions).

Note there are a few specific differences between native `Map` (and the
`MapWithDefault` implementation that extends from the native `Map` when
possible) and Ember's `Ember.Map` that we should be aware of:

* `Ember.Map` has custom `copy` and `isEmpty` methods which are not
present in native `Map`
* `Ember.Map` adds a static `create` method (which simply instantiates
itself with `new Ember.Map()`)
* `Ember.Map` does not accept constructor arguments
* `Ember.Map` does not have:
  * `@@species`
  * `@@iterator`
  * `entries`
  * `values`

(cherry picked from commit f60d1e9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants