vue-resource
Advanced tools
Comparing version 0.1.11 to 0.1.12
/** | ||
* vue-resource v0.1.11 | ||
* vue-resource v0.1.12 | ||
* https://github.com/vuejs/vue-resource | ||
@@ -353,3 +353,3 @@ * Released under the MIT License. | ||
var self = this, promise; | ||
var promise; | ||
@@ -364,3 +364,3 @@ options = options || {}; | ||
options = _.extend(true, {url: url}, | ||
Http.options, _.options('http', self, options) | ||
Http.options, _.options('http', this, options) | ||
); | ||
@@ -372,6 +372,6 @@ | ||
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 | ||
@@ -403,11 +403,24 @@ ); | ||
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; | ||
}; | ||
@@ -417,7 +430,6 @@ | ||
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; | ||
}; | ||
@@ -428,18 +440,8 @@ | ||
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; | ||
@@ -470,2 +472,3 @@ } | ||
data: '', | ||
xhr: null, | ||
jsonp: 'callback', | ||
@@ -528,2 +531,6 @@ beforeSend: null, | ||
if (_.isPlainObject(options.xhr)) { | ||
_.extend(request, options.xhr); | ||
} | ||
if (_.isFunction(options.beforeSend)) { | ||
@@ -530,0 +537,0 @@ options.beforeSend.call(this, request, options); |
/** | ||
* vue-resource v0.1.11 | ||
* vue-resource v0.1.12 | ||
* 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=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}}])}); | ||
!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 f;return i=i||{},r.isPlainObject(t)&&(i=t,t=""),i=r.extend(!0,{url:t},e.options,r.options("http",this,i)),null===i.crossOrigin&&(i.crossOrigin=c(i.url)),i.method=i.method.toLowerCase(),i.headers=r.extend({},e.headers.common,i.crossOrigin?{}:e.headers.custom,e.headers[i.method],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=u.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)),f=("jsonp"==i.method?a:o).call(this,this.$url||u,i),f=n(f.then(s,s),this),i.success&&(f=f.success(i.success)),i.error&&(f=f.error(i.error)),f}function n(t,e){return t.success=function(r){return n(t.then(function(t){r.call(e,t.data,t.status,t)}),e)},t.error=function(r){return n(t.then(void 0,function(t){r.call(e,t.data,t.status,t)}),e)},t.always=function(r){var o=function(t){r.call(e,t.data,t.status,t)};return n(t.then(o,o),e)},t}function s(t){try{t.data=JSON.parse(t.responseText)}catch(e){t.data=t.responseText}return t.ok?t:i.reject(t)}function c(t){var e=u.parse(t);return e.protocol!==f.protocol||e.host!==f.host}var u=t.url,f=u.parse(location.href),p={"Content-Type":"application/json;charset=utf-8"};return e.options={method:"get",params:{},data:"",xhr:null,jsonp:"callback",beforeSend:null,crossOrigin:null,emulateHTTP:!1,emulateJSON:!1},e.headers={put:p,post:p,patch:p,"delete":p,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.isPlainObject(e.xhr)&&r.extend(a,e.xhr),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.11", | ||
"version": "0.1.12", | ||
"description": "A web request service for Vue.js", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -25,8 +25,8 @@ # vue-resource | ||
* `Vue.http.get(url, [data], [success], [options])` | ||
* `Vue.http.post(url, [data], [success], [options])` | ||
* `Vue.http.put(url, [data], [success], [options])` | ||
* `Vue.http.patch(url, [data], [success], [options])` | ||
* `Vue.http.delete(url, [data], [success], [options])` | ||
* `Vue.http.jsonp(url, [data], [success], [options])` | ||
* `get(url, [data], [success], [options])` | ||
* `post(url, [data], [success], [options])` | ||
* `put(url, [data], [success], [options])` | ||
* `patch(url, [data], [success], [options])` | ||
* `delete(url, [data], [success], [options])` | ||
* `jsonp(url, [data], [success], [options])` | ||
@@ -45,5 +45,6 @@ ### Options | ||
* **emulateJSON** - `boolean` - Send request data as `application/x-www-form-urlencoded` content type | ||
* **xhr** - `Object` - Parameters object to be set on the native XHR object | ||
* **jsonp** - `string` - Callback function name in a JSONP request | ||
### Usage | ||
### Example | ||
@@ -76,3 +77,3 @@ ```javascript | ||
* `Vue.resource(url, [params], [actions])` | ||
* `resource(url, [params], [actions])` | ||
@@ -90,3 +91,3 @@ ### Default Actions | ||
### Usage | ||
### Example | ||
```javascript | ||
@@ -93,0 +94,0 @@ new Vue({ |
@@ -18,3 +18,3 @@ /** | ||
var self = this, promise; | ||
var promise; | ||
@@ -29,3 +29,3 @@ options = options || {}; | ||
options = _.extend(true, {url: url}, | ||
Http.options, _.options('http', self, options) | ||
Http.options, _.options('http', this, options) | ||
); | ||
@@ -37,6 +37,6 @@ | ||
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 | ||
@@ -68,11 +68,24 @@ ); | ||
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; | ||
}; | ||
@@ -82,7 +95,6 @@ | ||
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; | ||
}; | ||
@@ -93,18 +105,8 @@ | ||
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; | ||
@@ -135,2 +137,3 @@ } | ||
data: '', | ||
xhr: null, | ||
jsonp: 'callback', | ||
@@ -137,0 +140,0 @@ beforeSend: null, |
@@ -12,2 +12,6 @@ /** | ||
if (_.isPlainObject(options.xhr)) { | ||
_.extend(request, options.xhr); | ||
} | ||
if (_.isFunction(options.beforeSend)) { | ||
@@ -14,0 +18,0 @@ options.beforeSend.call(this, request, options); |
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
56426
1344
119