Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Support node-style callbacks #125
Hey! I started playing with Bacon after attending your workshop at mloc.js. I really like it so far. Here's one addition I'd find useful: support for Node.js-style callbacks. This makes bacon.js much easier to use on the server side.
I realize that this is a bit like the jQuery adapter so maybe it should be in a separate package, but the readme explicitly mentions that bacon.js works fine on the server; this looks like a basic requirement for node.js usage.
Hope you like the idea; please give feedback on the implementation if you'd prefer some other solution :)
Keep up the great work!
tl;dr Using the Redis client library
Of course. Here's one where I use it: https://github.com/abesto/shopping-list/blob/master/routes/tab.js
This is basically an end-point of a REST API. Walking through the
Edit: oh, you mean in the readme?
@00Davo I'd prefer to call it
To me, the
Bottom line: I still prefer
I guess "node-style callbacks" are well-known enough to warrant for the name
The example code is pretty cool and I also like the fact that you only need to deal with errors in a single spot. And yes, I'm a kind-of-a Haskellist too, having written reactive-bacon before starting to work on bacon.js.
I hope you don't mind if I do some code review for you. The code looks very good, but some simplifications could probably be made. Looking at the
Now because key is really just a constant value, you could still simplyfy to
Also, on the last line, you have
While you could have instead just
Oh, and you can use plain
The bottom line is, I'm pretty convinced we should include
Wow, thanks for the suggestions :) You're right on all counts. I guess bacon.js is such a shiny hammer, even constants look like nails.
I've added two simple examples (with and without error), using the example for
Yeah, it's quite a hammer :) I recently bought a Fein Multimaster and been trying to fit it to all kinds of jobs I've done just fine without the new tool.
Actually I was thinking of more realistic examples, involving some real Node.js APIs. That would also serve to demonstrate the partial application capabilities.
That's it! Merging.
A blog post on server-side Bacon would be nice too. It would be nice to demonstrate how you can avoid the infamous callback hell, while taking care of error handling in a reliable and simple way. The problem is that I haven't done any serious node dev for some time and feel a bit lacking in credibility there, like "if I did node dev, this is how I'd do it".. Well, I should probably do my next server in node+bacon.
added a commit
this pull request
Mar 24, 2013
I'm trying to use BaconJS for the first time for the following use case:
So the above would be: