vue-resource
Advanced tools
Comparing version 0.1.10 to 0.1.11
/** | ||
* vue-resource v0.1.10 | ||
* vue-resource v0.1.11 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -343,3 +343,3 @@ * Released under the MIT License. | ||
var jsonp = __webpack_require__(6); | ||
var jsonType = {'Content-Type': 'application/json;charset=utf-8'}; | ||
var Promise = __webpack_require__(5); | ||
@@ -350,2 +350,3 @@ module.exports = function (Vue) { | ||
var originUrl = Url.parse(location.href); | ||
var jsonType = {'Content-Type': 'application/json;charset=utf-8'}; | ||
@@ -401,6 +402,4 @@ function Http(url, options) { | ||
promise = (options.method.toLowerCase() == 'jsonp' ? jsonp : xhr).call(self, self.$url || Url, options); | ||
promise = (options.method.toLowerCase() == 'jsonp' ? jsonp : xhr).call(self, self.$url || Url, options).then(transformResponse, transformResponse); | ||
promise.then(transformResponse, transformResponse); | ||
promise.success = function (fn) { | ||
@@ -410,3 +409,3 @@ | ||
fn.call(self, response.data, response.status, response); | ||
}, function () {}); | ||
}); | ||
@@ -418,3 +417,3 @@ return promise; | ||
promise.catch(function (response) { | ||
promise.then(undefined, function (response) { | ||
fn.call(self, response.data, response.status, response); | ||
@@ -456,2 +455,3 @@ }); | ||
return response.ok ? response : Promise.reject(response); | ||
} | ||
@@ -541,9 +541,7 @@ | ||
if (this.readyState === 4) { | ||
if (request.readyState === 4) { | ||
if (this.status >= 200 && this.status < 300) { | ||
resolve(this); | ||
} else { | ||
reject(this); | ||
} | ||
request.ok = request.status >= 200 && request.status < 300; | ||
(request.ok ? resolve : reject)(request); | ||
} | ||
@@ -555,10 +553,2 @@ }; | ||
_.extend(promise, { | ||
abort: function () { | ||
request.abort(); | ||
} | ||
}); | ||
return promise; | ||
@@ -797,3 +787,3 @@ }; | ||
var callback = '_jsonp' + Math.random().toString(36).substr(2), script, body; | ||
var callback = '_jsonp' + Math.random().toString(36).substr(2), response = {}, script, body; | ||
@@ -826,5 +816,7 @@ options.params[options.jsonp] = callback; | ||
var text = body ? body : event.type, status = event.type === 'error' ? 404 : 200; | ||
response.ok = event.type !== 'error'; | ||
response.status = response.ok ? 200 : 404; | ||
response.responseText = body ? body : event.type; | ||
(status === 200 ? resolve : reject)({responseText: text, status: status}); | ||
(response.ok ? resolve : reject)(response); | ||
}; | ||
@@ -951,2 +943,3 @@ | ||
query: {method: 'get'}, | ||
update: {method: 'put'}, | ||
remove: {method: 'delete'}, | ||
@@ -953,0 +946,0 @@ delete: {method: 'delete'} |
/** | ||
* vue-resource v0.1.10 | ||
* vue-resource v0.1.11 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -7,2 +7,2 @@ * Released under the MIT License. | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports.VueResource=e():t.VueResource=e()}(this,function(){return 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(7)(t)}window.Vue&&Vue.use(r),t.exports=r},function(t,e,n){var r=n(2),o=document.createElement("a");t.exports=function(t){function e(t,n){var o,i={},s={},c=t;return r.isPlainObject(c)||(c={url:t,params:n}),c=r.extend({},e.options,r.options("url",this,c)),t=c.url.replace(/:([a-z]\w*)/gi,function(t,e){return c.params[e]?(i[e]=!0,a(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"),r.each(c.params,function(t,e){i[e]||(s[e]=t)}),o=e.params(s),o&&(t+=(-1==t.indexOf("?")?"?":"&")+o),t}function n(t,e,o){var a,i=r.isArray(e),s=r.isPlainObject(e);r.each(e,function(e,c){a=r.isObject(e)||r.isArray(e),o&&(c=o+"["+(s||a?c:"")+"]"),!o&&i?t.add(e.name,e.value):a?n(t,e,c):t.add(c,e)})}function a(t){return i(t,!0).replace(/%26/gi,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+")}function i(t,e){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,e?"%20":"+")}return e.options={url:"",params:{}},e.params=function(t){var e=[];return e.add=function(t,e){r.isFunction(e)&&(e=e()),null===e&&(e=""),this.push(a(t)+"="+a(e))},n(e,t),e.join("&")},e.parse=function(t){return o.href=t,{href:o.href,protocol:o.protocol?o.protocol.replace(/:$/,""):"",port:o.port,host:o.host,hostname:o.hostname,pathname:"/"===o.pathname.charAt(0)?o.pathname:"/"+o.pathname,search:o.search?o.search.replace(/^\?/,""):"",hash:o.hash?o.hash.replace(/^#/,""):""}},Object.defineProperty(t.prototype,"$url",{get:function(){return r.extend(e.bind(this),e)}}),e}},function(t,e){function n(t,e,o){for(var a in e)o&&(r.isPlainObject(e[a])||r.isArray(e[a]))?(r.isPlainObject(e[a])&&!r.isPlainObject(t[a])&&(t[a]={}),r.isArray(e[a])&&!r.isArray(t[a])&&(t[a]=[]),n(t[a],e[a],o)):void 0!==e[a]&&(t[a]=e[a])}var r=e;r.isArray=Array.isArray,r.isFunction=function(t){return t&&"function"==typeof t},r.isObject=function(t){return null!==t&&"object"==typeof t},r.isPlainObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)},r.options=function(t,e,n){var o=e.$options||{};return r.extend({},o[t],n)},r.each=function(t,e){var n,o;if("number"==typeof t.length)for(n=0;n<t.length;n++)e.call(t[n],t[n],n);else if(r.isObject(t))for(o in t)t.hasOwnProperty(o)&&e.call(t[o],t[o],o);return t},r.extend=function(t){var e,r=[],o=r.slice.call(arguments,1);return"boolean"==typeof t&&(e=t,t=o.shift()),o.forEach(function(r){n(t,r,e)}),t}},function(t,e,n){var r=n(2),o=n(4),a=n(6),i={"Content-Type":"application/json;charset=utf-8"};t.exports=function(t){function e(t,i){var u,f=this;return i=i||{},r.isPlainObject(t)&&(i=t,t=""),i=r.extend(!0,{url:t},e.options,r.options("http",f,i)),null===i.crossOrigin&&(i.crossOrigin=s(i.url)),i.headers=r.extend({},e.headers.common,i.crossOrigin?{}:e.headers.custom,e.headers[i.method.toLowerCase()],i.headers),r.isPlainObject(i.data)&&/^(get|jsonp)$/i.test(i.method)&&(r.extend(i.params,i.data),delete i.data),i.emulateHTTP&&!i.crossOrigin&&/^(put|patch|delete)$/i.test(i.method)&&(i.headers["X-HTTP-Method-Override"]=i.method,i.method="post"),i.emulateJSON&&r.isPlainObject(i.data)&&(i.headers["Content-Type"]="application/x-www-form-urlencoded",i.data=c.params(i.data)),r.isObject(i.data)&&/FormData/i.test(i.data.toString())&&delete i.headers["Content-Type"],r.isPlainObject(i.data)&&(i.data=JSON.stringify(i.data)),u=("jsonp"==i.method.toLowerCase()?a:o).call(f,f.$url||c,i),u.then(n,n),u.success=function(t){return u.then(function(e){t.call(f,e.data,e.status,e)},function(){}),u},u.error=function(t){return u["catch"](function(e){t.call(f,e.data,e.status,e)}),u},u.always=function(t){var e=function(e){t.call(f,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 n(t){try{t.data=JSON.parse(t.responseText)}catch(e){t.data=t.responseText}}function s(t){var e=c.parse(t);return e.protocol!==u.protocol||e.host!==u.host}var c=t.url,u=c.parse(location.href);return e.options={method:"get",params:{},data:"",jsonp:"callback",beforeSend:null,crossOrigin:null,emulateHTTP:!1,emulateJSON:!1},e.headers={put:i,post:i,patch:i,"delete":i,common:{Accept:"application/json, text/plain, */*"},custom:{"X-Requested-With":"XMLHttpRequest"}},["get","put","post","patch","delete","jsonp"].forEach(function(t){e[t]=function(e,n,o,a){return r.isFunction(n)&&(a=o,o=n,n=void 0),this(e,r.extend({method:t,data:n,success:o},a))}}),Object.defineProperty(t.prototype,"$http",{get:function(){return r.extend(e.bind(this),e)}}),e}},function(t,e,n){var r=n(2),o=n(5);t.exports=function(t,e){var n,a=new XMLHttpRequest;return r.isFunction(e.beforeSend)&&e.beforeSend.call(this,a,e),n=new o(function(n,o){a.open(e.method,t(e),!0),r.each(e.headers,function(t,e){a.setRequestHeader(e,t)}),a.onreadystatechange=function(){4===this.readyState&&(this.status>=200&&this.status<300?n(this):o(this))},a.send(e.data)}),r.extend(n,{abort:function(){a.abort()}}),n}},function(t,e){function n(t){this.state=a,this.value=void 0,this.deferred=[];var e=this;try{t(function(t){e.resolve(t)},function(t){e.reject(t)})}catch(n){e.reject(n)}}var r=0,o=1,a=2;n.reject=function(t){return new n(function(e,n){n(t)})},n.resolve=function(t){return new n(function(e,n){e(t)})},n.all=function(t){return new n(function(e,n){function r(n){return function(r){a[n]=r,o+=1,o===t.length&&e(a)}}var o=0,a=[];0===t.length&&e(a);for(var i=0;i<t.length;i+=1)t[i].then(r(i),n)})},n.race=function(t){return new n(function(e,n){for(var r=0;r<t.length;r+=1)t[r].then(e,n)})};var i=n.prototype;i.resolve=function(t){var e=this;if(e.state===a){if(t===e)throw new TypeError("Promise settled with itself.");var n=!1;try{var o=t&&t.then;if(null!==t&&"object"==typeof t&&"function"==typeof o)return void o.call(t,function(t){n||e.resolve(t),n=!0},function(t){n||e.reject(t),n=!0})}catch(i){return void(n||e.reject(i))}e.state=r,e.value=t,e.notify()}},i.reject=function(t){var e=this;if(e.state===a){if(t===e)throw new TypeError("Promise settled with itself.");e.state=o,e.value=t,e.notify()}},i.notify=function(){var t=this;c(function(){if(t.state!==a)for(;t.deferred.length;){var e=t.deferred.shift(),n=e[0],i=e[1],s=e[2],c=e[3];try{t.state===r?s("function"==typeof n?n.call(void 0,t.value):t.value):t.state===o&&("function"==typeof i?s(i.call(void 0,t.value)):c(t.value))}catch(u){c(u)}}})},i["catch"]=function(t){return this.then(void 0,t)},i.then=function(t,e){var r=this;return new n(function(n,o){r.deferred.push([t,e,n,o]),r.notify()})};var s=[],c=function(t){s.push(t),1===s.length&&c.async()};if(c.run=function(){for(;s.length;)s[0](),s.shift()},window.MutationObserver){var u=document.createElement("div"),f=new MutationObserver(c.run);f.observe(u,{attributes:!0}),c.async=function(){u.setAttribute("x",0)}}else c.async=function(){setTimeout(c.run)};t.exports=window.Promise||n},function(t,e,n){var r=n(2),o=n(5);t.exports=function(t,e){var n,a,i="_jsonp"+Math.random().toString(36).substr(2);return e.params[e.jsonp]=i,r.isFunction(e.beforeSend)&&e.beforeSend.call(this,{},e),new o(function(r,o){n=document.createElement("script"),n.src=t(e.url,e.params),n.type="text/javascript",n.async=!0,window[i]=function(t){a=t};var s=function(t){delete window[i],document.body.removeChild(n),"load"!==t.type||a||(t.type="error");var e=a?a:t.type,s="error"===t.type?404:200;(200===s?r:o)({responseText:e,status:s})};n.onload=s,n.onerror=s,document.body.appendChild(n)})}},function(t,e,n){var r=n(2);t.exports=function(t){function e(o,a,i){var s=this,c={};return i=r.extend({},e.actions,i),r.each(i,function(e,i){e=r.extend(!0,{url:o,params:a||{}},e),c[i]=function(){return(s.$http||t.http)(n(e,arguments))}}),c}function n(t,e){var n,o,a,i=r.extend({},t),s={};switch(e.length){case 4:a=e[3],o=e[2];case 3:case 2:if(!r.isFunction(e[1])){s=e[0],n=e[1],o=e[2];break}if(r.isFunction(e[0])){o=e[0],a=e[1];break}o=e[1],a=e[2];case 1:r.isFunction(e[0])?o=e[0]:/^(post|put|patch)$/i.test(i.method)?n=e[0]:s=e[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, data, success, error], got "+e.length+" arguments"}return i.url=t.url,i.data=n,i.params=r.extend({},t.params,s),o&&(i.success=o),a&&(i.error=a),i}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,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports.VueResource=e():t.VueResource=e()}(this,function(){return 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(7)(t)}window.Vue&&Vue.use(r),t.exports=r},function(t,e,n){var r=n(2),o=document.createElement("a");t.exports=function(t){function e(t,n){var o,i={},s={},c=t;return r.isPlainObject(c)||(c={url:t,params:n}),c=r.extend({},e.options,r.options("url",this,c)),t=c.url.replace(/:([a-z]\w*)/gi,function(t,e){return c.params[e]?(i[e]=!0,a(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"),r.each(c.params,function(t,e){i[e]||(s[e]=t)}),o=e.params(s),o&&(t+=(-1==t.indexOf("?")?"?":"&")+o),t}function n(t,e,o){var a,i=r.isArray(e),s=r.isPlainObject(e);r.each(e,function(e,c){a=r.isObject(e)||r.isArray(e),o&&(c=o+"["+(s||a?c:"")+"]"),!o&&i?t.add(e.name,e.value):a?n(t,e,c):t.add(c,e)})}function a(t){return i(t,!0).replace(/%26/gi,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+")}function i(t,e){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,e?"%20":"+")}return e.options={url:"",params:{}},e.params=function(t){var e=[];return e.add=function(t,e){r.isFunction(e)&&(e=e()),null===e&&(e=""),this.push(a(t)+"="+a(e))},n(e,t),e.join("&")},e.parse=function(t){return o.href=t,{href:o.href,protocol:o.protocol?o.protocol.replace(/:$/,""):"",port:o.port,host:o.host,hostname:o.hostname,pathname:"/"===o.pathname.charAt(0)?o.pathname:"/"+o.pathname,search:o.search?o.search.replace(/^\?/,""):"",hash:o.hash?o.hash.replace(/^#/,""):""}},Object.defineProperty(t.prototype,"$url",{get:function(){return r.extend(e.bind(this),e)}}),e}},function(t,e){function n(t,e,o){for(var a in e)o&&(r.isPlainObject(e[a])||r.isArray(e[a]))?(r.isPlainObject(e[a])&&!r.isPlainObject(t[a])&&(t[a]={}),r.isArray(e[a])&&!r.isArray(t[a])&&(t[a]=[]),n(t[a],e[a],o)):void 0!==e[a]&&(t[a]=e[a])}var r=e;r.isArray=Array.isArray,r.isFunction=function(t){return t&&"function"==typeof t},r.isObject=function(t){return null!==t&&"object"==typeof t},r.isPlainObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)},r.options=function(t,e,n){var o=e.$options||{};return r.extend({},o[t],n)},r.each=function(t,e){var n,o;if("number"==typeof t.length)for(n=0;n<t.length;n++)e.call(t[n],t[n],n);else if(r.isObject(t))for(o in t)t.hasOwnProperty(o)&&e.call(t[o],t[o],o);return t},r.extend=function(t){var e,r=[],o=r.slice.call(arguments,1);return"boolean"==typeof t&&(e=t,t=o.shift()),o.forEach(function(r){n(t,r,e)}),t}},function(t,e,n){var r=n(2),o=n(4),a=n(6),i=n(5);t.exports=function(t){function e(t,i){var u,f=this;return i=i||{},r.isPlainObject(t)&&(i=t,t=""),i=r.extend(!0,{url:t},e.options,r.options("http",f,i)),null===i.crossOrigin&&(i.crossOrigin=s(i.url)),i.headers=r.extend({},e.headers.common,i.crossOrigin?{}:e.headers.custom,e.headers[i.method.toLowerCase()],i.headers),r.isPlainObject(i.data)&&/^(get|jsonp)$/i.test(i.method)&&(r.extend(i.params,i.data),delete i.data),i.emulateHTTP&&!i.crossOrigin&&/^(put|patch|delete)$/i.test(i.method)&&(i.headers["X-HTTP-Method-Override"]=i.method,i.method="post"),i.emulateJSON&&r.isPlainObject(i.data)&&(i.headers["Content-Type"]="application/x-www-form-urlencoded",i.data=c.params(i.data)),r.isObject(i.data)&&/FormData/i.test(i.data.toString())&&delete i.headers["Content-Type"],r.isPlainObject(i.data)&&(i.data=JSON.stringify(i.data)),u=("jsonp"==i.method.toLowerCase()?a:o).call(f,f.$url||c,i).then(n,n),u.success=function(t){return u.then(function(e){t.call(f,e.data,e.status,e)}),u},u.error=function(t){return u.then(void 0,function(e){t.call(f,e.data,e.status,e)}),u},u.always=function(t){var e=function(e){t.call(f,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 n(t){try{t.data=JSON.parse(t.responseText)}catch(e){t.data=t.responseText}return t.ok?t:i.reject(t)}function s(t){var e=c.parse(t);return e.protocol!==u.protocol||e.host!==u.host}var c=t.url,u=c.parse(location.href),f={"Content-Type":"application/json;charset=utf-8"};return e.options={method:"get",params:{},data:"",jsonp:"callback",beforeSend:null,crossOrigin:null,emulateHTTP:!1,emulateJSON:!1},e.headers={put:f,post:f,patch:f,"delete":f,common:{Accept:"application/json, text/plain, */*"},custom:{"X-Requested-With":"XMLHttpRequest"}},["get","put","post","patch","delete","jsonp"].forEach(function(t){e[t]=function(e,n,o,a){return r.isFunction(n)&&(a=o,o=n,n=void 0),this(e,r.extend({method:t,data:n,success:o},a))}}),Object.defineProperty(t.prototype,"$http",{get:function(){return r.extend(e.bind(this),e)}}),e}},function(t,e,n){var r=n(2),o=n(5);t.exports=function(t,e){var n,a=new XMLHttpRequest;return r.isFunction(e.beforeSend)&&e.beforeSend.call(this,a,e),n=new o(function(n,o){a.open(e.method,t(e),!0),r.each(e.headers,function(t,e){a.setRequestHeader(e,t)}),a.onreadystatechange=function(){4===a.readyState&&(a.ok=a.status>=200&&a.status<300,(a.ok?n:o)(a))},a.send(e.data)})}},function(t,e){function n(t){this.state=a,this.value=void 0,this.deferred=[];var e=this;try{t(function(t){e.resolve(t)},function(t){e.reject(t)})}catch(n){e.reject(n)}}var r=0,o=1,a=2;n.reject=function(t){return new n(function(e,n){n(t)})},n.resolve=function(t){return new n(function(e,n){e(t)})},n.all=function(t){return new n(function(e,n){function r(n){return function(r){a[n]=r,o+=1,o===t.length&&e(a)}}var o=0,a=[];0===t.length&&e(a);for(var i=0;i<t.length;i+=1)t[i].then(r(i),n)})},n.race=function(t){return new n(function(e,n){for(var r=0;r<t.length;r+=1)t[r].then(e,n)})};var i=n.prototype;i.resolve=function(t){var e=this;if(e.state===a){if(t===e)throw new TypeError("Promise settled with itself.");var n=!1;try{var o=t&&t.then;if(null!==t&&"object"==typeof t&&"function"==typeof o)return void o.call(t,function(t){n||e.resolve(t),n=!0},function(t){n||e.reject(t),n=!0})}catch(i){return void(n||e.reject(i))}e.state=r,e.value=t,e.notify()}},i.reject=function(t){var e=this;if(e.state===a){if(t===e)throw new TypeError("Promise settled with itself.");e.state=o,e.value=t,e.notify()}},i.notify=function(){var t=this;c(function(){if(t.state!==a)for(;t.deferred.length;){var e=t.deferred.shift(),n=e[0],i=e[1],s=e[2],c=e[3];try{t.state===r?s("function"==typeof n?n.call(void 0,t.value):t.value):t.state===o&&("function"==typeof i?s(i.call(void 0,t.value)):c(t.value))}catch(u){c(u)}}})},i["catch"]=function(t){return this.then(void 0,t)},i.then=function(t,e){var r=this;return new n(function(n,o){r.deferred.push([t,e,n,o]),r.notify()})};var s=[],c=function(t){s.push(t),1===s.length&&c.async()};if(c.run=function(){for(;s.length;)s[0](),s.shift()},window.MutationObserver){var u=document.createElement("div"),f=new MutationObserver(c.run);f.observe(u,{attributes:!0}),c.async=function(){u.setAttribute("x",0)}}else c.async=function(){setTimeout(c.run)};t.exports=window.Promise||n},function(t,e,n){var r=n(2),o=n(5);t.exports=function(t,e){var n,a,i="_jsonp"+Math.random().toString(36).substr(2),s={};return e.params[e.jsonp]=i,r.isFunction(e.beforeSend)&&e.beforeSend.call(this,{},e),new o(function(r,o){n=document.createElement("script"),n.src=t(e.url,e.params),n.type="text/javascript",n.async=!0,window[i]=function(t){a=t};var c=function(t){delete window[i],document.body.removeChild(n),"load"!==t.type||a||(t.type="error"),s.ok="error"!==t.type,s.status=s.ok?200:404,s.responseText=a?a:t.type,(s.ok?r:o)(s)};n.onload=c,n.onerror=c,document.body.appendChild(n)})}},function(t,e,n){var r=n(2);t.exports=function(t){function e(o,a,i){var s=this,c={};return i=r.extend({},e.actions,i),r.each(i,function(e,i){e=r.extend(!0,{url:o,params:a||{}},e),c[i]=function(){return(s.$http||t.http)(n(e,arguments))}}),c}function n(t,e){var n,o,a,i=r.extend({},t),s={};switch(e.length){case 4:a=e[3],o=e[2];case 3:case 2:if(!r.isFunction(e[1])){s=e[0],n=e[1],o=e[2];break}if(r.isFunction(e[0])){o=e[0],a=e[1];break}o=e[1],a=e[2];case 1:r.isFunction(e[0])?o=e[0]:/^(post|put|patch)$/i.test(i.method)?n=e[0]:s=e[0];break;case 0:break;default:throw"Expected up to 4 arguments [params, data, success, error], got "+e.length+" arguments"}return i.url=t.url,i.data=n,i.params=r.extend({},t.params,s),o&&(i.success=o),a&&(i.error=a),i}return e.actions={get:{method:"get"},save:{method:"post"},query:{method:"get"},update:{method:"put"},remove:{method:"delete"},"delete":{method:"delete"}},Object.defineProperty(t.prototype,"$resource",{get:function(){return e.bind(this)}}),e}}])}); |
{ | ||
"name": "vue-resource", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"description": "A web request service for Vue.js", | ||
@@ -25,4 +25,4 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"webpack": "^1.10.1" | ||
"webpack": "^1.10.5" | ||
} | ||
} |
@@ -7,2 +7,14 @@ # vue-resource | ||
## Setup | ||
### Browserify | ||
Add `vue` and `vue-resource` to your `package.json`, then `npm install`, then add these lines in your code: | ||
```javascript | ||
var Vue = require('vue'); | ||
Vue.use(require('vue-resource')); | ||
``` | ||
## HTTP | ||
@@ -71,2 +83,3 @@ | ||
query: {method: 'GET'}, | ||
update: {method: 'PUT'}, | ||
remove: {method: 'DELETE'}, | ||
@@ -73,0 +86,0 @@ delete: {method: 'DELETE'} |
@@ -8,3 +8,3 @@ /** | ||
var jsonp = require('./lib/jsonp'); | ||
var jsonType = {'Content-Type': 'application/json;charset=utf-8'}; | ||
var Promise = require('./lib/promise'); | ||
@@ -15,2 +15,3 @@ module.exports = function (Vue) { | ||
var originUrl = Url.parse(location.href); | ||
var jsonType = {'Content-Type': 'application/json;charset=utf-8'}; | ||
@@ -66,6 +67,4 @@ function Http(url, options) { | ||
promise = (options.method.toLowerCase() == 'jsonp' ? jsonp : xhr).call(self, self.$url || Url, options); | ||
promise = (options.method.toLowerCase() == 'jsonp' ? jsonp : xhr).call(self, self.$url || Url, options).then(transformResponse, transformResponse); | ||
promise.then(transformResponse, transformResponse); | ||
promise.success = function (fn) { | ||
@@ -75,3 +74,3 @@ | ||
fn.call(self, response.data, response.status, response); | ||
}, function () {}); | ||
}); | ||
@@ -83,3 +82,3 @@ return promise; | ||
promise.catch(function (response) { | ||
promise.then(undefined, function (response) { | ||
fn.call(self, response.data, response.status, response); | ||
@@ -121,2 +120,3 @@ }); | ||
return response.ok ? response : Promise.reject(response); | ||
} | ||
@@ -123,0 +123,0 @@ |
@@ -10,3 +10,3 @@ /** | ||
var callback = '_jsonp' + Math.random().toString(36).substr(2), script, body; | ||
var callback = '_jsonp' + Math.random().toString(36).substr(2), response = {}, script, body; | ||
@@ -39,5 +39,7 @@ options.params[options.jsonp] = callback; | ||
var text = body ? body : event.type, status = event.type === 'error' ? 404 : 200; | ||
response.ok = event.type !== 'error'; | ||
response.status = response.ok ? 200 : 404; | ||
response.responseText = body ? body : event.type; | ||
(status === 200 ? resolve : reject)({responseText: text, status: status}); | ||
(response.ok ? resolve : reject)(response); | ||
}; | ||
@@ -44,0 +46,0 @@ |
@@ -26,9 +26,7 @@ /** | ||
if (this.readyState === 4) { | ||
if (request.readyState === 4) { | ||
if (this.status >= 200 && this.status < 300) { | ||
resolve(this); | ||
} else { | ||
reject(this); | ||
} | ||
request.ok = request.status >= 200 && request.status < 300; | ||
(request.ok ? resolve : reject)(request); | ||
} | ||
@@ -40,11 +38,3 @@ }; | ||
_.extend(promise, { | ||
abort: function () { | ||
request.abort(); | ||
} | ||
}); | ||
return promise; | ||
}; |
@@ -107,2 +107,3 @@ /** | ||
query: {method: 'get'}, | ||
update: {method: 'put'}, | ||
remove: {method: 'delete'}, | ||
@@ -109,0 +110,0 @@ delete: {method: 'delete'} |
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
55744
118
1334