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

Commit 6868247

Browse files
committed
v0.1.6
1 parent 0b1533b commit 6868247

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
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.5",
5+
"version": "0.1.6",
66
"homepage": "https://github.com/vuejs/vue-resource",
77
"license": "MIT",
88
"ignore": [

dist/vue-resource.js

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* vue-resource v0.1.5
2+
* vue-resource v0.1.6
33
* https://github.com/vuejs/vue-resource
44
* Released under the MIT License.
55
*/
@@ -102,7 +102,7 @@
102102
return '';
103103
});
104104

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

@@ -130,7 +130,6 @@
130130

131131
Url.options = {
132132
url: '',
133-
root: false,
134133
params: {}
135134
};
136135

@@ -355,40 +354,36 @@
355354
options.data = '';
356355
}
357356

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

360-
_.extend(promise, {
361-
362-
success: function (onSuccess) {
363-
364-
this.then(function (request) {
365-
onSuccess.apply(self, parseReq(request));
366-
}, function () {});
359+
promise.success = function (fn) {
367360

368-
return this;
369-
},
361+
promise.then(function (response) {
362+
fn.call(self, response.data, response.status, response);
363+
});
370364

371-
error: function (onError) {
365+
return promise;
366+
};
372367

373-
this.catch(function (request) {
374-
onError.apply(self, parseReq(request));
375-
});
368+
promise.error = function (fn) {
376369

377-
return this;
378-
},
370+
promise.catch(function (response) {
371+
fn.call(self, response.data, response.status, response);
372+
});
379373

380-
always: function (onAlways) {
374+
return promise;
375+
};
381376

382-
var cb = function (request) {
383-
onAlways.apply(self, parseReq(request));
384-
};
377+
promise.always = function (fn) {
385378

386-
this.then(cb, cb);
379+
var cb = function (response) {
380+
fn.call(self, response.data, response.status, response);
381+
};
387382

388-
return this;
389-
}
383+
promise.then(cb, cb);
390384

391-
});
385+
return promise;
386+
};
392387

393388
if (options.success) {
394389
promise.success(options.success);
@@ -505,17 +500,15 @@
505500
return promise;
506501
}
507502

508-
function parseReq(request) {
509-
510-
var result;
503+
function transformResponse(response) {
511504

512505
try {
513-
result = JSON.parse(request.responseText);
506+
response.data = JSON.parse(response.responseText);
514507
} catch (e) {
515-
result = request.responseText;
508+
response.data = response.responseText;
516509
}
517510

518-
return [result, request.status, request];
511+
return response;
519512
}
520513

521514
Http.options = {
@@ -525,7 +518,7 @@
525518
jsonp: 'callback',
526519
beforeSend: null,
527520
emulateHTTP: false,
528-
emulateJSON: false,
521+
emulateJSON: false
529522
};
530523

531524
Http.headers = {

dist/vue-resource.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-resource",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "A web request service for Vue.js",
55
"main": "src/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)