mercredi 14 octobre 2015

How to use ES2015 Template strings in an Ember helper

Ember > 2.0 + Ember suave are telling me:

"requireTemplateStringsForConcatenation: Using manual concatenation with strings is not allowed at helpers/svg-icon.js"

import Ember from 'ember';

export function svgIcon(iconName) {
  return Ember.String.htmlSafe("<svg class='icon-x'><use xlink:href='#icon-" +  iconName + "'></use></svg>");
}

export default Ember.Helper.helper(svgIcon);

I've just come from a meetup where Ember.string.fmt was discussed and sounded promising ~ but that has been deprecated and suggests you use ES2015 Template Strings.

Reading about those here: http://ift.tt/1Iu7svO

I am unclear about how 'manual' concatenation works - what the problem would be - and well, the whole thing.

return Ember.String.htmlSafe("<svg class='icon-x'><use xlink:href='#icon-${iconName}'></use></svg>"); ?

Implementation and reasoning happily accepted.




Aucun commentaire:

Enregistrer un commentaire