Skip to content

Instantly share code, notes, and snippets.

@chriskrycho
Last active September 11, 2018 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chriskrycho/39ec866cdf2fc3d477c186838d04df81 to your computer and use it in GitHub Desktop.
Save chriskrycho/39ec866cdf2fc3d477c186838d04df81 to your computer and use it in GitHub Desktop.
get-not-working
import Controller from '@ember/controller';
import { get, set } from '@ember/object';
import { action, computed } from '@ember-decorators/object';
export default class ApplicationController extends Controller {
init() {
super.init(...arguments);
const initial = [
{ emailAddress: 'hello@example.com' },
{ emailAddress: 'goodbye@example.com' },
];
const selected = initial
.reduce((dict, { emailAddress }) => Object.assign({}, dict, { [emailAddress]: false }), {});
this.setProperties({ initial, selected });
}
@action
toggleAll() {
const updated = Object.entries(this.selected)
.reduce((dict, [k, v]) => Object.assign({}, dict, { [k]: !v }), {});
set(this, 'selected', updated);
}
@computed('selected')
get selectedAsString() {
return Object.entries(this.selected)
.reduce((dict, [k, v]) => Object.assign({}, dict, { [k]: `${v}` }), {});
}
}
<ul>
{{#each this.initial as |item|}}
{{log this.selected}}
{{log item.emailAddress}}
{{log (get this.selected item.emailAddress)}}
{{log (get this.selectedAsString item.emailAddress)}}
<li>
{{item.emailAddress}} is
{{if (get this.selected item.emailAddress) 'selected' 'not selected'}}.<br>
    Literal value: {{get this.selectedAsString item.emailAddress}}
</li>
{{/each}}
</ul>
<button onclick={{action this.toggleAll}}>Toggle!</button>
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0",
"ember-decorators": "2.4.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment