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

Commit

Permalink
v0.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
steffans committed Aug 11, 2015
1 parent 58d180a commit be874dd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vue-resource",
"main": "dist/vue-resource.js",
"description": "A web request service for Vue.js",
"version": "0.1.11",
"version": "0.1.12",
"homepage": "https://github.com/vuejs/vue-resource",
"license": "MIT",
"ignore": [
Expand Down
61 changes: 34 additions & 27 deletions dist/vue-resource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vue-resource v0.1.11
* vue-resource v0.1.12
* https://github.com/vuejs/vue-resource
* Released under the MIT License.
*/
Expand Down Expand Up @@ -350,7 +350,7 @@ return /******/ (function(modules) { // webpackBootstrap

function Http(url, options) {

var self = this, promise;
var promise;

options = options || {};

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

options = _.extend(true, {url: url},
Http.options, _.options('http', self, options)
Http.options, _.options('http', this, options)
);

if (options.crossOrigin === null) {
options.crossOrigin = crossOrigin(options.url);
}

options.headers = _.extend({},
Http.headers.common,
options.method = options.method.toLowerCase();
options.headers = _.extend({}, Http.headers.common,
!options.crossOrigin ? Http.headers.custom : {},
Http.headers[options.method.toLowerCase()],
Http.headers[options.method],
options.headers
);

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

promise = (options.method.toLowerCase() == 'jsonp' ? jsonp : xhr).call(self, self.$url || Url, options).then(transformResponse, transformResponse);
promise = (options.method == 'jsonp' ? jsonp : xhr).call(this, this.$url || Url, options);
promise = extendPromise(promise.then(transformResponse, transformResponse), this);

if (options.success) {
promise = promise.success(options.success);
}

if (options.error) {
promise = promise.error(options.error);
}

return promise;
}

function extendPromise(promise, thisArg) {

promise.success = function (fn) {

promise.then(function (response) {
fn.call(self, response.data, response.status, response);
});
return extendPromise(promise.then(function (response) {
fn.call(thisArg, response.data, response.status, response);
}), thisArg);

return promise;
};

promise.error = function (fn) {

promise.then(undefined, function (response) {
fn.call(self, response.data, response.status, response);
});
return extendPromise(promise.then(undefined, function (response) {
fn.call(thisArg, response.data, response.status, response);
}), thisArg);

return promise;
};

promise.always = function (fn) {

var cb = function (response) {
fn.call(self, response.data, response.status, response);
fn.call(thisArg, response.data, response.status, response);
};

promise.then(cb, cb);

return promise;
return extendPromise(promise.then(cb, cb), thisArg);
};

if (options.success) {
promise.success(options.success);
}

if (options.error) {
promise.error(options.error);
}

return promise;
}

Expand All @@ -461,6 +463,7 @@ return /******/ (function(modules) { // webpackBootstrap
method: 'get',
params: {},
data: '',
xhr: null,
jsonp: 'callback',
beforeSend: null,
crossOrigin: null,
Expand Down Expand Up @@ -518,6 +521,10 @@ return /******/ (function(modules) { // webpackBootstrap

var request = new XMLHttpRequest(), promise;

if (_.isPlainObject(options.xhr)) {
_.extend(request, options.xhr);
}

if (_.isFunction(options.beforeSend)) {
options.beforeSend.call(this, request, options);
}
Expand Down
Loading

0 comments on commit be874dd

Please sign in to comment.