Open scripting opened 4 years ago
I will write up some code to demonstrate what the Babel plug-in will do, hopefully later today. Stay tuned.
Here are two examples, in one, folderloader.load is a JavaScript routine running in the current Node. It downloads a folder on S3 into a folder on the local disk, and when it's done, it calls a callback with some text for a log.
function loadFromConfigList (callback) {
var logarray = new Array ();
function loadone (ix) {
if (ix >= config.locations.length) {
callback (logarray);
}
else {
var loc = config.locations [ix], logtext;
folderloader.load (loc.s3path, loc.folder, function (logtext) {
if (logtext.length == 0) {
logtext = "No changes.";
}
logarray.push (logtext);
loadone (ix + 1);
});
}
}
loadone (0);
}
The second example, below, would be running in a new JavaScript engine, that hides the details of synchronization behind an interface.
In this version, folderloader.load doesn't return until it has completely downloaded the folder, returning the log text as the returned value of the function.
function loadFromConfigList () {
var logarray = new Array ();
config.locations.forEach (function (loc) {
var logtext = folderloader.load (loc.s3path, loc.folder);
if (logtext.length == 0) {
logtext = "No changes.";
}
logarray.push (logtext);
});
return (logarray);
}
In the second example folderloader.load would be specified with a new keyword instead of function.
var folderloader = {
sync function load (s3path, localfolder) {
//do the thing
return ("the log text");
}
}
In a blog post I wrote:
A friend suggested using Babel to get started.
This is the way to start. I wonder if anyone reading this has the expertise in Babel to make this work. I'll start a thread over in the repo to discuss.
This is that thread. :boom: