Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit be874dd

Browse files
committed
v0.1.12
1 parent 58d180a commit be874dd

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vue-resource",
33
"main": "dist/vue-resource.js",
44
"description": "A web request service for Vue.js",
5-
"version": "0.1.11",
5+
"version": "0.1.12",
66
"homepage": "https://github.com/vuejs/vue-resource",
77
"license": "MIT",
88
"ignore": [

dist/vue-resource.js

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* vue-resource v0.1.11
2+
* vue-resource v0.1.12
33
* https://github.com/vuejs/vue-resource
44
* Released under the MIT License.
55
*/
@@ -350,7 +350,7 @@ return /******/ (function(modules) { // webpackBootstrap
350350

351351
function Http(url, options) {
352352

353-
var self = this, promise;
353+
var promise;
354354

355355
options = options || {};
356356

@@ -360,17 +360,17 @@ return /******/ (function(modules) { // webpackBootstrap
360360
}
361361

362362
options = _.extend(true, {url: url},
363-
Http.options, _.options('http', self, options)
363+
Http.options, _.options('http', this, options)
364364
);
365365

366366
if (options.crossOrigin === null) {
367367
options.crossOrigin = crossOrigin(options.url);
368368
}
369369

370-
options.headers = _.extend({},
371-
Http.headers.common,
370+
options.method = options.method.toLowerCase();
371+
options.headers = _.extend({}, Http.headers.common,
372372
!options.crossOrigin ? Http.headers.custom : {},
373-
Http.headers[options.method.toLowerCase()],
373+
Http.headers[options.method],
374374
options.headers
375375
);
376376

@@ -397,45 +397,47 @@ return /******/ (function(modules) { // webpackBootstrap
397397
options.data = JSON.stringify(options.data);
398398
}
399399

400-
promise = (options.method.toLowerCase() == 'jsonp' ? jsonp : xhr).call(self, self.$url || Url, options).then(transformResponse, transformResponse);
400+
promise = (options.method == 'jsonp' ? jsonp : xhr).call(this, this.$url || Url, options);
401+
promise = extendPromise(promise.then(transformResponse, transformResponse), this);
402+
403+
if (options.success) {
404+
promise = promise.success(options.success);
405+
}
406+
407+
if (options.error) {
408+
promise = promise.error(options.error);
409+
}
410+
411+
return promise;
412+
}
413+
414+
function extendPromise(promise, thisArg) {
401415

402416
promise.success = function (fn) {
403417

404-
promise.then(function (response) {
405-
fn.call(self, response.data, response.status, response);
406-
});
418+
return extendPromise(promise.then(function (response) {
419+
fn.call(thisArg, response.data, response.status, response);
420+
}), thisArg);
407421

408-
return promise;
409422
};
410423

411424
promise.error = function (fn) {
412425

413-
promise.then(undefined, function (response) {
414-
fn.call(self, response.data, response.status, response);
415-
});
426+
return extendPromise(promise.then(undefined, function (response) {
427+
fn.call(thisArg, response.data, response.status, response);
428+
}), thisArg);
416429

417-
return promise;
418430
};
419431

420432
promise.always = function (fn) {
421433

422434
var cb = function (response) {
423-
fn.call(self, response.data, response.status, response);
435+
fn.call(thisArg, response.data, response.status, response);
424436
};
425437

426-
promise.then(cb, cb);
427-
428-
return promise;
438+
return extendPromise(promise.then(cb, cb), thisArg);
429439
};
430440

431-
if (options.success) {
432-
promise.success(options.success);
433-
}
434-
435-
if (options.error) {
436-
promise.error(options.error);
437-
}
438-
439441
return promise;
440442
}
441443

@@ -461,6 +463,7 @@ return /******/ (function(modules) { // webpackBootstrap
461463
method: 'get',
462464
params: {},
463465
data: '',
466+
xhr: null,
464467
jsonp: 'callback',
465468
beforeSend: null,
466469
crossOrigin: null,
@@ -518,6 +521,10 @@ return /******/ (function(modules) { // webpackBootstrap
518521

519522
var request = new XMLHttpRequest(), promise;
520523

524+
if (_.isPlainObject(options.xhr)) {
525+
_.extend(request, options.xhr);
526+
}
527+
521528
if (_.isFunction(options.beforeSend)) {
522529
options.beforeSend.call(this, request, options);
523530
}

0 commit comments

Comments
 (0)