As I delve into the realm of async JavaScript coding, I have encountered a gist that has left me puzzled: https://gist.github.com/dariocravero/3922137
Specifically within client_save.file.js - there are parts of this code snippet that baffle me:
fileReader.onload = function(file) {
Meteor.call('saveFile', file.srcElement.result, name, path, encoding);
}
Firstly, the argument in the function(file) is not defined - where does "file" come from? Is there some hidden magic involving "closure" that assigns a value to the file argument?
Secondly, the Meteor.call doesn't seem to trigger. I have added console.logs in the Meteor.methods version of saveFile, but they don't show anything. Could it be because fileReader.onload = function( ... isn't actually a stub?
Lastly, what exactly is fileReader.onload? Does it signify that when the DOM loads the fileReader content, then this function should be executed? Would it make more sense to implement this in Meteor using something like Meteor.template.rendered = function() .. ?
At this point, my mind is completely tangled after staring at this code for hours on end. I just can't seem to figure out why the Meteor.call won't work as outlined in that gist.
(I am working with meteor 0.6.31).