vendor/assets/javascripts/vue-resource.js in vuejs-1.0.37 vs vendor/assets/javascripts/vue-resource.js in vuejs-1.0.38
- old
+ new
@@ -1,24 +1,24 @@
/*!
- * vue-resource v1.0.3
- * https://github.com/vuejs/vue-resource
+ * vue-resource v1.2.0
+ * https://github.com/pagekit/vue-resource
* Released under the MIT License.
*/
(function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
- typeof define === 'function' && define.amd ? define(factory) :
- (global.VueResource = factory());
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+ typeof define === 'function' && define.amd ? define(factory) :
+ (global.VueResource = factory());
}(this, (function () { 'use strict';
/**
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis)
*/
var RESOLVED = 0;
var REJECTED = 1;
-var PENDING = 2;
+var PENDING = 2;
function Promise$1(executor) {
this.state = PENDING;
this.value = undefined;
@@ -49,12 +49,11 @@
});
};
Promise$1.all = function all(iterable) {
return new Promise$1(function (resolve, reject) {
- var count = 0,
- result = [];
+ var count = 0, result = [];
if (iterable.length === 0) {
resolve(result);
}
@@ -102,10 +101,11 @@
then.call(x, function (x) {
if (!called) {
promise.resolve(x);
}
called = true;
+
}, function (r) {
if (!called) {
promise.reject(r);
}
called = true;
@@ -251,29 +251,37 @@
};
p.finally = function (callback) {
return this.then(function (value) {
- callback.call(this);
- return value;
- }, function (reason) {
- callback.call(this);
- return Promise.reject(reason);
- });
+ callback.call(this);
+ return value;
+ }, function (reason) {
+ callback.call(this);
+ return Promise.reject(reason);
+ }
+ );
};
/**
* Utility functions.
*/
-var debug = false;var util = {};var slice = [].slice;
+var debug = false;
+var util = {};
+var ref = {};
+var hasOwnProperty = ref.hasOwnProperty;
+var ref$1 = [];
+var slice = ref$1.slice;
-function Util (Vue) {
+var inBrowser = typeof window !== 'undefined';
+
+var Util = function (Vue) {
util = Vue.util;
debug = Vue.config.debug || !Vue.config.silent;
-}
+};
function warn(msg) {
if (typeof console !== 'undefined' && debug) {
console.warn('[VueResource warn]: ' + msg);
}
@@ -288,11 +296,11 @@
function nextTick(cb, ctx) {
return util.nextTick(cb, ctx);
}
function trim(str) {
- return str.replace(/^\s*|\s*$/g, '');
+ return str ? str.replace(/^\s*|\s*$/g, '') : '';
}
function toLower(str) {
return str ? str.toLowerCase() : '';
}
@@ -305,14 +313,12 @@
function isString(val) {
return typeof val === 'string';
}
-function isBoolean(val) {
- return val === true || val === false;
-}
+
function isFunction(val) {
return typeof val === 'function';
}
function isObject(obj) {
@@ -348,24 +354,24 @@
if (isFunction(opts)) {
opts = opts.call(obj);
}
- return merge(fn.bind({ $vm: obj, $options: opts }), fn, { $options: opts });
+ return merge(fn.bind({$vm: obj, $options: opts}), fn, {$options: opts});
}
function each(obj, iterator) {
var i, key;
- if (obj && typeof obj.length == 'number') {
+ if (isArray(obj)) {
for (i = 0; i < obj.length; i++) {
iterator.call(obj[i], obj[i], i);
}
} else if (isObject(obj)) {
for (key in obj) {
- if (obj.hasOwnProperty(key)) {
+ if (hasOwnProperty.call(obj, key)) {
iterator.call(obj[key], obj[key], key);
}
}
}
@@ -394,10 +400,11 @@
for (var key in source) {
if (target[key] === undefined) {
target[key] = source[key];
}
}
+
});
return target;
}
@@ -430,32 +437,30 @@
/**
* Root Prefix Transform.
*/
-function root (options, next) {
+var root = function (options$$1, next) {
- var url = next(options);
+ var url = next(options$$1);
- if (isString(options.root) && !url.match(/^(https?:)?\//)) {
- url = options.root + '/' + url;
+ if (isString(options$$1.root) && !url.match(/^(https?:)?\//)) {
+ url = options$$1.root + '/' + url;
}
return url;
-}
+};
/**
* Query Parameter Transform.
*/
-function query (options, next) {
+var query = function (options$$1, next) {
- var urlParams = Object.keys(Url.options.params),
- query = {},
- url = next(options);
+ var urlParams = Object.keys(Url.options.params), query = {}, url = next(options$$1);
- each(options.params, function (value, key) {
+ each(options$$1.params, function (value, key) {
if (urlParams.indexOf(key) === -1) {
query[key] = value;
}
});
@@ -464,41 +469,38 @@
if (query) {
url += (url.indexOf('?') == -1 ? '?' : '&') + query;
}
return url;
-}
+};
/**
* URL Template v2.0.6 (https://github.com/bramstein/url-template)
*/
function expand(url, params, variables) {
- var tmpl = parse(url),
- expanded = tmpl.expand(params);
+ var tmpl = parse(url), expanded = tmpl.expand(params);
if (variables) {
variables.push.apply(variables, tmpl.vars);
}
return expanded;
}
function parse(template) {
- var operators = ['+', '#', '.', '/', ';', '?', '&'],
- variables = [];
+ var operators = ['+', '#', '.', '/', ';', '?', '&'], variables = [];
return {
vars: variables,
- expand: function (context) {
+ expand: function expand(context) {
return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) {
if (expression) {
- var operator = null,
- values = [];
+ var operator = null, values = [];
if (operators.indexOf(expression.charAt(0)) !== -1) {
operator = expression.charAt(0);
expression = expression.substr(1);
}
@@ -521,22 +523,22 @@
return (values.length !== 0 ? operator : '') + values.join(separator);
} else {
return values.join(',');
}
+
} else {
return encodeReserved(literal);
}
});
}
};
}
function getValues(context, operator, key, modifier) {
- var value = context[key],
- result = [];
+ var value = context[key], result = [];
if (isDefined(value) && value !== '') {
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
value = value.toString();
@@ -602,11 +604,11 @@
return operator === ';' || operator === '&' || operator === '?';
}
function encodeValue(operator, value, key) {
- value = operator === '+' || operator === '#' ? encodeReserved(value) : encodeURIComponent(value);
+ value = (operator === '+' || operator === '#') ? encodeReserved(value) : encodeURIComponent(value);
if (key) {
return encodeURIComponent(key) + '=' + value;
} else {
return value;
@@ -624,46 +626,40 @@
/**
* URL Template (RFC 6570) Transform.
*/
-function template (options) {
+var template = function (options) {
- var variables = [],
- url = expand(options.url, options.params, variables);
+ var variables = [], url = expand(options.url, options.params, variables);
variables.forEach(function (key) {
delete options.params[key];
});
return url;
-}
+};
/**
* Service for URL templating.
*/
-var ie = document.documentMode;
-var el = document.createElement('a');
-
function Url(url, params) {
- var self = this || {},
- options = url,
- transform;
+ var self = this || {}, options$$1 = url, transform;
if (isString(url)) {
- options = { url: url, params: params };
+ options$$1 = {url: url, params: params};
}
- options = merge({}, Url.options, self.$options, options);
+ options$$1 = merge({}, Url.options, self.$options, options$$1);
Url.transforms.forEach(function (handler) {
transform = factory(handler, transform, self.$vm);
});
- return transform(options);
+ return transform(options$$1);
}
/**
* Url options.
*/
@@ -686,12 +682,11 @@
* @param {Object} obj
*/
Url.params = function (obj) {
- var params = [],
- escape = encodeURIComponent;
+ var params = [], escape = encodeURIComponent;
params.add = function (key, value) {
if (isFunction(value)) {
value = value();
@@ -715,11 +710,13 @@
* @param {String} url
*/
Url.parse = function (url) {
- if (ie) {
+ var el = document.createElement('a');
+
+ if (document.documentMode) {
el.href = url;
url = el.href;
}
el.href = url;
@@ -735,20 +732,18 @@
hash: el.hash ? el.hash.replace(/^#/, '') : ''
};
};
function factory(handler, next, vm) {
- return function (options) {
- return handler.call(vm, options, next);
+ return function (options$$1) {
+ return handler.call(vm, options$$1, next);
};
}
function serialize(params, obj, scope) {
- var array = isArray(obj),
- plain = isPlainObject(obj),
- hash;
+ var array = isArray(obj), plain = isPlainObject(obj), hash;
each(obj, function (value, key) {
hash = isObject(value) || isArray(value);
@@ -768,84 +763,82 @@
/**
* XDomain client (Internet Explorer).
*/
-function xdrClient (request) {
+var xdrClient = function (request) {
return new PromiseObj(function (resolve) {
- var xdr = new XDomainRequest(),
- handler = function (_ref) {
- var type = _ref.type;
+ var xdr = new XDomainRequest(), handler = function (ref) {
+ var type = ref.type;
var status = 0;
if (type === 'load') {
status = 200;
} else if (type === 'error') {
status = 500;
}
- resolve(request.respondWith(xdr.responseText, { status: status }));
+ resolve(request.respondWith(xdr.responseText, {status: status}));
};
- request.abort = function () {
- return xdr.abort();
- };
+ request.abort = function () { return xdr.abort(); };
xdr.open(request.method, request.getUrl());
- xdr.timeout = 0;
+
+ if (request.timeout) {
+ xdr.timeout = request.timeout;
+ }
+
xdr.onload = handler;
+ xdr.onabort = handler;
xdr.onerror = handler;
xdr.ontimeout = handler;
xdr.onprogress = function () {};
xdr.send(request.getBody());
});
-}
+};
/**
* CORS Interceptor.
*/
-var ORIGIN_URL = Url.parse(location.href);
-var SUPPORTS_CORS = 'withCredentials' in new XMLHttpRequest();
+var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest();
-function cors (request, next) {
+var cors = function (request, next) {
- if (!isBoolean(request.crossOrigin) && crossOrigin(request)) {
- request.crossOrigin = true;
- }
+ if (inBrowser) {
- if (request.crossOrigin) {
+ var orgUrl = Url.parse(location.href);
+ var reqUrl = Url.parse(request.getUrl());
- if (!SUPPORTS_CORS) {
- request.client = xdrClient;
- }
+ if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) {
- delete request.emulateHTTP;
+ request.crossOrigin = true;
+ request.emulateHTTP = false;
+
+ if (!SUPPORTS_CORS) {
+ request.client = xdrClient;
+ }
+ }
}
next();
-}
+};
-function crossOrigin(request) {
-
- var requestUrl = Url.parse(Url(request));
-
- return requestUrl.protocol !== ORIGIN_URL.protocol || requestUrl.host !== ORIGIN_URL.host;
-}
-
/**
* Body Interceptor.
*/
-function body (request, next) {
+var body = function (request, next) {
if (isFormData(request.body)) {
request.headers.delete('Content-Type');
+
} else if (isObject(request.body) || isArray(request.body)) {
if (request.emulateJSON) {
request.body = Url.params(request.body);
request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
@@ -855,199 +848,191 @@
}
next(function (response) {
Object.defineProperty(response, 'data', {
- get: function () {
+
+ get: function get() {
return this.body;
},
- set: function (body) {
+
+ set: function set(body) {
this.body = body;
}
+
});
return response.bodyText ? when(response.text(), function (text) {
- var type = response.headers.get('Content-Type');
+ var type = response.headers.get('Content-Type') || '';
- if (isString(type) && type.indexOf('application/json') === 0) {
+ if (type.indexOf('application/json') === 0 || isJson(text)) {
try {
response.body = JSON.parse(text);
} catch (e) {
response.body = null;
}
+
} else {
response.body = text;
}
return response;
+
}) : response;
+
});
+};
+
+function isJson(str) {
+
+ var start = str.match(/^\[|^\{(?!\{)/), end = {'[': /]$/, '{': /}$/};
+
+ return start && end[start[0]].test(str);
}
/**
- * JSONP client.
+ * JSONP client (Browser).
*/
-function jsonpClient (request) {
+var jsonpClient = function (request) {
return new PromiseObj(function (resolve) {
- var name = request.jsonp || 'callback',
- callback = '_jsonp' + Math.random().toString(36).substr(2),
- body = null,
- handler,
- script;
+ var name = request.jsonp || 'callback', callback = request.jsonpCallback || '_jsonp' + Math.random().toString(36).substr(2), body = null, handler, script;
- handler = function (_ref) {
- var type = _ref.type;
+ handler = function (ref) {
+ var type = ref.type;
var status = 0;
if (type === 'load' && body !== null) {
status = 200;
} else if (type === 'error') {
status = 500;
}
- resolve(request.respondWith(body, { status: status }));
+ if (status && window[callback]) {
+ delete window[callback];
+ document.body.removeChild(script);
+ }
- delete window[callback];
- document.body.removeChild(script);
+ resolve(request.respondWith(body, {status: status}));
};
- request.params[name] = callback;
-
window[callback] = function (result) {
body = JSON.stringify(result);
};
+ request.abort = function () {
+ handler({type: 'abort'});
+ };
+
+ request.params[name] = callback;
+
+ if (request.timeout) {
+ setTimeout(request.abort, request.timeout);
+ }
+
script = document.createElement('script');
script.src = request.getUrl();
script.type = 'text/javascript';
script.async = true;
script.onload = handler;
script.onerror = handler;
document.body.appendChild(script);
});
-}
+};
/**
* JSONP Interceptor.
*/
-function jsonp (request, next) {
+var jsonp = function (request, next) {
if (request.method == 'JSONP') {
request.client = jsonpClient;
}
- next(function (response) {
+ next();
+};
- if (request.method == 'JSONP') {
-
- return when(response.json(), function (json) {
-
- response.body = json;
-
- return response;
- });
- }
- });
-}
-
/**
* Before Interceptor.
*/
-function before (request, next) {
+var before = function (request, next) {
if (isFunction(request.before)) {
request.before.call(this, request);
}
next();
-}
+};
/**
* HTTP method override Interceptor.
*/
-function method (request, next) {
+var method = function (request, next) {
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) {
request.headers.set('X-HTTP-Method-Override', request.method);
request.method = 'POST';
}
next();
-}
+};
/**
* Header Interceptor.
*/
-function header (request, next) {
+var header = function (request, next) {
- var headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, Http.headers[toLower(request.method)]);
+ var headers = assign({}, Http.headers.common,
+ !request.crossOrigin ? Http.headers.custom : {},
+ Http.headers[toLower(request.method)]
+ );
each(headers, function (value, name) {
if (!request.headers.has(name)) {
request.headers.set(name, value);
}
});
next();
-}
+};
/**
- * Timeout Interceptor.
+ * XMLHttp client (Browser).
*/
-function timeout (request, next) {
+var SUPPORTS_BLOB = typeof Blob !== 'undefined' && typeof FileReader !== 'undefined';
- var timeout;
-
- if (request.timeout) {
- timeout = setTimeout(function () {
- request.abort();
- }, request.timeout);
- }
-
- next(function (response) {
-
- clearTimeout(timeout);
- });
-}
-
-/**
- * XMLHttp client.
- */
-
-function xhrClient (request) {
+var xhrClient = function (request) {
return new PromiseObj(function (resolve) {
- var xhr = new XMLHttpRequest(),
- handler = function (event) {
+ var xhr = new XMLHttpRequest(), handler = function (event) {
- var response = request.respondWith('response' in xhr ? xhr.response : xhr.responseText, {
- status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug
- statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText)
- });
+ var response = request.respondWith(
+ 'response' in xhr ? xhr.response : xhr.responseText, {
+ status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug
+ statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText)
+ }
+ );
each(trim(xhr.getAllResponseHeaders()).split('\n'), function (row) {
response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1));
});
resolve(response);
};
- request.abort = function () {
- return xhr.abort();
- };
+ request.abort = function () { return xhr.abort(); };
if (request.progress) {
if (request.method === 'GET') {
xhr.addEventListener('progress', request.progress);
} else if (/^(POST|PUT)$/i.test(request.method)) {
@@ -1055,38 +1040,82 @@
}
}
xhr.open(request.method, request.getUrl(), true);
- if ('responseType' in xhr) {
- xhr.responseType = 'blob';
+ if (request.timeout) {
+ xhr.timeout = request.timeout;
}
if (request.credentials === true) {
xhr.withCredentials = true;
}
+ if (!request.crossOrigin) {
+ request.headers.set('X-Requested-With', 'XMLHttpRequest');
+ }
+
+ if ('responseType' in xhr && SUPPORTS_BLOB) {
+ xhr.responseType = 'blob';
+ }
+
request.headers.forEach(function (value, name) {
xhr.setRequestHeader(name, value);
});
- xhr.timeout = 0;
xhr.onload = handler;
+ xhr.onabort = handler;
xhr.onerror = handler;
+ xhr.ontimeout = handler;
xhr.send(request.getBody());
});
-}
+};
/**
+ * Http client (Node).
+ */
+
+var nodeClient = function (request) {
+
+ var client = require('got');
+
+ return new PromiseObj(function (resolve) {
+
+ var url = request.getUrl();
+ var body = request.getBody();
+ var method = request.method;
+ var headers = {}, handler;
+
+ request.headers.forEach(function (value, name) {
+ headers[name] = value;
+ });
+
+ client(url, {body: body, method: method, headers: headers}).then(handler = function (resp) {
+
+ var response = request.respondWith(resp.body, {
+ status: resp.statusCode,
+ statusText: trim(resp.statusMessage)
+ }
+ );
+
+ each(resp.headers, function (value, name) {
+ response.headers.set(name, value);
+ });
+
+ resolve(response);
+
+ }, function (error$$1) { return handler(error$$1.response); });
+ });
+};
+
+/**
* Base client.
*/
-function Client (context) {
+var Client = function (context) {
- var reqHandlers = [sendRequest],
- resHandlers = [],
- handler;
+ var reqHandlers = [sendRequest], resHandlers = [], handler;
if (!isObject(context)) {
context = null;
}
@@ -1098,20 +1127,21 @@
handler = reqHandlers.pop();
if (isFunction(handler)) {
handler.call(context, request, next);
} else {
- warn('Invalid interceptor of type ' + typeof handler + ', must be a function');
+ warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function"));
next();
}
}
function next(response) {
if (isFunction(response)) {
resHandlers.unshift(response);
+
} else if (isObject(response)) {
resHandlers.forEach(function (handler) {
response = when(response, function (response) {
return handler.call(context, response) || response;
@@ -1125,98 +1155,87 @@
exec();
}
exec();
+
}, context);
}
Client.use = function (handler) {
reqHandlers.push(handler);
};
return Client;
-}
+};
function sendRequest(request, resolve) {
- var client = request.client || xhrClient;
+ var client = request.client || (inBrowser ? xhrClient : nodeClient);
resolve(client(request));
}
-var classCallCheck = function (instance, Constructor) {
- if (!(instance instanceof Constructor)) {
- throw new TypeError("Cannot call a class as a function");
- }
-};
-
/**
* HTTP Headers.
*/
-var Headers = function () {
- function Headers(headers) {
- var _this = this;
+var Headers = function Headers(headers) {
+ var this$1 = this;
- classCallCheck(this, Headers);
+ this.map = {};
- this.map = {};
+ each(headers, function (value, name) { return this$1.append(name, value); });
+};
- each(headers, function (value, name) {
- return _this.append(name, value);
- });
- }
+Headers.prototype.has = function has (name) {
+ return getName(this.map, name) !== null;
+};
- Headers.prototype.has = function has(name) {
- return getName(this.map, name) !== null;
- };
+Headers.prototype.get = function get (name) {
- Headers.prototype.get = function get(name) {
+ var list = this.map[getName(this.map, name)];
- var list = this.map[getName(this.map, name)];
+ return list ? list[0] : null;
+};
- return list ? list[0] : null;
- };
+Headers.prototype.getAll = function getAll (name) {
+ return this.map[getName(this.map, name)] || [];
+};
- Headers.prototype.getAll = function getAll(name) {
- return this.map[getName(this.map, name)] || [];
- };
+Headers.prototype.set = function set (name, value) {
+ this.map[normalizeName(getName(this.map, name) || name)] = [trim(value)];
+};
- Headers.prototype.set = function set(name, value) {
- this.map[normalizeName(getName(this.map, name) || name)] = [trim(value)];
- };
+Headers.prototype.append = function append (name, value){
- Headers.prototype.append = function append(name, value) {
+ var list = this.getAll(name);
- var list = this.getAll(name);
+ if (list.length) {
+ list.push(trim(value));
+ } else {
+ this.set(name, value);
+ }
+};
- if (list.length) {
- list.push(trim(value));
- } else {
- this.set(name, value);
- }
- };
+Headers.prototype.delete = function delete$1 (name){
+ delete this.map[getName(this.map, name)];
+};
- Headers.prototype.delete = function _delete(name) {
- delete this.map[getName(this.map, name)];
- };
+Headers.prototype.deleteAll = function deleteAll (){
+ this.map = {};
+};
- Headers.prototype.forEach = function forEach(callback, thisArg) {
- var _this2 = this;
+Headers.prototype.forEach = function forEach (callback, thisArg) {
+ var this$1 = this;
- each(this.map, function (list, name) {
- each(list, function (value) {
- return callback.call(thisArg, value, name, _this2);
- });
- });
- };
+ each(this.map, function (list, name) {
+ each(list, function (value) { return callback.call(thisArg, value, name, this$1); });
+ });
+};
- return Headers;
-}();
-
function getName(map, name) {
return Object.keys(map).reduce(function (prev, curr) {
return toLower(name) === toLower(curr) ? curr : prev;
}, null);
}
@@ -1232,65 +1251,60 @@
/**
* HTTP Response.
*/
-var Response = function () {
- function Response(body, _ref) {
- var url = _ref.url;
- var headers = _ref.headers;
- var status = _ref.status;
- var statusText = _ref.statusText;
- classCallCheck(this, Response);
+var Response = function Response(body, ref) {
+ var url = ref.url;
+ var headers = ref.headers;
+ var status = ref.status;
+ var statusText = ref.statusText;
- this.url = url;
- this.ok = status >= 200 && status < 300;
- this.status = status || 0;
- this.statusText = statusText || '';
- this.headers = new Headers(headers);
- this.body = body;
+ this.url = url;
+ this.ok = status >= 200 && status < 300;
+ this.status = status || 0;
+ this.statusText = statusText || '';
+ this.headers = new Headers(headers);
+ this.body = body;
- if (isString(body)) {
+ if (isString(body)) {
- this.bodyText = body;
- } else if (isBlob(body)) {
+ this.bodyText = body;
- this.bodyBlob = body;
+ } else if (isBlob(body)) {
- if (isBlobText(body)) {
- this.bodyText = blobText(body);
- }
+ this.bodyBlob = body;
+
+ if (isBlobText(body)) {
+ this.bodyText = blobText(body);
}
}
+};
- Response.prototype.blob = function blob() {
- return when(this.bodyBlob);
- };
+Response.prototype.blob = function blob () {
+ return when(this.bodyBlob);
+};
- Response.prototype.text = function text() {
- return when(this.bodyText);
- };
+Response.prototype.text = function text () {
+ return when(this.bodyText);
+};
- Response.prototype.json = function json() {
- return when(this.text(), function (text) {
- return JSON.parse(text);
- });
- };
+Response.prototype.json = function json () {
+ return when(this.text(), function (text) { return JSON.parse(text); });
+};
- return Response;
-}();
-
function blobText(body) {
return new PromiseObj(function (resolve) {
var reader = new FileReader();
reader.readAsText(body);
reader.onload = function () {
resolve(reader.result);
};
+
});
}
function isBlobText(body) {
return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1;
@@ -1298,64 +1312,57 @@
/**
* HTTP Request.
*/
-var Request = function () {
- function Request(options) {
- classCallCheck(this, Request);
+var Request = function Request(options$$1) {
+ this.body = null;
+ this.params = {};
- this.body = null;
- this.params = {};
+ assign(this, options$$1, {
+ method: toUpper(options$$1.method || 'GET')
+ });
- assign(this, options, {
- method: toUpper(options.method || 'GET')
- });
-
- if (!(this.headers instanceof Headers)) {
- this.headers = new Headers(this.headers);
- }
+ if (!(this.headers instanceof Headers)) {
+ this.headers = new Headers(this.headers);
}
+};
- Request.prototype.getUrl = function getUrl() {
- return Url(this);
- };
+Request.prototype.getUrl = function getUrl (){
+ return Url(this);
+};
- Request.prototype.getBody = function getBody() {
- return this.body;
- };
+Request.prototype.getBody = function getBody (){
+ return this.body;
+};
- Request.prototype.respondWith = function respondWith(body, options) {
- return new Response(body, assign(options || {}, { url: this.getUrl() }));
- };
+Request.prototype.respondWith = function respondWith (body, options$$1) {
+ return new Response(body, assign(options$$1 || {}, {url: this.getUrl()}));
+};
- return Request;
-}();
-
/**
* Service for sending network requests.
*/
-var CUSTOM_HEADERS = { 'X-Requested-With': 'XMLHttpRequest' };
-var COMMON_HEADERS = { 'Accept': 'application/json, text/plain, */*' };
-var JSON_CONTENT_TYPE = { 'Content-Type': 'application/json;charset=utf-8' };
+var COMMON_HEADERS = {'Accept': 'application/json, text/plain, */*'};
+var JSON_CONTENT_TYPE = {'Content-Type': 'application/json;charset=utf-8'};
-function Http(options) {
+function Http(options$$1) {
- var self = this || {},
- client = Client(self.$vm);
+ var self = this || {}, client = Client(self.$vm);
- defaults(options || {}, self.$options, Http.options);
+ defaults(options$$1 || {}, self.$options, Http.options);
Http.interceptors.forEach(function (handler) {
client.use(handler);
});
- return client(new Request(options)).then(function (response) {
+ return client(new Request(options$$1)).then(function (response) {
return response.ok ? response : PromiseObj.reject(response);
+
}, function (response) {
if (response instanceof Error) {
error(response);
}
@@ -1369,44 +1376,48 @@
Http.headers = {
put: JSON_CONTENT_TYPE,
post: JSON_CONTENT_TYPE,
patch: JSON_CONTENT_TYPE,
delete: JSON_CONTENT_TYPE,
- custom: CUSTOM_HEADERS,
- common: COMMON_HEADERS
+ common: COMMON_HEADERS,
+ custom: {}
};
-Http.interceptors = [before, timeout, method, body, jsonp, header, cors];
+Http.interceptors = [before, method, body, jsonp, header, cors];
-['get', 'delete', 'head', 'jsonp'].forEach(function (method) {
+['get', 'delete', 'head', 'jsonp'].forEach(function (method$$1) {
- Http[method] = function (url, options) {
- return this(assign(options || {}, { url: url, method: method }));
+ Http[method$$1] = function (url, options$$1) {
+ return this(assign(options$$1 || {}, {url: url, method: method$$1}));
};
+
});
-['post', 'put', 'patch'].forEach(function (method) {
+['post', 'put', 'patch'].forEach(function (method$$1) {
- Http[method] = function (url, body, options) {
- return this(assign(options || {}, { url: url, method: method, body: body }));
+ Http[method$$1] = function (url, body$$1, options$$1) {
+ return this(assign(options$$1 || {}, {url: url, method: method$$1, body: body$$1}));
};
+
});
/**
* Service for interacting with RESTful services.
*/
-function Resource(url, params, actions, options) {
+function Resource(url, params, actions, options$$1) {
- var self = this || {},
- resource = {};
+ var self = this || {}, resource = {};
- actions = assign({}, Resource.actions, actions);
+ actions = assign({},
+ Resource.actions,
+ actions
+ );
each(actions, function (action, name) {
- action = merge({ url: url, params: assign({}, params) }, options, action);
+ action = merge({url: url, params: assign({}, params)}, options$$1, action);
resource[name] = function () {
return (self.$http || Http)(opts(action, arguments));
};
});
@@ -1414,13 +1425,11 @@
return resource;
}
function opts(action, args) {
- var options = assign({}, action),
- params = {},
- body;
+ var options$$1 = assign({}, action), params = {}, body;
switch (args.length) {
case 2:
@@ -1429,11 +1438,11 @@
break;
case 1:
- if (/^(POST|PUT|PATCH)$/i.test(options.method)) {
+ if (/^(POST|PUT|PATCH)$/i.test(options$$1.method)) {
body = args[0];
} else {
params = args[0];
}
@@ -1443,27 +1452,27 @@
break;
default:
- throw 'Expected up to 4 arguments [params, body], got ' + args.length + ' arguments';
+ throw 'Expected up to 2 arguments [params, body], got ' + args.length + ' arguments';
}
- options.body = body;
- options.params = assign({}, options.params, params);
+ options$$1.body = body;
+ options$$1.params = assign({}, options$$1.params, params);
- return options;
+ return options$$1;
}
Resource.actions = {
- get: { method: 'GET' },
- save: { method: 'POST' },
- query: { method: 'GET' },
- update: { method: 'PUT' },
- remove: { method: 'DELETE' },
- delete: { method: 'DELETE' }
+ get: {method: 'GET'},
+ save: {method: 'POST'},
+ query: {method: 'GET'},
+ update: {method: 'PUT'},
+ remove: {method: 'DELETE'},
+ delete: {method: 'DELETE'}
};
/**
* Install plugin.
@@ -1483,33 +1492,31 @@
Vue.Promise = PromiseObj;
Object.defineProperties(Vue.prototype, {
$url: {
- get: function () {
+ get: function get() {
return options(Vue.url, this, this.$options.url);
}
},
$http: {
- get: function () {
+ get: function get() {
return options(Vue.http, this, this.$options.http);
}
},
$resource: {
- get: function () {
+ get: function get() {
return Vue.resource.bind(this);
}
},
$promise: {
- get: function () {
- var _this = this;
+ get: function get() {
+ var this$1 = this;
- return function (executor) {
- return new Vue.Promise(executor, _this);
- };
+ return function (executor) { return new Vue.Promise(executor, this$1); };
}
}
});
}