andyet / thoonk.js

Persistent (and fast!) push feeds, queues, and jobs leveraging Redis
http://thoonk.com
Other
330 stars 27 forks source link

When supplying callbacks to the subscribe method, maybe take an object instead of positional arguments? #3

Open HenrikJoreteg opened 13 years ago

HenrikJoreteg commented 13 years ago

Remember the order of arguments is annoying when using a library. Obviously JS doesn't have named args, so a lot of times people will pass an object with named properties.

thoonk.subscribe(function(id, item) {
    //publish event
},
function(id, item) {
    //edit event
},
function(id) {
    //retract event
},
function(id, position) {
    //position event for sorted feed
    //position is begin:, :end, :X, X: where X is the relative id
},
function() {
    //subscription ready
});

Say I only care about retractions? Then I'd have to pass null for all the others. You could instead do:

thoonk.subscribe({
    retract: function () {
        // my retract callback
    },
    add: function () {
         // my add callback
    }
});
legastero commented 13 years ago

Develop branch has the nicer API now.