Skip to content

Instantly share code, notes, and snippets.

@jgwhite
Last active January 11, 2016 11:45
Show Gist options
  • Save jgwhite/efc125d794b6e8820e10 to your computer and use it in GitHub Desktop.
Save jgwhite/efc125d794b6e8820e10 to your computer and use it in GitHub Desktop.
Failure observing nested keys beyond @each
import Ember from 'ember';
const { computed } = Ember;
export default Ember.Controller.extend({
items: [{
name: 'Foo',
isActive: true
}, {
name: 'Bar',
isActive: false
}, {
name: 'Baz',
isActive: true
}],
activeItems: computed.filterBy('items', 'isActive'),
otherItems: [{
name: 'Foo',
state: {
isActive: true
}
}, {
name: 'Bar',
state: {
isActive: false
}
}, {
name: 'Baz',
state: {
isActive: true
}
}],
activeOtherItems: computed.filterBy('otherItems', 'state.isActive')
});
<h4>Enumerable with non-nested dependent key (working fine)</h4>
<p><code>items</code></p>
<ul>
{{#each items as |item|}}
<li>
{{item.name}}
{{input type="checkbox" checked=item.isActive}}
</li>
{{/each}}
</ul>
<p><code>activeItems: computed.filterBy('items', 'isActive')</code></p>
<ul>
{{#each activeItems as |item|}}
<li>{{item.name}}</li>
{{/each}}
</ul>
<hr>
<h4>Enumerable with nested dependent key (problems)</h4>
<p><code>otherItems</code></p>
<ul>
{{#each otherItems as |item|}}
<li>
{{item.name}}
{{input type="checkbox" checked=item.state.isActive}}
</li>
{{/each}}
</ul>
<p><code>activeOtherItems: computed.filterBy('otherItems', 'state.isActive')</code></p>
<ul>
{{#each activeOtherItems as |item|}}
<li>{{item.name}}</li>
{{/each}}
</ul>
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.3.0-beta.3/ember.debug.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.3.0-beta.3/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment