vue-resource
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -5,3 +5,3 @@ { | ||
"description": "A web request service for Vue.js", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"homepage": "https://github.com/vuejs/vue-resource", | ||
@@ -8,0 +8,0 @@ "license": "MIT", |
/** | ||
* vue-resource v0.1.5 | ||
* vue-resource v0.1.6 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -105,3 +105,3 @@ * Released under the MIT License. | ||
if (options.root !== false && !url.match(/^(https?:)?\//)) { | ||
if (typeof options.root === 'string' && !url.match(/^(https?:)?\//)) { | ||
url = options.root + '/' + url; | ||
@@ -134,3 +134,2 @@ } | ||
url: '', | ||
root: false, | ||
params: {} | ||
@@ -360,37 +359,33 @@ }; | ||
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, { | ||
promise.success = function (fn) { | ||
success: function (onSuccess) { | ||
promise.then(function (response) { | ||
fn.call(self, response.data, response.status, response); | ||
}); | ||
this.then(function (request) { | ||
onSuccess.apply(self, parseReq(request)); | ||
}, function () {}); | ||
return promise; | ||
}; | ||
return this; | ||
}, | ||
promise.error = function (fn) { | ||
error: function (onError) { | ||
promise.catch(function (response) { | ||
fn.call(self, response.data, response.status, response); | ||
}); | ||
this.catch(function (request) { | ||
onError.apply(self, parseReq(request)); | ||
}); | ||
return promise; | ||
}; | ||
return this; | ||
}, | ||
promise.always = function (fn) { | ||
always: function (onAlways) { | ||
var cb = function (response) { | ||
fn.call(self, response.data, response.status, response); | ||
}; | ||
var cb = function (request) { | ||
onAlways.apply(self, parseReq(request)); | ||
}; | ||
promise.then(cb, cb); | ||
this.then(cb, cb); | ||
return promise; | ||
}; | ||
return this; | ||
} | ||
}); | ||
if (options.success) { | ||
@@ -511,13 +506,11 @@ promise.success(options.success); | ||
function parseReq(request) { | ||
function transformResponse(response) { | ||
var result; | ||
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; | ||
} | ||
@@ -532,3 +525,3 @@ | ||
emulateHTTP: false, | ||
emulateJSON: false, | ||
emulateJSON: false | ||
}; | ||
@@ -535,0 +528,0 @@ |
/** | ||
* vue-resource v0.1.5 | ||
* vue-resource v0.1.6 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -7,2 +7,2 @@ * Released under the MIT License. | ||
!function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function r(t){t.url=n(1)(t),t.http=n(3)(t),t.resource=n(5)(t)}window.Vue&&Vue.use(r),t.exports=r},function(t,e,n){t.exports=function(t){function e(t,n){var r,s={},i={},c=t;return a.isPlainObject(c)||(c={url:t,params:n}),c=a.extend({},e.options,a.options("url",this,c)),t=c.url.replace(/:([a-z]\w*)/gi,function(t,e){return c.params[e]?(s[e]=!0,o(c.params[e])):""}),c.root===!1||t.match(/^(https?:)?\//)||(t=c.root+"/"+t),t=t.replace(/([^:])[\/]{2,}/g,"$1/"),t=t.replace(/(\w+)\/+$/,"$1"),a.each(c.params,function(t,e){s[e]||(i[e]=t)}),r=e.params(i),r&&(t+=(-1==t.indexOf("?")?"?":"&")+r),t}function r(t,e,n){var o,s=a.isArray(e),i=a.isPlainObject(e);a.each(e,function(e,c){o=a.isObject(e)||a.isArray(e),n&&(c=n+"["+(i||o?c:"")+"]"),!n&&s?t.add(e.name,e.value):o?r(t,e,c):t.add(c,e)})}function o(t){return s(t,!0).replace(/%26/gi,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+")}function s(t,e){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,e?"%20":"+")}var a=n(2)(t);return e.options={url:"",root:!1,params:{}},e.params=function(t){var e=[];return e.add=function(t,e){a.isFunction(e)&&(e=e()),null===e&&(e=""),this.push(o(t)+"="+o(e))},r(e,t),e.join("&")},e.parse=function(t){var e=new RegExp("^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?"),n=t.match(e);return{url:t,scheme:n[1]||"",host:n[2]||"",path:n[3]||"",query:n[4]||"",fragment:n[5]||""}},Object.defineProperty(t.prototype,"$url",{get:function(){return a.extend(e.bind(this),e)}}),e}},function(t,e){t.exports=function(t){function e(t,r,o){for(var s in r)o&&(n.isPlainObject(r[s])||n.isArray(r[s]))?(n.isPlainObject(r[s])&&!n.isPlainObject(t[s])&&(t[s]={}),n.isArray(r[s])&&!n.isArray(t[s])&&(t[s]=[]),e(t[s],r[s],o)):void 0!==r[s]&&(t[s]=r[s])}var n=t.util.extend({},t.util);return n.options=function(t,e,r){var o=e.$options||{};return n.extend({},o[t],r)},n.each=function(t,e){var r,o;if("number"==typeof t.length)for(r=0;r<t.length;r++)e.call(t[r],t[r],r);else if(n.isObject(t))for(o in t)t.hasOwnProperty(o)&&e.call(t[o],t[o],o);return t},n.extend=function(t){var n,r=[],o=r.slice.call(arguments,1);return"boolean"==typeof t&&(n=t,t=o.shift()),o.forEach(function(r){e(t,r,n)}),t},n.isFunction=function(t){return t&&"function"==typeof t},n}},function(t,e,n){t.exports=function(t){function e(n,i){var c,u,p=this;return i=i||{},a.isPlainObject(n)&&(i=n,n=""),c=a.extend({},e.headers.common,e.headers[i.method.toLowerCase()]),i=a.extend(!0,{url:n,headers:c},e.options,a.options("http",this,i)),a.isPlainObject(i.data)&&/^(get|jsonp)$/i.test(i.method)&&(a.extend(i.params,i.data),i.data=""),u=("jsonp"==i.method.toLowerCase()?o:r).call(this,this.$url||t.url,i),a.extend(u,{success:function(t){return this.then(function(e){t.apply(p,s(e))},function(){}),this},error:function(t){return this["catch"](function(e){t.apply(p,s(e))}),this},always:function(t){var e=function(e){t.apply(p,s(e))};return this.then(e,e),this}}),i.success&&u.success(i.success),i.error&&u.error(i.error),u}function r(t,e){var n=new XMLHttpRequest;a.isFunction(e.beforeSend)&&e.beforeSend(n,e),e.emulateHTTP&&/^(put|patch|delete)$/i.test(e.method)&&(e.headers["X-HTTP-Method-Override"]=e.method,e.method="post"),e.emulateJSON&&a.isPlainObject(e.data)&&(e.headers["Content-Type"]="application/x-www-form-urlencoded",e.data=t.params(e.data)),a.isObject(e.data)&&/FormData/i.test(e.data.toString())&&delete e.headers["Content-Type"],a.isPlainObject(e.data)&&(e.data=JSON.stringify(e.data));var r=new i(function(r,o){n.open(e.method,t(e),!0),a.each(e.headers,function(t,e){n.setRequestHeader(e,t)}),n.onreadystatechange=function(){4===this.readyState&&(this.status>=200&&this.status<300?r(this):o(this))},n.send(e.data)});return a.extend(r,{abort:function(){n.abort()}}),r}function o(t,e){var n,r,o="_jsonp"+Math.random().toString(36).substr(2);e.params[e.jsonp]=o,a.isFunction(e.beforeSend)&&e.beforeSend({},e);var s=new i(function(s,a){n=document.createElement("script"),n.src=t(e.url,e.params),n.type="text/javascript",n.async=!0,window[o]=function(t){r=t};var i=function(t){delete window[o],document.body.removeChild(n),"load"!==t.type||r||(t.type="error");var e=r?r:t.type,i="error"===t.type?404:200;(200===i?s:a)({responseText:e,status:i})};n.onload=i,n.onerror=i,document.body.appendChild(n)});return s}function s(t){var e;try{e=JSON.parse(t.responseText)}catch(n){e=t.responseText}return[e,t.status,t]}var a=n(2)(t),i=n(4),c={"Content-Type":"application/json;charset=utf-8"};return e.options={method:"get",params:{},data:"",jsonp:"callback",beforeSend:null,emulateHTTP:!1,emulateJSON:!1},e.headers={put:c,post:c,patch:c,"delete":c,common:{Accept:"application/json, text/plain, */*","X-Requested-With":"XMLHttpRequest"}},["get","put","post","patch","delete","jsonp"].forEach(function(t){e[t]=function(e,n,r,o){return a.isFunction(n)&&(o=r,r=n,n=void 0),this(e,a.extend({method:t,data:n,success:r},o))}}),Object.defineProperty(t.prototype,"$http",{get:function(){return a.extend(e.bind(this),e)}}),e}},function(t,e){function n(t){t(this.resolve.bind(this),this.reject.bind(this)),this._thens=[]}n.prototype={then:function(t,e,n){this._thens.push({resolve:t,reject:e,progress:n})},"catch":function(t){this._thens.push({reject:t})},resolve:function(t){this._complete("resolve",t)},reject:function(t){this._complete("reject",t)},progress:function(t){for(var e,n=0;e=this._thens[n++];)e.progress&&e.progress(t)},_complete:function(t,e){this.then="resolve"===t?function(t,n){t&&t(e)}:function(t,n){n&&n(e)},this.resolve=this.reject=this.progress=function(){throw new Error("Promise already completed.")};for(var n,r=0;n=this._thens[r++];)n[t]&&n[t](e);delete this._thens}},t.exports=window.Promise?window.Promise:n},function(t,e,n){t.exports=function(t){function e(n,s,a){var i=this,c={};return a=o.extend({},e.actions,a),o.each(a,function(e,a){e=o.extend(!0,{url:n,params:s||{}},e),c[a]=function(){return(i.$http||t.http)(r(e,arguments))}}),c}function r(t,e){var n,r,s,a=o.extend({},t),i={};switch(e.length){case 4:s=e[3],r=e[2];case 3:case 2:if(!o.isFunction(e[1])){i=e[0],n=e[1],r=e[2];break}if(o.isFunction(e[0])){r=e[0],s=e[1];break}r=e[1],s=e[2];case 1:o.isFunction(e[0])?r=e[0]:/^(POST|PUT|PATCH)$/i.test(a.method)?n=e[0]:i=e[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, data, success, error], got "+e.length+" arguments"}return a.url=t.url,a.data=n,a.params=o.extend({},t.params,i),r&&(a.success=r),s&&(a.error=s),a}var o=n(2)(t);return e.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},remove:{method:"DELETE"},"delete":{method:"DELETE"}},Object.defineProperty(t.prototype,"$resource",{get:function(){return e.bind(this)}}),e}}]); | ||
!function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function r(t){t.url=n(1)(t),t.http=n(3)(t),t.resource=n(5)(t)}window.Vue&&Vue.use(r),t.exports=r},function(t,e,n){t.exports=function(t){function e(t,n){var r,a={},i={},c=t;return s.isPlainObject(c)||(c={url:t,params:n}),c=s.extend({},e.options,s.options("url",this,c)),t=c.url.replace(/:([a-z]\w*)/gi,function(t,e){return c.params[e]?(a[e]=!0,o(c.params[e])):""}),"string"!=typeof c.root||t.match(/^(https?:)?\//)||(t=c.root+"/"+t),t=t.replace(/([^:])[\/]{2,}/g,"$1/"),t=t.replace(/(\w+)\/+$/,"$1"),s.each(c.params,function(t,e){a[e]||(i[e]=t)}),r=e.params(i),r&&(t+=(-1==t.indexOf("?")?"?":"&")+r),t}function r(t,e,n){var o,a=s.isArray(e),i=s.isPlainObject(e);s.each(e,function(e,c){o=s.isObject(e)||s.isArray(e),n&&(c=n+"["+(i||o?c:"")+"]"),!n&&a?t.add(e.name,e.value):o?r(t,e,c):t.add(c,e)})}function o(t){return a(t,!0).replace(/%26/gi,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+")}function a(t,e){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,e?"%20":"+")}var s=n(2)(t);return e.options={url:"",params:{}},e.params=function(t){var e=[];return e.add=function(t,e){s.isFunction(e)&&(e=e()),null===e&&(e=""),this.push(o(t)+"="+o(e))},r(e,t),e.join("&")},e.parse=function(t){var e=new RegExp("^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\\?([^#]*))?(?:#(.*))?"),n=t.match(e);return{url:t,scheme:n[1]||"",host:n[2]||"",path:n[3]||"",query:n[4]||"",fragment:n[5]||""}},Object.defineProperty(t.prototype,"$url",{get:function(){return s.extend(e.bind(this),e)}}),e}},function(t,e){t.exports=function(t){function e(t,r,o){for(var a in r)o&&(n.isPlainObject(r[a])||n.isArray(r[a]))?(n.isPlainObject(r[a])&&!n.isPlainObject(t[a])&&(t[a]={}),n.isArray(r[a])&&!n.isArray(t[a])&&(t[a]=[]),e(t[a],r[a],o)):void 0!==r[a]&&(t[a]=r[a])}var n=t.util.extend({},t.util);return n.options=function(t,e,r){var o=e.$options||{};return n.extend({},o[t],r)},n.each=function(t,e){var r,o;if("number"==typeof t.length)for(r=0;r<t.length;r++)e.call(t[r],t[r],r);else if(n.isObject(t))for(o in t)t.hasOwnProperty(o)&&e.call(t[o],t[o],o);return t},n.extend=function(t){var n,r=[],o=r.slice.call(arguments,1);return"boolean"==typeof t&&(n=t,t=o.shift()),o.forEach(function(r){e(t,r,n)}),t},n.isFunction=function(t){return t&&"function"==typeof t},n}},function(t,e,n){t.exports=function(t){function e(n,i){var c,u,p=this;return i=i||{},s.isPlainObject(n)&&(i=n,n=""),c=s.extend({},e.headers.common,e.headers[i.method.toLowerCase()]),i=s.extend(!0,{url:n,headers:c},e.options,s.options("http",this,i)),s.isPlainObject(i.data)&&/^(get|jsonp)$/i.test(i.method)&&(s.extend(i.params,i.data),i.data=""),u=("jsonp"==i.method.toLowerCase()?o:r).call(this,this.$url||t.url,i).then(a,a),u.success=function(t){return u.then(function(e){t.call(p,e.data,e.status,e)}),u},u.error=function(t){return u["catch"](function(e){t.call(p,e.data,e.status,e)}),u},u.always=function(t){var e=function(e){t.call(p,e.data,e.status,e)};return u.then(e,e),u},i.success&&u.success(i.success),i.error&&u.error(i.error),u}function r(t,e){var n=new XMLHttpRequest;s.isFunction(e.beforeSend)&&e.beforeSend(n,e),e.emulateHTTP&&/^(put|patch|delete)$/i.test(e.method)&&(e.headers["X-HTTP-Method-Override"]=e.method,e.method="post"),e.emulateJSON&&s.isPlainObject(e.data)&&(e.headers["Content-Type"]="application/x-www-form-urlencoded",e.data=t.params(e.data)),s.isObject(e.data)&&/FormData/i.test(e.data.toString())&&delete e.headers["Content-Type"],s.isPlainObject(e.data)&&(e.data=JSON.stringify(e.data));var r=new i(function(r,o){n.open(e.method,t(e),!0),s.each(e.headers,function(t,e){n.setRequestHeader(e,t)}),n.onreadystatechange=function(){4===this.readyState&&(this.status>=200&&this.status<300?r(this):o(this))},n.send(e.data)});return s.extend(r,{abort:function(){n.abort()}}),r}function o(t,e){var n,r,o="_jsonp"+Math.random().toString(36).substr(2);e.params[e.jsonp]=o,s.isFunction(e.beforeSend)&&e.beforeSend({},e);var a=new i(function(a,s){n=document.createElement("script"),n.src=t(e.url,e.params),n.type="text/javascript",n.async=!0,window[o]=function(t){r=t};var i=function(t){delete window[o],document.body.removeChild(n),"load"!==t.type||r||(t.type="error");var e=r?r:t.type,i="error"===t.type?404:200;(200===i?a:s)({responseText:e,status:i})};n.onload=i,n.onerror=i,document.body.appendChild(n)});return a}function a(t){try{t.data=JSON.parse(t.responseText)}catch(e){t.data=t.responseText}return t}var s=n(2)(t),i=n(4),c={"Content-Type":"application/json;charset=utf-8"};return e.options={method:"get",params:{},data:"",jsonp:"callback",beforeSend:null,emulateHTTP:!1,emulateJSON:!1},e.headers={put:c,post:c,patch:c,"delete":c,common:{Accept:"application/json, text/plain, */*","X-Requested-With":"XMLHttpRequest"}},["get","put","post","patch","delete","jsonp"].forEach(function(t){e[t]=function(e,n,r,o){return s.isFunction(n)&&(o=r,r=n,n=void 0),this(e,s.extend({method:t,data:n,success:r},o))}}),Object.defineProperty(t.prototype,"$http",{get:function(){return s.extend(e.bind(this),e)}}),e}},function(t,e){function n(t){t(this.resolve.bind(this),this.reject.bind(this)),this._thens=[]}n.prototype={then:function(t,e,n){this._thens.push({resolve:t,reject:e,progress:n})},"catch":function(t){this._thens.push({reject:t})},resolve:function(t){this._complete("resolve",t)},reject:function(t){this._complete("reject",t)},progress:function(t){for(var e,n=0;e=this._thens[n++];)e.progress&&e.progress(t)},_complete:function(t,e){this.then="resolve"===t?function(t,n){t&&t(e)}:function(t,n){n&&n(e)},this.resolve=this.reject=this.progress=function(){throw new Error("Promise already completed.")};for(var n,r=0;n=this._thens[r++];)n[t]&&n[t](e);delete this._thens}},t.exports=window.Promise?window.Promise:n},function(t,e,n){t.exports=function(t){function e(n,a,s){var i=this,c={};return s=o.extend({},e.actions,s),o.each(s,function(e,s){e=o.extend(!0,{url:n,params:a||{}},e),c[s]=function(){return(i.$http||t.http)(r(e,arguments))}}),c}function r(t,e){var n,r,a,s=o.extend({},t),i={};switch(e.length){case 4:a=e[3],r=e[2];case 3:case 2:if(!o.isFunction(e[1])){i=e[0],n=e[1],r=e[2];break}if(o.isFunction(e[0])){r=e[0],a=e[1];break}r=e[1],a=e[2];case 1:o.isFunction(e[0])?r=e[0]:/^(POST|PUT|PATCH)$/i.test(s.method)?n=e[0]:i=e[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, data, success, error], got "+e.length+" arguments"}return s.url=t.url,s.data=n,s.params=o.extend({},t.params,i),r&&(s.success=r),a&&(s.error=a),s}var o=n(2)(t);return e.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},remove:{method:"DELETE"},"delete":{method:"DELETE"}},Object.defineProperty(t.prototype,"$resource",{get:function(){return e.bind(this)}}),e}}]); |
{ | ||
"name": "vue-resource", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "A web request service for Vue.js", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -36,37 +36,33 @@ module.exports = function (Vue) { | ||
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, { | ||
promise.success = function (fn) { | ||
success: function (onSuccess) { | ||
promise.then(function (response) { | ||
fn.call(self, response.data, response.status, response); | ||
}); | ||
this.then(function (request) { | ||
onSuccess.apply(self, parseReq(request)); | ||
}, function () {}); | ||
return promise; | ||
}; | ||
return this; | ||
}, | ||
promise.error = function (fn) { | ||
error: function (onError) { | ||
promise.catch(function (response) { | ||
fn.call(self, response.data, response.status, response); | ||
}); | ||
this.catch(function (request) { | ||
onError.apply(self, parseReq(request)); | ||
}); | ||
return promise; | ||
}; | ||
return this; | ||
}, | ||
promise.always = function (fn) { | ||
always: function (onAlways) { | ||
var cb = function (response) { | ||
fn.call(self, response.data, response.status, response); | ||
}; | ||
var cb = function (request) { | ||
onAlways.apply(self, parseReq(request)); | ||
}; | ||
promise.then(cb, cb); | ||
this.then(cb, cb); | ||
return promise; | ||
}; | ||
return this; | ||
} | ||
}); | ||
if (options.success) { | ||
@@ -187,13 +183,11 @@ promise.success(options.success); | ||
function parseReq(request) { | ||
function transformResponse(response) { | ||
var result; | ||
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; | ||
} | ||
@@ -208,3 +202,3 @@ | ||
emulateHTTP: false, | ||
emulateJSON: false, | ||
emulateJSON: false | ||
}; | ||
@@ -211,0 +205,0 @@ |
@@ -32,3 +32,3 @@ module.exports = function (Vue) { | ||
if (options.root !== false && !url.match(/^(https?:)?\//)) { | ||
if (typeof options.root === 'string' && !url.match(/^(https?:)?\//)) { | ||
url = options.root + '/' + url; | ||
@@ -61,3 +61,2 @@ } | ||
url: '', | ||
root: false, | ||
params: {} | ||
@@ -64,0 +63,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45921
1054