[BUGFIX beta] Allow numeric keys for the get keyword#13311
[BUGFIX beta] Allow numeric keys for the get keyword#13311duggiefresh wants to merge 1 commit intoemberjs:masterfrom
get keyword#13311Conversation
|
Calling |
There was a problem hiding this comment.
Test should be added in https://github.com/emberjs/ember.js/blob/master/packages/ember-glimmer/tests/integration/helpers/get-test.js (using that new format). That file is symlinked to ember-htmlbars tests so that it runs under both glimmer and htmlbars rendering engines.
See #13127 for a detailed description of that test format (and the I-N-U-R test cycle we are using in the ember-glimmer test suite).
There was a problem hiding this comment.
Oh yes! Thanks 💚
0ef6256 to
a62d83c
Compare
|
Updated per review. I made an update to Glimmer util/references that will "stringify" numeric keys. Thanks! |
a62d83c to
ad368af
Compare
There was a problem hiding this comment.
Can you add a test for this? (If the browser supports it?)
There was a problem hiding this comment.
if (supportsNativeSymbols) {
moduleFor('Helpers test: {{get}} with symbols', class extends RenderingTest {
// ...
});
}There was a problem hiding this comment.
Can do! Is there an example somewhere of how to check for browser support within tests? Thanks
There was a problem hiding this comment.
I think something like what I mentioned above should work:
moduleFor('Helpers test: {{get}}', class extends RenderingTest {
// current tests
}
if (typeof Symbol === 'function') { // I think?
moduleFor('Helpers test: {{get}} with symbols', class extends RenderingTest {
// moar tests
});
}There was a problem hiding this comment.
Thanks for the help. However, it seems there isn't support for symbols in templates. Do we want to add symbol support for the {{get}} keyword?
For example, something like this doesn't work either:
['@test should be able to get an object value with numeric keys']() {
let first = Symbol('first');
let second = Symbol('second');
let third = Symbol('third');
this.render(`{{#each indexes as |index|}}[{{get items index}}]{{/each}}`, {
indexes: [first, second, third],
items: {
[first]: 'First',
[second]: 'Second',
[third]: 'Third'
}
});
°°°There was a problem hiding this comment.
No, if we don't support symbols already in template-land, then we don't need to support it explicitly here.
There was a problem hiding this comment.
Great! Thanks will update the PR as necessary
|
Sorry to bother, but just a ping to move this along. Please see: #13311 (comment) Thanks, @chancancode @rwjblue |
|
I don't understand why we don't check for number and coerce it? Can we start conservatively? Does it make sense to toString anything? This will toString |
|
Especially if this is targeted as a bugfix to beta. |
|
@duggiefresh I think there was interest in removing the And @krisselden's suggestion re: swapping to a conservative approach, only coercing numbers, seems reasonable. Would love to see this land :-) |
|
@mixonic Thanks for pinging me on this. I believe I'll be attending your Contributors Workshop at WGE. Perhaps, we can land this before the conference. :) See you then |
ad368af to
a7cb4ac
Compare
|
Updated per comments! I removed the |
|
ping @mixonic @krisselden Thank you! |
|
does this work for |
|
@Turbo87 I'm not quite sure what you're asking. Can you provide an example? |
| get(propertyKey) { | ||
| if (typeof propertyKey === 'number') { | ||
| // Allows us to get numeric keys | ||
| propertyKey = '' + propertyKey; |
There was a problem hiding this comment.
I kind of expect you would only need the logic in the keyword. What other use-cases does this cover?
There was a problem hiding this comment.
I added the coercion here too, because of the assertion here: https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/property_get.js#L49
|
@mixonic I'm talking about something like |
| if (typeof key === 'string') { | ||
| return key; | ||
| } else if (typeof key === 'number') { | ||
| return '' + key; |
There was a problem hiding this comment.
can you explain why it is needed to be check in both places?
There was a problem hiding this comment.
I added a coercion in both ember-glimmer and ember-htmlbars because of the assertion here: https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/property_get.js#L49
Perhaps there's a better place to add this logic?
|
☔ The latest upstream changes (presumably #14041) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@duggiefresh are you able to rebase and solve the conflicts? Thank you! |
|
Pease let this happen. I have to manually change keys to strings to use get with them 😊 |
|
I rebased and updated to work on master, but this PR predates github's feature that allows project maintainers to push to PR branches. I resubmitted (with correct commit attribution) in #15366. |
Fixes #13296