rtd
rtd copied to clipboard
Wrap files in Immediately-invoked function expression
Meteor wraps all files in Immediately-invoked function expression (function() { /* your code */ }()); This makes sure nothing is accidentally made available on a global scope and gives each file private functions.
RTD should also do the same thing, because otherwise functions with the same name that exist in more than one file can be run for a different context than you would expect. For unit tests and code coverage.
Eg: Create a function called function test() { console.log('hello') } and on that say 'goodbye' in 2 different view files. Now when you call function test() in view 1, and it might call the same function name in view 2.
I recommend RTD wraps all files in an immediately invoked function expression before executing them like Meteor.
In which files did you find a missing function wrap ?
Every single file inside my application ie. the app/* directory.
@deepwell , then it's yours, not rtd related ;) http://en.wikipedia.org/wiki/Immediately-invoked_function_expression; well known Javascript pattern.
That's exactly what I thought at first too, so I modified every single one of my app files to be wrapped in immediately-invoked function expressions. But the more I thought about it, the more I realized that now on production with Meteor, all of my code is being wrapped twice. Once by me, and once by Meteor. Seems kind of silly. And only required to make my code work with RTD.
Because RTD mocks and stubs Meteor, I now feel that RTD should also wrap all files in an immediately invoked function exp. just like Meteor itself.
Thoughts?
Oh ! Well done ! you're right, i didn't noticed that some of my mirror_app files have dual function wrapping, excellent ! Waiting for Sam comment ...
Hello. We actually do wrap all functions manually, as you can see here: https://github.com/xolvio/meteor-rtd-example-project/blob/master. This keeps the jshint happy in our IDE :)
I think it would be a nice option to have RTD do it so I'll look into it and report back here.