Skip to content

Instantly share code, notes, and snippets.

@rwjblue
Forked from jlami/controllers.application.js
Created November 14, 2017 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwjblue/c212fc6f3364e67cb178b51bb7fa1537 to your computer and use it in GitHub Desktop.
Save rwjblue/c212fc6f3364e67cb178b51bb7fa1537 to your computer and use it in GitHub Desktop.
ember-bug-multi-brace-plus-arrayproxy
import Ember from 'ember';
export default Ember.Controller.extend({
items: [
{ id: 1, test: true, cat: 1},
{ id: 2, test: true, cat: 2},
{ id: 3, test: true, cat: 3},
{ id: 4, test: true, cat: 4},
{ id: 5, test: false, cat: 1},
{ id: 6, test: false, cat: 2},
{ id: 7, test: false, cat: 3},
{ id: 8, test: false, cat: 4},
],
testFilter: false,
filtered: Ember.computed('testFilter', 'items.@each.test', function() {
let result = this.get('items');
if (this.get('testFilter')) {
result = result.filterBy('test');
}
return result;
}),
multiEach: Ember.computed('filtered.@each.{cat,id}', function() {
return this.get('filtered').filter((item) => (item.id + item.cat) % 2 == 0);
}),
correct: Ember.computed.alias('multiEach'),
bugged: Ember.computed(function() {
return Ember.ArrayProxy.extend({parent: this, content: Ember.computed.alias('parent.multiEach')}).create();
}),
});
<h1>Multi brace expansion bug</h1>
Every change of the Filter checkbox should result in a change in the resulting list length
<br/><br/>
<label>{{input type="checkbox" checked=testFilter}} Filter</label><br>
<label>{{input type="checkbox" checked=showCorrect}} Show correct</label><br>
<br/>
{{#if showCorrect}}
Correct: {{correct.length}}<br/>
{{/if}}
Bugged: {{bugged.length}}<br/>
<br>
<br>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "canary",
"ember-template-compiler": "canary",
"ember-testing": "canary"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment