How to use the xhr.bind function in xhr

To help you get started, we’ve selected a few xhr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yoshuawuyts / fax / lib / index.js View on Github external
function *xhrmw(next) {
  if (!this.url) return yield next;

  var opts = {
    url: this.url,
    body: this.body,
    method: this.method,
    headers: this.headers
  };

  var thunk = xhr.bind(null, opts);
  var response = yield thunk;

  var res = response[0];
  if (res instanceof Error) throw res;

  Object.keys(res).forEach(function(key) {
    this.res[key] = res[key];
  }.bind(this));

  yield next;
}