Skip to content

Instantly share code, notes, and snippets.

@sholtomaud
Forked from KoryNunn/kgoToRighto.js
Last active December 20, 2018 03:38
Show Gist options
  • Save sholtomaud/6492bf0a93a2228c2e0fdadbf0058400 to your computer and use it in GitHub Desktop.
Save sholtomaud/6492bf0a93a2228c2e0fdadbf0058400 to your computer and use it in GitHub Desktop.
function update(account, id, schemaData, callback){
schemaData.companyId = account.companyId;
kgo
({
account: account,
id: id,
data: schemaData
})
('updated', ['data'], function(data, done){
db.Schema.update({ _id: id, companyId: account.companyId }, { $set: data, $inc: { version: 1 } }, done);
})
('schema', ['!updated', 'account', 'id'], get)
(['schema'], callback.bind(null, null))
.on('error', function(error){
callback(error);
});
}
var things = righto(function(done){
//Something async
setTimeout(function(){
done(null, 1);
}, 100);
})
var stuff = righto(function(done){
//Something async
setTimeout(function(){
done(null, 2);
}, 100);
})
var whatsits = righto(function(things, stuff, done){
//Something async
setTimeout(function(){
done(null, things + stuff);
}, 100);
}, things, stuff)
var dooby = righto(function(things, done){
//Something async
setTimeout(function(){
done(null, things/2);
}, 100);
}, things)
var result = righto.mate(whatsits, dooby)
result(function(error, whatsits, dooby){
//Done
console.log(whatsits, dooby);
});
var options = righto({
account: account,
id: id,
data: schemaData
})
var updated = righto(function(data, done){
db.Schema.update({ _id: id, companyId: account.companyId }, { $set: data, $inc: { version: 1 } }, done);
})
var schema = righto(['!updated', 'account', 'id'], get)
var result = righto.mate(options, updated, schema)
result(function(error, updated, schema){
if (error) callback(error);
callback.bind(null, null)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment