-
-
Save sholtomaud/6492bf0a93a2228c2e0fdadbf0058400 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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