Continuing this discussion from the RFCs repository, where things were getting a bit off topic on the named argument default values thread.
My original comment, outlining why myself and others believe that TO components could become much more valuable in the future:
I guess it’s pretty unclear to me how you would ever do something like this with TO components, because templates are just templates and the JS is everything else about a component
So, for some extra context here, one thing that is being discussed a lot is making TO components much more viable for use in the majority of component situations. Today they’re fairly limited in what they can do, but with template imports it may be possible to make them much more powerful.
import PowerSelect from 'ember-power-select';
function getCityNames(cities) {
return cities.map(c => c.name);
}
function getCountryNames(cities) {
let countries = new Set();
cities.forEach((city) => countries.add(city.country));
return Array.from(countries);
}
export default hbs`
City:
<PowerSelect
@selected={{@selectedCity}}
@options={{getCityNames @cities}}
@onChange={{@onCityChange}}
/>
Country:
<PowerSelect
@selected={{@selectedCountry}}
@options={{getCountryNames @cities}}
@onChange={{@onCountryChange}}
/>
`;
Or a frontmatter version:
---
import PowerSelect from 'ember-power-select';
function getCityNames(cities) {
return cities.map(c => c.name);
}
function getCountryNames(cities) {
let countries = new Set();
cities.forEach((city) => countries.add(city.country));
return Array.from(countries);
}
---
City:
<PowerSelect
@selected={{@selectedCity}}
@options={{getCityNames @cities}}
@onChange={{@onCityChange}}
/>
Country:
<PowerSelect
@selected={{@selectedCountry}}
@options={{getCountryNames @cities}}
@onChange={{@onCountryChange}}
/>
With this type of a setup, it would be possible to use TO components for many more use cases, especially when no root state exists on the component. Helper functions can take the place of computed properties/getters, and you could define modifiers inline as well potentially. Today, those would all have to be global, and the cost to setting them up is pretty prohibitive because of that.
This isn’t all set in stone at all, template imports could also end up being much more minimal (e.g. only allow import
syntax), but I do think it demonstrates the possibilities, and why we would like to make sure we think about them in general when designing new component APIs.