I'm working on a Twitter webapp, and I want to display both the
friends_timeline and replies streams, mixed together in chronological
(or reverse chronological) order. (FYI: the replies stream collects
tweets from people you *don't* follow as well as people you do. That's
why I want both.)

I can do

$.getJSON(friendURL, function(data){
  $.each(data, function(item){
    // Put the item on the page.
  });
});

$.getJSON(replyURL, function(data){
  $.each(data, function(item){
    // Put the item on the page.
  });
});

This collects everything and displays it, but the two streams are
separate. I'd like to be able to use $.extend() or $.merge() to create
one big stream and then sort it before displaying. But the asynchonous
nature of getJSON keeps confounding me. I thought nesting would work:

$.getJSON(friendURL, function(friends){
  $.getJSON(replyURL, function(replies){
    $.extend(friends, replies);
  });
  $.each(friends, function(item){
    // Put the item on the page.
  });
});

but it doesn't. I end up with just the friends timeline.

Is there a standard way of combining two objects that come from
getJSON?

Reply via email to