3
votes

By default a helper generated by ember-cli looks like this:

import Ember from 'ember';

export function boundLoc(input) {
  return input;
}

export default Ember.Handlebars.makeBoundHelper(boundLoc);

I have two questions to better my understanding of this code.

1) Why is there two exports? Does the first export allow the helper to be imported and used by other JavaScript files, whereas the second export is what actually registers it as a Handlebars helper?

2) Secondly, if the code looked like:

import Ember from 'ember';

export default Ember.Handlebars.makeBoundHelper(function boundLoc(input) {
  return input;
});

would this export it as a Handlebars template helper but not make the boundLoc() method accessible to other JavaScript files that imported this helper?

1

1 Answers

2
votes

1) Yes, there are two exports so that the helper can be used as a function from within other JavaScript after it is imported and as a handlebars helper.

In other JavaScript:

import {
  boundLoc
} from 'app/helpers/boundLoc';

boundloc(input);

and in a template:

{{boundloc input}}

2) Yes, the behavior you described is accurate. That would only export a boundHelper and not the function for consumption elsewhere. You can always try a POC.

Note, however, that you may have trouble with generated tests if you try to only export the boundHelper. See this answer for more details.