Best use case for helpers, when should we use it and when should we avoid it?


#1

Hi folks, I wanted to get your wisdom on the best use case for helpers - what is the golden rule for when we should be creating helpers vs when we should be avoiding it?

Personally I have created few helpers for: formatting date, concatenating strings and lately I have started creating some helpers that do and/or/not logic which I think are kinda helpful, and its easier to read when they are in my template context for simpler stuff(not more than 3 arguments) - but some of my colleagues disagree and think that those should be thrown in component/controller.

So here I am in a dilemma and I know this is very subjective topic but I just want to know what Ember gurus have to say about it, and quite honestly want to know if I am starting to abuse helpers.

Thanks.


#2

Dear Deewendra, I am by no means a guru but I’ll attempt to answer. I use helpers in templates until it starts to look contrived (i.e. too many nested subexpressions, especially with Ember Truth Helpers). Defining a computed property for every single line of logic in a template also seems like an abuse to me.

Lauren Tan recently gave a wonderful talk at EmberConf: https://www.youtube.com/watch?v=lP9ap-AKBAM where she talks about this (helpers starts around minute 22).