0

In my company, we are are evaluating several template engines in order to choose one to use with flight.

Subtemplates are perceived by some developers here as a feature, while i have the opinion that they don't fit so good with javascript frameworks, and thus with flight, since they can lead to bad practices.

I think subtemplates come from the past. If a framework is used, its views or components should be the modularization units.

In flight terms, if i have a modular part of the page, it would be better to import it as a different template and render it inside a component. Then i will have a flight selector for its attach point at least, and it will be much easier to evolve that separate template file into a full flight component.

I hope my concern is clear. What is your opinion about this? Are subtemplates a feature or they can lead to bad practices in a team?


Edit: an example of subtemplates i'm talking about are the partials, from dustjs http://akdubya.github.io/dustjs/

At the end of dustjs documentation they say dustjs has the feature of being composable, but the problem is that template composability is not enough. The modularization mechanisms provided by javascript frameworks are more powerful and should be taken into account.

danza
  • 11,511
  • 8
  • 40
  • 47

1 Answers1

0

If I understand correctly, you're suggesting that every template should have a corresponding component. This would imply that to create a list, you'd have to create a component instance for each list item.

If this is the case, then this is absolutely the wrong way to go. Subcomponents are definitely not a good idea in Flight. One component should never instantiate another.

If this is what you were thinking, let me know and I'll go in to more detail on why this is bad and what the alternatives are.

Tom Hamshere
  • 502
  • 5
  • 11
  • In the case of a list, i suggest that elements in the list have their dedicated template, imported separately in a separate string or variable, evaluated against an explicit context and attached to a flight selector. This as opposed to a subtemplate, referenced inside a bigger template, and maybe used inside a loop inside the main template logic. Using a subtemplate, no explicit objects are visible, no flight selectors are defined, and the structure is much more opaque and less compatible with an eventual conversion in a proper component, according to me. – danza Jun 24 '13 at 16:15
  • This is an old answer, but is it still true? For example, I have a `uiController` component that listens to `uiUpdated` events and reattaches all components for the current page, so that dynamically added elements become initialized when that event happens. – Rudi Jun 04 '15 at 07:00
  • This *is* an old answer. Although I still think instantiating a component for every item in a list would be unnecessary & inefficient, child components can be very useful. We now use https://github.com/flightjs/flight-with-child-components to manage creation/teardown of child components. – Tom Hamshere Jun 05 '15 at 09:28