Closed mriska closed 7 years ago
Initializers and helpers do something similar where there's a default export, and then the function is also exported, but named.
The helper is done like this:
export fooBar = () ->
export default Ember.Helper.helper fooBar
Which generates
export var fooBar = function() {};
export default Ember.Helper.helper(fooBar);
Utils are different though, because they use a default export, which are not named. Some alternatives I can think of:
export default () ->
export default function() {};
export default fooBar = () ->
var fooBar;
export default fooBar = function() {};
fooBar = () ->
export default fooBar
var fooBar;
fooBar = function() {};
export default fooBar;
If number 2 works, then I think that's the one we want, probably.
I did a small test by creating a util barCoffee.coffee
:
export default barCoffee = () ->
42
And the following test passes:
import barCoffee from 'foo/utils/bar-coffee'
import { module, test } from 'qunit'
module 'Unit | Utility | bar coffee'
test 'it works', (assert) ->
result = barCoffee()
assert.equal result, 42
I am unsure though in what way
export default barCoffee = () ->
would differ from export default () ->
, since they both only export the function as a default and not a named export that can be imported with import { barCoffee } from ...
But number 2 on your list definitely works, I just don't understand the benefit from it.
I am unsure though in what way export default barCoffee = () -> would differ from export default () ->, since they both only export the function as a default and not a named export that can be imported with import { barCoffee } from ...
But number 2 on your list definitely works, I just don't understand the benefit from it.
I don't completely understand what (if any) benefit it has either. It could be completely irrelevant in the context of an export/import, but in general if an anonymous function is assigned to a variable, then the browser will figure out the name and show it in the stack trace. It could be that I am mixing up variable assignment with objects with a function value, though.
The most pragmatic approach here is probably to leave the code as is, because I'm not sure how I would go about verifying or debunking the idea, and either way the potential value of figuring it out isn't that great.
I'll close the issue, but if you have any thoughts then please share them.
@kimroen Sounds good!
@kimroen:
https://github.com/kimroen/ember-cli-coffeescript/pull/137/files/f51b2479cfe013389a766b2a8bedd1ecf801db59#diff-0cf817951560f1b4dff974e60873ea9bR1