Ember state - registerHelper else always does twice

I am trying to create a handlebars block helper for use in an Ember project. This works partially by giving the expected if / else results. However, the content of the else block in the template is rendered twice in addition to the desired result in all situations.

Here is the assistant

Ember.Handlebars.registerHelper 'ifIn', (a, b, options) ->
  Ember.Handlebars.bind.call options.contexts[0], a, options, true, (item) =>
    Ember.Handlebars.bind.call options.contexts[0], b, options, true, (list) =>
      if item in list
        options.fn()
      else
        options.inverse()  

      

And here is a JS Bin that demonstrates the problem. ---> JS Bin

+3


source to share


1 answer


After playing around with jsbin for a bit, I came to the conclusion that the way you are trying to deal with this helper looks strange.

  • Calling options.context objects multiple times is not really needed. You just need to get the comparator property in the class (options.context[0].get('notFoundColor'))

    and compare it to the items in the list (options.context[0].get('colors'))

    .

  • Why not use a string in a helper to make your life easier? eg; the helper would simply compare A to B.list instead of diving into the computed property. But if that's a requirement, just use this parameter in the first pool.

  • The parameters a, b given to your helper are just strings. You will need to write logic in the helper on how to deal with them.



I would advise not to have too many helper in this case. pass a string for the property you want to evaluate and get () the property you want to use as a comparator and use a helper to execute the logic you want to execute.

0


source







All Articles