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

Commit

Permalink
v0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
steffans committed Jul 10, 2015
1 parent 0b1533b commit 6868247
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 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.5",
"version": "0.1.6",
"homepage": "https://github.com/vuejs/vue-resource",
"license": "MIT",
"ignore": [
Expand Down
61 changes: 27 additions & 34 deletions dist/vue-resource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vue-resource v0.1.5
* vue-resource v0.1.6
* https://github.com/vuejs/vue-resource
* Released under the MIT License.
*/
Expand Down Expand Up @@ -102,7 +102,7 @@
return '';
});

if (options.root !== false && !url.match(/^(https?:)?\//)) {
if (typeof options.root === 'string' && !url.match(/^(https?:)?\//)) {
url = options.root + '/' + url;
}

Expand Down Expand Up @@ -130,7 +130,6 @@

Url.options = {
url: '',
root: false,
params: {}
};

Expand Down Expand Up @@ -355,40 +354,36 @@
options.data = '';
}

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

_.extend(promise, {

success: function (onSuccess) {

this.then(function (request) {
onSuccess.apply(self, parseReq(request));
}, function () {});
promise.success = function (fn) {

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

error: function (onError) {
return promise;
};

this.catch(function (request) {
onError.apply(self, parseReq(request));
});
promise.error = function (fn) {

return this;
},
promise.catch(function (response) {
fn.call(self, response.data, response.status, response);
});

always: function (onAlways) {
return promise;
};

var cb = function (request) {
onAlways.apply(self, parseReq(request));
};
promise.always = function (fn) {

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

return this;
}
promise.then(cb, cb);

});
return promise;
};

if (options.success) {
promise.success(options.success);
Expand Down Expand Up @@ -505,17 +500,15 @@
return promise;
}

function parseReq(request) {

var result;
function transformResponse(response) {

try {
result = JSON.parse(request.responseText);
response.data = JSON.parse(response.responseText);
} catch (e) {
result = request.responseText;
response.data = response.responseText;
}

return [result, request.status, request];
return response;
}

Http.options = {
Expand All @@ -525,7 +518,7 @@
jsonp: 'callback',
beforeSend: null,
emulateHTTP: false,
emulateJSON: false,
emulateJSON: false
};

Http.headers = {
Expand Down
4 changes: 2 additions & 2 deletions dist/vue-resource.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-resource",
"version": "0.1.5",
"version": "0.1.6",
"description": "A web request service for Vue.js",
"main": "src/index.js",
"scripts": {
Expand Down

0 comments on commit 6868247

Please sign in to comment.