Skip to content

Instantly share code, notes, and snippets.

@blimmer
Last active October 29, 2016 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save blimmer/cadc5b6a3628439261c780571258c9ab to your computer and use it in GitHub Desktop.
Save blimmer/cadc5b6a3628439261c780571258c9ab to your computer and use it in GitHub Desktop.
Group-By Feature Reques
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr('string'),
category: attr('string'),
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.push({
data: [
{
id: '1',
type: 'artist',
attributes: {
name: 'Dead Prez',
category: 'Hip Hop'
}
},
{
id: '2',
type: 'artist',
attributes: {
name: 'Philip Glass',
category: 'Classical'
}
},
{
id: '3',
type: 'artist',
attributes: {
name: 'Claude DeBussy',
category: 'Classical'
}
},
// Uncommenting this breaks group-by
//{
// id: '4',
// type: 'artist',
// attributes: {
// name: 'The Flaming Lips'
// }
//}
]
});
}
});
<h1>Ember Composable Helpers Group-By Bug / Feature Request</h1>
<a href='https://github.com/DockYard/ember-composable-helpers/issues/223' target='_blank'>https://github.com/DockYard/ember-composable-helpers/issues/223</a>
{{outlet}}
<h1>Example</h1>
{{#each-in (group-by "category" model) as |category artists|}}
<h1>{{category}} Artists</h1>
<ul>
{{#each artists as |artist|}}
<li>{{artist.name}}</li>
{{/each}}
</ul>
{{/each-in}}
<hr>
<h1>Suggestion for group-by helper</h1>
<p>
Ideally, we'd be able to have a group for unknown artist types. In the index route, if you uncomment the last artist in the model (The Flaming Lips), you'd get this exception:
<pre>
Uncaught Error: Assertion Failed:
The key provided to get must be a string, you passed undefined
</pre>
thrown <a href='https://github.com/DockYard/ember-composable-helpers/blob/f7a913dfc7a7545083b56419c4b98709fb00f5a7/addon/helpers/group-by.js#L21' target='_blank'>Here</a>
</p>
<p>
It'd be nice if we could say something like:
<pre>
(group-by "category" model 'Unknown Category')
</pre>
to handle this and not throw an exception.
</p>
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.0",
"ember-template-compiler": "2.6.0"
},
"addons": {
"ember-composable-helpers": "1.1.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment