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] Allow numeric keys for the get helper. #15366

Merged
merged 1 commit into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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