ember.js - How to define a large number of resources that use the same logic without creating boilerplate modules in ember-cli? -
i have large number of resources use same logic. each resource has <resource>
route , <resource>.show
route. i've defined baseroute
, baseshowroute
, basecontroller
, baseshowcontroller
, corresponding templates capture common logic. set appropriate controller/templates on route objects:
// routes/base.js import ember 'ember'; export default ember.route.extend({ controllername: 'base', templatename: 'base' }); // routes/base/show.js import ember 'ember'; export default ember.route.extend({ controllername: 'baseshow', templatename: 'baseshow' });
but in order use these route prototypes resources, have have 2 modules each resource:
// routes/<resource>.js import baseroute './base'; export default baseroute.extend({ }); // routes/<resource>/show.js import baseshowroute './base/show' export default baseshowroute.extend({ });
this seems silly. specify of these resources should use baseroute
, baseshowroute
without needing create these modules. reasonable have option in router.map
. this:
router.map(function(){ this.resource('articles', { extends: baseroute }, function() { this.route('show', { path: ':article_id', extends: baseshowroute }) }); });
but knowledge there nothing extends
option i'm using above.
the documentation can find route
, resource
methods invoked in router.map
in routing guide. option can pass these methods seems path
. ember-cli user guide can override base class generated routes if define routes/basic.js, not enough me-- need multiple base classes.
how can rid of boilerplate route modules?
in our application have same usecase you. far know there isn't such api in router
. boilerplate needed routes, controller module not needed , define same way do:
// routes/base/show.js import ember 'ember'; export default ember.route.extend({ controllername: 'baseshow', });
the problem ember picks same instance of controller every resources. ok of our resources, need own state (for example: form has more 1 tab , want remember last active tab each resource) , define controller , override controllername
:
// routes/user/show.js import baseshowroute './base/show' export default baseshowroute.extend({ controllername: 'user/show', });
it great if route
had property controllerclass
telling ember: create instance of controller
route
.
Comments
Post a Comment