fknoll
September 23, 2016, 7:11am
1
What am I doing wrong here?
I define a util function isXDefactoEqualY .
I use this util function to define a template helper isXEqualY .
When using this template helper in a specific template, then this template is NOT rendered.
I see no compilation errors.
I see no errors in console.
app/utils/is-x-defacto-equal-y.js
import Ember from 'ember';
export default function ([model, list]) {
... code
return true;
}
app/helpers/is-x-equal-y.js
import Ember from 'ember';
import isXDefactoEqualY from '../utils/is-x-defacto-equal-y';
export function isXEqualY([model, list]) {
return isXDefactoEqualY (model, list);
}
export default Ember.Helper.helper(isXEqualY);
app/templates/x.hbs
<div>isXEqualY: {{isXEqualY myModel myList}}</div>
Helper names are dasherized in your template. Should be {{is-x-equal-y}}
fknoll
September 24, 2016, 9:24am
3
Dasherizing (kebab-case) does not make a difference - I tried both
I have other not-based-on-a-util-function template helpers up running. For those helpers both {{kebab-case …} and {{camelCase …}} works fine.
maffews
September 26, 2016, 10:00am
4
isXDefactoEqualY
is called with individual arguments instead of an array, resulting in:
Uncaught TypeError: Invalid attempt to destructure non-iterable instanceon line 3 of
app/utils/is-x-defacto-equal-y.js`
I would change that function definition to:
export default function (model, list) { ... }
I also think the camelCase helper call is an issue, but maybe that’s environment-specific. Take a look at this twiddle to see what I’m talking about.
1 Like
fknoll
September 26, 2016, 2:10pm
5
@maffews , you are so spot-on!
Ember passes an array of arguments to a helper function!
The problem is, that I forgot to remove the array notation from the parameter list, when I copied from the original helper code.
My code now works perfect! Thank you @maffews ! Case closed
fknoll
September 26, 2016, 2:18pm
6
@maffews , I saw your twiddle. Yes, to avoid problems with different environments, it is probably best always to use kebab-case notation. Thank you!