Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve transport logic (support batch requests) #152

Merged

Conversation

jharding
Copy link
Contributor

Piggyback off of pending requests intelligently. Previously the following code would result in 2 separate requests being made to https://twitter.com?q=query:

var transport1 = new Transport({ 
      url: 'https://twitter.com?q=%QUERY' 
    }),
    transport2 = new Transport({ 
      url: 'https://twitter.com?q=%QUERY'
    });

transport1.get('query');
transport2.get('query');

Now, before a transport makes a request to a url, it checks to see if there's already a pending request to that url and if there is, it'll rely on the response from that pending request.

The main benefit of this is that it's now possible to do batch requests i.e.

$('.typeahead').typeahead([
  {
    name: 'colors',
    remote: {
      url: 'http://everything.com?q=%QUERY',
      filter: function(resp) { return resp.colors; }
    }
  },
  {
    name: 'numbers',
    remote: {
      url: 'http://everything.com?q=%QUERY',
      filter: function(resp) { return resp.numbers; }
    }
  }
]);

This pull request also fixes a bug mentioned in #151.

@jharding
Copy link
Contributor Author

@timtrueman can you give this a once over when you get a chance? No rush.

@timtrueman
Copy link
Contributor

The word "batch" confused me into thinking this would batch requests into a single request but this code looks great; it's just more of a shared request cache than a batched request model.

Ship it.

jharding added a commit that referenced this pull request Mar 30, 2013
Improve transport logic (support batch requests)
@jharding jharding merged commit 3a77aea into twitter:integration-0.9.1 Mar 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants