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

The {{hash}} helper creates objects that don't inherit from Object.prototype #1429

Closed
sandydoo opened this issue May 14, 2023 · 1 comment
Closed

Comments

@sandydoo
Copy link

sandydoo commented May 14, 2023

Description

The object created by the hash helper does not inherit from Object.prototype and is missing a lot of common functions like hasOwnProperty.

I've been a bit out of the loop, but it seems the behaviour may have changed in: 52f5257

Reproduce

The issue can be reproduced in the production docs for ember-google-maps: https://ember-google-maps.sandydoo.me/docs/directions

Throughout the docs for ember-google-maps, I suggest that people use the hash helper to quickly build up map settings without leaving the template. For example:

<directions.route
      @draggable={{true}}
      @polylineOptions={{hash
        strokeColor="green"
        strokeWeight=8
        strokeOpacity=0.7}} as |route|>

The above currently breaks Google Maps when it tries to call hasOwnProperty on the polylineOptions object.

Expected behaviour and feedback

Is this a reasonable use-case for the hash helper? Or should I ditch the idea and remove this pattern from the documentation?

One could argue that creating the object outside of the template is the safer option, given how restrictive the hash helper is around updates. There's nothing stopping a third-party library like Google Maps from calling set in the future and breaking the app.

It's also fair to argue that Google Maps should be using something like Object.prototype.hasOwnProperty.call to be safe.

Any guidance, thoughts, and suggestions are very welcome!

@sandydoo
Copy link
Author

I found out that this behavior is mentioned in the docs.

Note that the hash is an empty object with no prototype chain, therefore common methods like toString are not available in the resulting hash. If you need to use such a method, you can use the call or apply approach:

I guess the solution here is to introduce a custom hash helper.

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

No branches or pull requests

1 participant