lundi 8 juin 2015

ember-cli call a makeBoundHelper function in javascript

I have an ember-cli helper function: translate-i18n that I am nicely using in my hbs templates as an accessory helper to dockyards i18n translation library.

The helper I created takes the word as an argument and just provides for a few fallback situations (e.x. if a translation is missing, it will fire an airbrake error).

My helper is working fantastically when used within hbs templates, but it seems like it is impossible to call it from a JS file, specifically another helper file. In a nutshell, the problem is this:

  • If I create the helper using Ember.Handlebars.makeBoundHelper(translate); the helper is not accessible using Ember.Handlebars.helpers .... so I can't call it that way. I CAN see that the helper exisits by doing this.container.lookup('helper:translate-i18n'), but I don't seem to have the ability to call the function this way.
  • If I create the helper using register (instead of makeBound), so by doing this: export default Ember.Handlebars.registerBoundHelper('translate', translate()); I can then access my helper from anywhere, but suddenly the container is not defined, and I no longer can get at the dockyards i18n (t helper), as this line throws an error: var t = this.container.lookup('utils:t');

Any suggestions/pointers/observations would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire