Skip to content

Instantly share code, notes, and snippets.

@fterrier
Created February 10, 2014 14:22
Show Gist options
  • Save fterrier/8916751 to your computer and use it in GitHub Desktop.
Save fterrier/8916751 to your computer and use it in GitHub Desktop.
// d: initial data
// cs: success callback
// cf: failure callback
var flows = {
'get_likes': function(d, cs, cf) {
likes_api
.get_likes(d)
.then(cs, cf);
},
'read_set_read_remove_read_likes': function(d, cs, cf) {
likes_api
.get_likes_by_user(d, function(body) {
// make sure that the user has no likes
return body.likes.length === 0;
})
.then(function(d) {
likes_api.set_like_for_user_and_item(d, function(body) {
// we test that it's set
return
true
}, function(new_data) {
return new_data;
})
}, cf)
.then(function(d) {
likes_api.get_likes_by_user(d, function(body) {
logger.info("test", body);
return true;
}, function(new_data) {
return new_data;
})
}, cf)
.then(likes_api.remove_like_from_user_and_item, cf)
.then(cs, cf);
}
};
@philippkueng
Copy link

Ah ja und d muss in diesem Fall umbenannt werden. temp_d in meinem Fall, da es sonst mit dem ersten aus irgend einem Grund kollidiert, was es nicht tun sollte.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment