mardi 17 février 2015

Ember custom conventions

I'm build a list-view, which renders a list of records in a table. The list-view is build as a reusable mixin, and has a reusable template as well. I want the list-view to be as easy to use as possible, and not have to write too much code, to make it work - but only overwrite what I want to change.


Idealy I only want to tell the controller (or perhaps even better) the router, that it's going to render a list-view, and only render custom template, if I have one defined.


Example:



import Ember from 'ember';
import MixinList from '../../mixins/mixin-list';

export default Ember.Route.extend(MixinList, {
model: function() {
return this.store.find('category');
}
});


Currently I have to write this code, to make the list-view work:


Categories route:



import Ember from 'ember';

export default Ember.Route.extend({
model: function() {
return this.store.find('category');
}
});


Categories controller:



import Ember from 'ember';
import MixinList from '../../mixins/mixin-list';

export default Ember.Controller.extend(MixinList, {
actions: {
itemAction: function(actionName, item) {
if (actionName === 'edit') {
this.transitionToRoute('categories.edit', item.get('id'));
}
}
}
});


Categories template:



<h1>Categories</h1>
{{partial 'mixin-list'}}


Is it possible to setup conventions, so routes which are using a specific mixin, are given a default controller and template, if they arent added to the project by the user?





Aucun commentaire:

Enregistrer un commentaire