Add string.concat?
billdami opened this issue · 3 comments
billdami commented
Wondering if it would make sense/be useful to add a string.concat()
macro, that would allow for the following:
someStr: 'blah',
anotherStr: 'blarg',
yetAnotherStr: 'argh',
foo: string.concat('someStr', 'anotherStr', 'yetAnotherStr', raw('-')) // => "blah-blarg-argh"
I have a custom macro using lazyComputed()
from ember-macro-helpers that is close to this:
import lazyComputed from 'ember-macro-helpers/lazy-computed';
import { isNone } from '@ember/utils';
export default function(...values) {
const separator = values.pop();
return lazyComputed(...values, (get, ...props) => {
return props.map(prop => get(prop)).filter(val => !isNone(val)).join(separator);
});
}
But would be nice to see this as part of ember-awesome-macro's otherwise comprehensive suite of macros. :)
mriska commented
You are probably already aware of this, but pointing it out just in case. It is already possible to do exactly what you want without the need for a custom macro by leveraging composition.
someStr: 'blah',
anotherStr: 'blarg',
yetAnotherStr: 'argh',
foo: join(collect('someStr', 'anotherStr', 'yetAnotherStr'), raw('-')) // => "blah-blarg-argh"
kellyselden commented
@mriska's comment is what you want, or tag
someStr: 'blah',
anotherStr: 'blarg',
yetAnotherStr: 'argh',
foo: tag`${'someStr'}-${'anotherStr'}-${'yetAnotherStr'}` // => "blah-blarg-argh"
billdami commented
ah perfect, thank you!