What’s the best way to break down big functions in meteor? I have a fairly large onCreated function that I’d like to break down and test.
Roughly I have
Template.my_template.onCreated(function(){
Tracker.autorun(function() {
Meteor.call(‘getData’, function(error, result)
{
// do lots of seperate little calculations with the data
littlefunction(result);
anotherlittlefunction(result)
…
}
}
I’d like to test the seperate little calculations seperately. So what’s a good way to decopose and expose the little bits of functionality.
- I’ve thought about helper functions, but that seems like overkill and its a pain to call helpers from inside templates.
- I’ve thought about const functions at the top of the file, but then they aren’t well exposed for testing.
- I’ve thought about hanging functions off the instance but that probably doesn’t work well with testing.
- I’ve thought about a global function store similar to Template where I could do some MyFunctions.my_template.littlefunction = function() {} but don’t particularly want to do globals
I’m thinking the best way may be to off Template, so Template.my_template.littlefunciton - function(){}
That’s not completely awful and can probably work with testing, iI may be worried about name conflicts but can probably control for that.
Hoping someone has a better pattern.
Thanks