mardi 24 mars 2015

Component Hierarchies and Template file grouping

I'm refactoring my code into components, I"m finding that component hierarchies are working well. The only issue I'm running into is with the template naming requirements. I'd like to be able to have multiple templates in a components directory, that I can lookup dynamically. An example below of whats working and whats not:


side-bar/ |__component.js |__template.hbs |__sidebar-links/ |_component.js |_template.hbs |_sidebar-drawer/ |_component.js |_template-one.hbs |_template-two.hbs |_...


So -- as a simplification, my sidebar-drawer component can make use of many templates (as partials, or sometimes childViews with the layout property dynamically set), swapping them out based on links. I'd ideally like to group them together. Instead, to do something like this i"m forced to keep them in the /app/templates directory, or treat them like components.


I think I can get this working by modifying the templates compiler (found [here]):

javascript app._podTemplatePatterns = function() { return this.registry.extensionsForType('template').map(function(extension) { return new RegExp(extension + '$'); }); };


This compiles all templates having hbs extensions, regardless of location. But I'm then unable to look them up -- presumably i'd need to sub-class the Resolver as well. I'm fine to start going down that path, but a few questions:



  1. Should I be hesitant about using the (seemingly) private method _podTemplatePatterns above?

  2. Is it a bad idea to modify the resolver to accommodate this (e.g. performance impact?)

  3. Any other reason this might be discouraged in ember-land?





Aucun commentaire:

Enregistrer un commentaire