vendredi 22 février 2019

Can Ember helpers be used as utilities?

I was going through the codebase of an old project that uses Ember-CLI 1.13 and found something strange.

There are many helpers that are not directly used inside templates but are used in component js files by importing into them. One such example is

//..helpers/my-helper.js

export function func1 (param1, param2) {
   //return something;
}

export function func2 (param1, param2) {
   //return something;
}

export function func3 (param1, param2) {
   //return something;
}

export default Ember.Helper.helper(func1);
export default Ember.Helper.helper(func2);
export default Ember.Helper.helper(func3);

And inside a component js file, I could see the above helpers being imported and used.

//../components/my-component.js
import Ember from "ember";

import { func1 } from '../helpers/my-helper';
import { func2 } from '../helpers/my-helper';
import { func3 } from '../helpers/my-helper';

I have few questions:

  1. Shouldn't we create a utility instead of a helper in this case?
  2. Is it ok to include many functions in a single helper file?
  3. Inside the helper file, is it required to use export default Ember.Helper.helper(); , if we are not intending to use the helper inside templates direcly?
  4. Are the imports inside the component file necessary?



Aucun commentaire:

Enregistrer un commentaire