Skip to content

Instantly share code, notes, and snippets.

@nomadster
Last active August 29, 2015 13:56
Show Gist options
  • Save nomadster/9005050 to your computer and use it in GitHub Desktop.
Save nomadster/9005050 to your computer and use it in GitHub Desktop.
var qhttp = require('q-io/http'),
_ = require('lodash'),
cacheServer = 'http://localhost:7000/',
dbServer = 'http://localhost:7001/';
//E' circa function(arg) { return String.concat(dbServer, arg) }
buildDbPath = _.bind(String.prototype.concat, dbServer);
qhttp.read(cacheServer)
//Chiama qhttp.read(String.concat(dbServer, il Return Di Quella Sopra))
.then(_.compose(qhttp.read, buildDbPath))
//Chiama console.log(JSON.parse(il return di quella sopra))
.then(_.compose(console.log, JSON.parse))
//Stampa a video con console.error se errore
.then(null, console.error)
//Ultimo handler in caso di unhandled exceptions :)
.done();
//Bind di lodash è fatta così
function bind(func, thisArg) {
return arguments.length > 2
? createWrapper(func, 17, slice(arguments, 2), null, thisArg)
: createWrapper(func, 1, null, null, thisArg);
}
//compose di lodash e fatta così e fa la composizione di funzioni
function compose() {
var funcs = arguments,
length = funcs.length;
while (length--) {
if (!isFunction(funcs[length])) {
throw new TypeError;
}
}
return function() {
var args = arguments,
length = funcs.length;
while (length--) {
args = [funcs[length].apply(this, args)];
}
return args[0];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment