Skip to content

Commit

Permalink
[BUGFIX beta] Allow numeric keys for the get helper.
Browse files Browse the repository at this point in the history
Fixes #13296
  • Loading branch information
duggiefresh authored and rwjblue committed Jun 16, 2017
1 parent 6a6f279 commit 49787ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/helpers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class GetHelperReference extends CachedReference {
if (pathType === 'string') {
innerReference = this.innerReference = referenceFromParts(this.sourceReference, path.split('.'));
} else if (pathType === 'number') {
innerReference = this.innerReference = this.sourceReference.get(path);
innerReference = this.innerReference = this.sourceReference.get('' + path);
}

innerTag.update(innerReference.tag);
Expand Down
25 changes: 25 additions & 0 deletions packages/ember-glimmer/tests/integration/helpers/get-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ moduleFor('Helpers test: {{get}}', class extends RenderingTest {
this.assertText('[red and yellow] [red and yellow]');
}

['@test should be able to get an object value with numeric keys']() {
this.render(`{{#each indexes as |index|}}[{{get items index}}]{{/each}}`, {
indexes: [1, 2, 3],
items: {
1: 'First',
2: 'Second',
3: 'Third'
}
});

this.assertText('[First][Second][Third]');

this.runTask(() => this.rerender());

this.assertText('[First][Second][Third]');

this.runTask(() => set(this.context, 'items.1', 'Qux'));

this.assertText('[Qux][Second][Third]');

this.runTask(() => set(this.context, 'items', { 1: 'First', 2: 'Second', 3: 'Third' }));

this.assertText('[First][Second][Third]');
}

['@test should be able to get an object value with a bound/dynamic key']() {
this.render(`[{{get colors key}}] [{{if true (get colors key)}}]`, {
colors: { apple: 'red', banana: 'yellow' },
Expand Down

0 comments on commit 49787ed

Please sign in to comment.